3 [![NPM Version][npm-image]][npm-url]
4 [![NPM Downloads][downloads-image]][downloads-url]
5 [![Node.js Version][node-version-image]][node-version-url]
6 [![Build Status][travis-image]][travis-url]
7 [![Test Coverage][coveralls-image]][coveralls-url]
9 Range header field parser.
14 $ npm install range-parser
20 var parseRange = require('range-parser')
23 ### parseRange(size, header, options)
25 Parse the given `header` string where `size` is the maximum size of the resource.
26 An array of ranges will be returned or negative numbers indicating an error parsing.
28 * `-2` signals a malformed header string
29 * `-1` signals an unsatisfiable range
32 // parse header from request
33 var range = parseRange(size, req.headers.range)
35 // the type of the range
36 if (range.type === 'bytes') {
38 range.forEach(function (r) {
39 // do something with r.start and r.end
46 These properties are accepted in the options object.
50 Specifies if overlapping & adjacent ranges should be combined, defaults to `false`.
51 When `true`, ranges will be combined and returned as if they were specified that
55 parseRange(100, 'bytes=50-55,0-10,5-10,56-60', { combine: true })
57 // { start: 0, end: 10 },
58 // { start: 50, end: 60 }
66 [npm-image]: https://img.shields.io/npm/v/range-parser.svg
67 [npm-url]: https://npmjs.org/package/range-parser
68 [node-version-image]: https://img.shields.io/node/v/range-parser.svg
69 [node-version-url]: https://nodejs.org/endownload
70 [travis-image]: https://img.shields.io/travis/jshttp/range-parser.svg
71 [travis-url]: https://travis-ci.org/jshttp/range-parser
72 [coveralls-image]: https://img.shields.io/coveralls/jshttp/range-parser.svg
73 [coveralls-url]: https://coveralls.io/r/jshttp/range-parser
74 [downloads-image]: https://img.shields.io/npm/dm/range-parser.svg
75 [downloads-url]: https://npmjs.org/package/range-parser