Socket
Socket
Sign inDemoInstall

range-parser

Package Overview
Dependencies
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

range-parser - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

5

HISTORY.md

@@ -0,1 +1,6 @@

unreleased
==========
* perf: enable strict mode
1.0.2 / 2014-09-08

@@ -2,0 +7,0 @@ ==================

20

index.js

@@ -0,3 +1,17 @@

/*!
* range-parser
* Copyright(c) 2012-2014 TJ Holowaychuk
* MIT Licensed
*/
'use strict';
/**
* Module exports.
* @public
*/
module.exports = rangeParser;
/**
* Parse "Range" header `str` relative to the given file `size`.

@@ -8,6 +22,6 @@ *

* @return {Array}
* @api public
* @public
*/
module.exports = function(size, str){
function rangeParser(size, str) {
var valid = true;

@@ -50,2 +64,2 @@ var i = str.indexOf('=');

return valid ? arr : -1;
};
}

13

package.json

@@ -5,3 +5,3 @@ {

"description": "Range header field string parser",
"version": "1.0.2",
"version": "1.0.3",
"license": "MIT",

@@ -15,5 +15,4 @@ "keywords": [

"devDependencies": {
"istanbul": "0",
"mocha": "1",
"should": "2"
"istanbul": "0.4.0",
"mocha": "1.21.5"
},

@@ -29,6 +28,6 @@ "files": [

"scripts": {
"test": "mocha --reporter spec --require should",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --require should",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot --require should"
"test": "mocha --reporter spec",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot"
}
}

@@ -17,20 +17,29 @@ # range-parser

## Examples
## API
```js
assert(-1 == parse(200, 'bytes=500-20'));
assert(-2 == parse(200, 'bytes=malformed'));
parse(200, 'bytes=0-499').should.eql(arr('bytes', [{ start: 0, end: 199 }]));
parse(1000, 'bytes=0-499').should.eql(arr('bytes', [{ start: 0, end: 499 }]));
parse(1000, 'bytes=40-80').should.eql(arr('bytes', [{ start: 40, end: 80 }]));
parse(1000, 'bytes=-500').should.eql(arr('bytes', [{ start: 500, end: 999 }]));
parse(1000, 'bytes=-400').should.eql(arr('bytes', [{ start: 600, end: 999 }]));
parse(1000, 'bytes=500-').should.eql(arr('bytes', [{ start: 500, end: 999 }]));
parse(1000, 'bytes=400-').should.eql(arr('bytes', [{ start: 400, end: 999 }]));
parse(1000, 'bytes=0-0').should.eql(arr('bytes', [{ start: 0, end: 0 }]));
parse(1000, 'bytes=-1').should.eql(arr('bytes', [{ start: 999, end: 999 }]));
parse(1000, 'items=0-5').should.eql(arr('items', [{ start: 0, end: 5 }]));
parse(1000, 'bytes=40-80,-1').should.eql(arr('bytes', [{ start: 40, end: 80 }, { start: 999, end: 999 }]));
var parseRange = require('range-parser')
```
### parseRange(size, header)
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 invalid range
```js
// parse header from request
var range = parseRange(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
})
}
```
## License

@@ -40,11 +49,11 @@

[npm-image]: https://img.shields.io/npm/v/range-parser.svg?style=flat
[npm-image]: https://img.shields.io/npm/v/range-parser.svg
[npm-url]: https://npmjs.org/package/range-parser
[node-version-image]: https://img.shields.io/badge/node.js-%3E%3D_0.6-brightgreen.svg?style=flat
[node-version-image]: https://img.shields.io/node/v/range-parser.svg
[node-version-url]: http://nodejs.org/download/
[travis-image]: https://img.shields.io/travis/jshttp/range-parser.svg?style=flat
[travis-image]: https://img.shields.io/travis/jshttp/range-parser.svg
[travis-url]: https://travis-ci.org/jshttp/range-parser
[coveralls-image]: https://img.shields.io/coveralls/jshttp/range-parser.svg?style=flat
[coveralls-image]: https://img.shields.io/coveralls/jshttp/range-parser.svg
[coveralls-url]: https://coveralls.io/r/jshttp/range-parser
[downloads-image]: https://img.shields.io/npm/dm/range-parser.svg?style=flat
[downloads-image]: https://img.shields.io/npm/dm/range-parser.svg
[downloads-url]: https://npmjs.org/package/range-parser
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc