Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jshttp/range-parser
Range header field parser
https://github.com/jshttp/range-parser
http javascript nodejs range
Last synced: 5 days ago
JSON representation
Range header field parser
- Host: GitHub
- URL: https://github.com/jshttp/range-parser
- Owner: jshttp
- License: mit
- Created: 2012-06-11T16:07:47.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2024-05-14T17:16:59.000Z (6 months ago)
- Last Synced: 2024-11-05T20:10:52.451Z (8 days ago)
- Topics: http, javascript, nodejs, range
- Language: JavaScript
- Size: 72.3 KB
- Stars: 91
- Watchers: 12
- Forks: 16
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE
Awesome Lists containing this project
README
# range-parser
[![NPM Version][npm-version-image]][npm-url]
[![NPM Downloads][npm-downloads-image]][npm-url]
[![Node.js Version][node-image]][node-url]
[![Build Status][ci-image]][ci-url]
[![Test Coverage][coveralls-image]][coveralls-url]Range header field parser.
## Installation
This is a [Node.js](https://nodejs.org/en/) module available through the
[npm registry](https://www.npmjs.com/). Installation is done using the
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):```sh
$ npm install range-parser
```## API
```js
var parseRange = require('range-parser')
```### parseRange(size, header, options)
Parse the given `header` string where `size` is the size of the selected
representation that is to be partitioned into subranges. An array of subranges
will be returned or negative numbers indicating an error parsing.* `-2` signals a malformed header string
* `-1` signals an unsatisfiable range```js
// parse header from request
var subranges = parseRange(size, req.headers.range)// the type of the subranges
if (subranges.type === 'bytes') {
// the ranges
subranges.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 subranges should be combined, defaults to
`false`. When `true`, ranges will be combined and returned as if they were
specified that way in the header.```js
parseRange(100, 'bytes=50-55,0-10,5-10,56-60', { combine: true })
// => [
// { start: 0, end: 10 },
// { start: 50, end: 60 }
// ]
```## License
[MIT](LICENSE)
[ci-image]: https://badgen.net/github/checks/jshttp/range-parser/master?label=ci
[ci-url]: https://github.com/jshttp/range-parser/actions/workflows/ci.yml
[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/range-parser/master
[coveralls-url]: https://coveralls.io/r/jshttp/range-parser?branch=master
[node-image]: https://badgen.net/npm/node/range-parser
[node-url]: https://nodejs.org/en/download
[npm-downloads-image]: https://badgen.net/npm/dm/range-parser
[npm-url]: https://npmjs.org/package/range-parser
[npm-version-image]: https://badgen.net/npm/v/range-parser