🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

range-parser

Package Overview
Dependencies
Maintainers
6
Versions
12
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.2.1
to
1.3.0
+27
-8
index.js

@@ -47,12 +47,17 @@ /*!

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)
var indexOf = arr[i].indexOf('-')
if (indexOf === -1) {
return -2
}
// -nnn
if (isNaN(start)) {
var startStr = arr[i].slice(0, indexOf).trim()
var endStr = arr[i].slice(indexOf + 1).trim()
var start = parsePos(startStr)
var end = parsePos(endStr)
if (startStr.length === 0) {
start = size - end
end = size - 1
// nnn-
} else if (isNaN(end)) {
} else if (endStr.length === 0) {
end = size - 1

@@ -66,4 +71,8 @@ }

if (isNaN(start) || isNaN(end)) {
return -2
}
// invalid or unsatisifiable
if (isNaN(start) || isNaN(end) || start > end || start < 0) {
if (start > end || start < 0) {
continue

@@ -90,2 +99,12 @@ }

/**
* Parse string to integer.
* @private
*/
function parsePos (str) {
if (/^\d+$/.test(str)) return Number(str)
return NaN
}
/**
* Combine overlapping & adjacent ranges.

@@ -92,0 +111,0 @@ * @private

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

"description": "Range header field string parser",
"version": "1.2.1",
"version": "1.3.0",
"contributors": [

@@ -19,10 +19,14 @@ "Douglas Christopher Wilson <doug@somethingdoug.com>",

"repository": "jshttp/range-parser",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
},
"devDependencies": {
"deep-equal": "1.0.1",
"eslint": "5.16.0",
"eslint-config-standard": "12.0.0",
"eslint": "6.0.1",
"eslint-config-standard": "13.0.1",
"eslint-plugin-markdown": "1.0.0",
"eslint-plugin-import": "2.17.2",
"eslint-plugin-node": "8.0.1",
"eslint-plugin-promise": "4.1.1",
"eslint-plugin-import": "2.18.0",
"eslint-plugin-node": "9.1.0",
"eslint-plugin-promise": "4.2.1",
"eslint-plugin-standard": "4.0.0",

@@ -43,5 +47,5 @@ "mocha": "6.1.4",

"test": "mocha --reporter spec",
"test-cov": "nyc --reporter=html --reporter=text npm test",
"test-travis": "nyc --reporter=text npm test"
"test-ci": "nyc --reporter=lcovonly --reporter=text npm test",
"test-cov": "nyc --reporter=html --reporter=text npm test"
}
}
+13
-12

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

[![Node.js Version][node-image]][node-url]
[![Build Status][travis-image]][travis-url]
[![Build Status][ci-image]][ci-url]
[![Test Coverage][coveralls-image]][coveralls-url]

@@ -32,4 +32,5 @@

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.
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.

@@ -43,8 +44,8 @@ * `-2` signals a malformed header string

// parse header from request
var range = parseRange(size, req.headers.range)
var subranges = parseRange(size, req.headers.range)
// the type of the range
if (range.type === 'bytes') {
// the type of the subranges
if (subranges.type === 'bytes') {
// the ranges
range.forEach(function (r) {
subranges.forEach(function (r) {
// do something with r.start and r.end

@@ -61,5 +62,5 @@ })

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.
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.

@@ -80,2 +81,4 @@ <!-- eslint-disable no-undef -->

[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

@@ -88,3 +91,1 @@ [coveralls-url]: https://coveralls.io/r/jshttp/range-parser?branch=master

[npm-version-image]: https://badgen.net/npm/v/range-parser
[travis-image]: https://badgen.net/travis/jshttp/range-parser/master
[travis-url]: https://travis-ci.org/jshttp/range-parser