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.3 to 1.1.0

10

HISTORY.md

@@ -1,4 +0,10 @@

unreleased
==========
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

@@ -5,0 +11,0 @@

59

index.js

@@ -7,3 +7,3 @@ /*!

'use strict';
'use strict'

@@ -15,3 +15,3 @@ /**

module.exports = rangeParser;
module.exports = rangeParser

@@ -27,40 +27,49 @@ /**

function rangeParser(size, str) {
var valid = true;
var i = str.indexOf('=');
function rangeParser (size, str) {
var index = str.indexOf('=')
if (-1 == i) return -2;
if (index === -1) {
return -2
}
var arr = str.slice(i + 1).split(',').map(function(range){
var range = range.split('-')
, start = parseInt(range[0], 10)
, end = parseInt(range[1], 10);
// split the range string
var arr = str.slice(index + 1).split(',')
var ranges = []
// add ranges type
ranges.type = str.slice(0, index)
// parse all ranges
for (var i = 0; i < arr.length; i++) {
var range = arr[i].split('-')
var start = parseInt(range[0], 10)
var end = parseInt(range[1], 10)
// -nnn
if (isNaN(start)) {
start = size - end;
end = size - 1;
start = size - end
end = size - 1
// nnn-
} else if (isNaN(end)) {
end = size - 1;
end = size - 1
}
// limit last-byte-pos to current length
if (end > size - 1) end = size - 1;
if (end > size - 1) {
end = size - 1
}
// invalid
if (isNaN(start)
|| isNaN(end)
|| start > end
|| start < 0) valid = false;
// invalid or unsatisifiable
if (isNaN(start) || isNaN(end) || start > end || start < 0) {
continue
}
return {
// add range
ranges.push({
start: start,
end: end
};
});
})
}
arr.type = str.slice(0, i);
return valid ? arr : -1;
return ranges.length ? ranges : -1
}

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

"description": "Range header field string parser",
"version": "1.0.3",
"version": "1.1.0",
"contributors": [
"Douglas Christopher Wilson <doug@somethingdoug.com>",
"Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)"
],
"license": "MIT",

@@ -15,3 +19,7 @@ "keywords": [

"devDependencies": {
"istanbul": "0.4.0",
"eslint": "2.9.0",
"eslint-config-standard": "5.3.1",
"eslint-plugin-promise": "1.1.0",
"eslint-plugin-standard": "1.3.2",
"istanbul": "0.4.3",
"mocha": "1.21.5"

@@ -28,2 +36,3 @@ },

"scripts": {
"lint": "eslint **/*.js",
"test": "mocha --reporter spec",

@@ -30,0 +39,0 @@ "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot",

@@ -29,3 +29,3 @@ # range-parser

* `-2` signals a malformed header string
* `-1` signals an invalid range
* `-1` signals an unsatisfiable range

@@ -52,3 +52,3 @@ ```js

[node-version-image]: https://img.shields.io/node/v/range-parser.svg
[node-version-url]: http://nodejs.org/download/
[node-version-url]: https://nodejs.org/endownload
[travis-image]: https://img.shields.io/travis/jshttp/range-parser.svg

@@ -55,0 +55,0 @@ [travis-url]: https://travis-ci.org/jshttp/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