Skip to content

shahradelahi/http-range-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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

About

πŸ“ Lightweight HTTP Range header parser.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published