http-range-parse

raw JSON →
1.0.0 verified Sat Apr 25 auth: no javascript

Parses HTTP Range headers according to RFC7233. Current version 1.0.0, stable with no recent updates. Converts a range header string into a structured object with unit and range details (first, last, suffix, or multiple ranges). Lightweight, no dependencies. Compared to alternatives like `range-parser`, this library returns a more detailed object and supports multi-range headers.

error TypeError: parse is not a function
cause Incorrect import in ESM context (using default import for CJS module).
fix
Use import parse from 'http-range-parse' or const parse = require('http-range-parse') depending on module system.
error Cannot find module 'http-range-parse'
cause Package not installed or not in node_modules.
fix
Run npm install http-range-parse.
error Range header is malformed
cause Passing invalid or empty string to parse.
fix
Check header format; ensure it follows RFC7233 (e.g., 'unit=x-y').
gotcha Invalid range formats may return unexpected results or throw.
fix Validate input header string before parsing; handle errors with try/catch.
deprecated Package is not actively maintained; last release 2015.
fix Consider using alternatives like `range-parser` or `http-range-parser` for ongoing support.
gotcha Suffix range notation (-N) returns suffix property, but combined with other ranges may be misinterpreted.
fix Check for `suffix` property separately and ensure it's not used with `first`/`last` in same header.
gotcha The package does not validate units; any string before '=' is accepted as unit.
fix Manually verify the unit is one of the expected values (e.g., 'bytes') if required.
npm install http-range-parse
yarn add http-range-parse
pnpm add http-range-parse

Parses an HTTP Range header and prints the structured result with unit and range objects.

const parse = require('http-range-parse');

const header = 'bytes=0-499,500-999';
const result = parse(header);
console.log(result);
// { unit: 'bytes', ranges: [{ first: 0, last: 499 }, { first: 500, last: 999 }] }