# range-parser

> Range header field string parser

Latest version **1.3.0** (published 2026-06-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install range-parser
pnpm add range-parser
yarn add range-parser
bun add range-parser
```

## Health

**Score 58/100 (C)** — status: active.

Positive: has types package; no vulnerabilities; recently updated; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2026-06-25 |
| First published | 2012-06-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/range-parser) |
| Module format | CommonJS |
| Node | >= 0.6 |
| Dependencies | 0 |
| Unpacked size | 8.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 99 |
| Author | TJ Holowaychuk |
| Maintainers | ulisesgascon, blakeembrey, tjholowaychuk, dougwilson, jonathanong, jongleberry |
| Keywords | range, parser, http |

## Links

- npm: https://www.npmjs.com/package/range-parser
- Repository: https://github.com/jshttp/range-parser
- Homepage: https://github.com/jshttp/range-parser#readme
- Issues: https://github.com/jshttp/range-parser/issues
- Funding: https://opencollective.com/express
- npm.io page: https://npm.io/package/range-parser

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.3.0 (latest) — 2026-06-25
- 1.2.1 — 2019-05-11
- 1.2.0 — 2016-06-01
- 1.1.0 — 2016-05-13
- 1.0.3 — 2015-10-29
- 1.0.2 — 2014-09-09
- 1.0.1 — 2014-09-08
- 1.0.0 — 2013-12-11
- 0.0.4 — 2012-06-18
- 0.0.3 — 2012-06-18
- 0.0.2 — 2012-06-18
- 0.0.1 — 2012-06-11

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

<!-- eslint-disable no-unused-vars -->

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

<!-- eslint-disable no-undef -->

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

<!-- eslint-disable no-undef -->

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

---
_Source: https://npm.io/package/range-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
