Skip to content

Commit 06db6e7

Browse files
committed
Update docs
1 parent 797d9e3 commit 06db6e7

1 file changed

Lines changed: 10 additions & 21 deletions

File tree

README.md

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,56 +10,45 @@ Range header field parser.
1010

1111
## Installation
1212

13-
This is a [Node.js](https://nodejs.org/en/) module available through the
14-
[npm registry](https://www.npmjs.com/). Installation is done using the
15-
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
16-
1713
```sh
1814
$ npm install range-parser
1915
```
2016

2117
## API
2218

23-
<!-- eslint-disable no-unused-vars -->
24-
2519
```js
26-
var parseRange = require("range-parser");
20+
import { parse, combineRanges } from "range-parser";
2721
```
2822

29-
### parseRange(size, header, options)
23+
### `parse(size, header)`
3024

3125
Parse the given `header` string where `size` is the size of the selected
32-
representation that is to be partitioned into subranges. An array of subranges
33-
will be returned or negative numbers indicating an error parsing.
26+
representation that is to be partitioned into subranges. A type and an array of
27+
subranges will be returned or negative numbers indicating an error parsing.
3428

3529
- `-2` signals a malformed header string
3630
- `-1` signals an unsatisfiable range
3731

3832
```js
3933
// parse header from request
40-
var subranges = parseRange(size, req.headers.range);
34+
var subranges = parse(size, req.headers.range);
4135

4236
// the type of the subranges
4337
if (subranges.type === "bytes") {
4438
// the ranges
45-
subranges.forEach(function (r) {
39+
subranges.ranges.forEach(function (r) {
4640
// do something with r.start and r.end
4741
});
4842
}
4943
```
5044

51-
#### Options
52-
53-
These properties are accepted in the options object.
54-
55-
##### combine
45+
### `combineRanges(ranges)`
5646

57-
Specifies if overlapping & adjacent subranges should be combined, defaults to
58-
`false`. When `true`, ranges will be combined and returned as if they were
59-
specified that way in the header.
47+
Overlapping & adjacent ranges will be combined and returned.
6048

6149
```js
62-
parseRange(100, "bytes=50-55,0-10,5-10,56-60", { combine: true });
50+
const { ranges } = parseRange(100, "bytes=50-55,0-10,5-10,56-60");
51+
combineRanges(ranges);
6352
// => [
6453
// { start: 0, end: 10 },
6554
// { start: 50, end: 60 }

0 commit comments

Comments
 (0)