Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

range-parser

jshttp101.3mMIT1.2.1TypeScript support: definitely-typed

Range header field string parser

range, parser, http

readme

range-parser

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

Range header field parser.

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install range-parser

API

var parseRange = require('range-parser')

parseRange(size, header, options)

Parse the given header string where size is the maximum size of the resource. An array of ranges will be returned or negative numbers indicating an error parsing.

  • -2 signals a malformed header string
  • -1 signals an unsatisfiable range
// parse header from request
var range = parseRange(size, req.headers.range)

// the type of the range
if (range.type === 'bytes') {
  // the ranges
  range.forEach(function (r) {
    // do something with r.start and r.end
  })
}

Options

These properties are accepted in the options object.

combine

Specifies if overlapping & adjacent ranges should be combined, defaults to false. When true, ranges will be combined and returned as if they were specified that way in the header.

parseRange(100, 'bytes=50-55,0-10,5-10,56-60', { combine: true })
// => [
//      { start: 0,  end: 10 },
//      { start: 50, end: 60 }
//    ]

License

MIT

changelog

1.2.1 / 2019-05-10

  • Improve error when str is not a string

1.2.0 / 2016-06-01

  • Add combine option to combine overlapping ranges

1.1.0 / 2016-05-13

  • Fix incorrectly returning -1 when there is at least one valid range
  • perf: remove internal function

1.0.3 / 2015-10-29

  • perf: enable strict mode

1.0.2 / 2014-09-08

  • Support Node.js 0.6

1.0.1 / 2014-09-07

  • Move repository to jshttp

1.0.0 / 2013-12-11

  • Add repository to package.json
  • Add MIT license

0.0.4 / 2012-06-17

  • Change ret -1 for unsatisfiable and -2 when invalid

0.0.3 / 2012-06-17

  • Fix last-byte-pos default to len - 1

0.0.2 / 2012-06-14

  • Add .type

0.0.1 / 2012-06-11

  • Initial release