3 [![NPM Version][npm-version-image]][npm-url]
4 [![NPM Downloads][npm-downloads-image]][npm-url]
5 [![Node.js Version][node-image]][node-url]
6 [![Build Status][travis-image]][travis-url]
7 [![Test Coverage][coveralls-image]][coveralls-url]
9 Range header field parser.
13 This is a [Node.js](https://nodejs.org/en/) module available through the
14 [npm registry](https://www.npmjs.com/). Installation is done using the
15 [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
18 $ npm install range-parser
23 <!-- eslint-disable no-unused-vars -->
26 var parseRange = require('range-parser')
29 ### parseRange(size, header, options)
31 Parse the given `header` string where `size` is the maximum size of the resource.
32 An array of ranges will be returned or negative numbers indicating an error parsing.
34 * `-2` signals a malformed header string
35 * `-1` signals an unsatisfiable range
37 <!-- eslint-disable no-undef -->
40 // parse header from request
41 var range = parseRange(size, req.headers.range)
43 // the type of the range
44 if (range.type === 'bytes') {
46 range.forEach(function (r) {
47 // do something with r.start and r.end
54 These properties are accepted in the options object.
58 Specifies if overlapping & adjacent ranges should be combined, defaults to `false`.
59 When `true`, ranges will be combined and returned as if they were specified that
62 <!-- eslint-disable no-undef -->
65 parseRange(100, 'bytes=50-55,0-10,5-10,56-60', { combine: true })
67 // { start: 0, end: 10 },
68 // { start: 50, end: 60 }
76 [coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/range-parser/master
77 [coveralls-url]: https://coveralls.io/r/jshttp/range-parser?branch=master
78 [node-image]: https://badgen.net/npm/node/range-parser
79 [node-url]: https://nodejs.org/en/download
80 [npm-downloads-image]: https://badgen.net/npm/dm/range-parser
81 [npm-url]: https://npmjs.org/package/range-parser
82 [npm-version-image]: https://badgen.net/npm/v/range-parser
83 [travis-image]: https://badgen.net/travis/jshttp/range-parser/master
84 [travis-url]: https://travis-ci.org/jshttp/range-parser