@se-oss/range-parser
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@se-oss/range-parser

CI NPM Version MIT License Install Size

@se-oss/range-parser is a lightweight, fast parser for HTTP Range headers. It supports multi-range requests, range combination.


📦 Installation

npm i @se-oss/range-parser

📖 Usage

import { parseRange } from '@se-oss/range-parser';

const size = 1000;
const str = 'bytes=500-999';
console.log(parseRange(size, str));
// [ { start: 500, end: 999 }, type: 'bytes' ]

const multi = 'bytes=0-4,90-99,5-75,100-199,101-102';
console.log(parse(150, multi, { combine: true }));
// [ { start: 0, end: 75 }, { start: 90, end: 149 }, type: 'bytes' ]

📚 Documentation

For all configuration options, please see the API docs.

API
/**
 * Parse "Range" header `str` relative to the given file `size`.
 *
 * @param size - The size of the file.
 * @param str - The Range header string.
 * @param options - Optional configuration.
 * @returns Array of ranges if valid, -1 for unsatisfiable ranges, or -2 for malformed header.
 */
declare function parseRange(size: number, str: string, options?: RangeParserOptions): RangeArray | -1 | -2;

🤝 Contributing

Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub.

Thanks again for your support, it is much appreciated! 🙏

🙌 Credits

This package is a TypeScript port of jshttp/range-parser with support for both CommonJS and ECMAScript modules.

License

MIT © Shahrad Elahi and contributors.

Readme

Keywords

Package Sidebar

Install

npm i @se-oss/range-parser

Weekly Downloads

3

Version

1.0.0

License

MIT

Unpacked Size

8.4 kB

Total Files

6

Last publish

Collaborators

  • shahradelahi