Registry / devops / content-range

content-range

JSON →
library2.0.2jsnpmunverified

Parser and formatter for the HTTP/1.1 Content-Range header field. Current stable version is 2.0.2, released periodically via npm. Provides two functions: format() to build the header string from object parameters (unit, start, end, size) and parse() to parse the header string into an object with unit, start, end, and length. Ships TypeScript definitions. Key differentiator: lightweight (no dependencies) and focuses solely on Content-Range, unlike larger HTTP libraries.

npm install content-range
INSTALL
IMPORT
SIG · CONTENT-RANGE
C
content-range
devopsjavascriptv2.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

format
import { format } from 'content-range'
import contentRange from 'content-range'
Package exports named exports only; no default export.
parse
import { parse } from 'content-range'
const { parse } = require('content-range')
Works in both ESM and CJS, but require() will not work in ESM-only environments.
ContentRange
import type { ContentRange } from 'content-range'
TypeScript type representing the parsed result object.

Shows how to format a Content-Range header object into a string and parse a string back into an object.

import { format, parse } from 'content-range'; const formatted = format({ unit: 'bytes', start: 10, end: 20, size: 100, }); console.log(formatted); // 'bytes 10-20/100' const parsed = parse('bytes 10-20/100'); console.log(parsed); // { unit: 'bytes', start: 10, end: 20, length: 100 }
Debug
Known issues
gotchaThe parse() function returns 'length' not 'size' for the total size field.
fix
Access the parsed object's 'length' property instead of 'size'.
affects: >=1.0.0
gotchaThe format() function expects the key 'size' for total length, but parse() returns 'length'. This asymmetry can cause confusion.
fix
Use 'size' when calling format() and expect 'length' when using parse().
affects: >=1.0.0
gotchaThe header value must be a string exactly as per HTTP spec; parse() does not normalize whitespace.
fix
Ensure the input to parse has no extra spaces. For example, 'bytes 10-20/100' (single space between 'bytes' and range).
affects: >=1.0.0
Errors
Common errors & fixes
Cannot read properties of undefined (reading 'unit')
Calling format() with an object missing required properties.
fix
Ensure the argument to format() includes 'unit', 'start', 'end', and 'size'.
TypeError: contentRange.parse is not a function
Using default import when package only exports named exports.
fix
Use named import: import { parse } from 'content-range'
Expected 'bytes' but got undefined
Parsing a malformed header string (e.g., missing unit prefix).
fix
Pass a valid HTTP Content-Range header string like 'bytes 0-499/1000'.
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
24 hits · last 30 days
node
22
OpenAI (training)
1
Resources
content-range — npm install content-range · libregistry