https://github.com/httpland/accept-ranges-parser
HTTP Accept-Ranges header field parser
https://github.com/httpland/accept-ranges-parser
accept-ranges bytes deserializer header http none parse parser serialize serializer stringify
Last synced: 5 days ago
JSON representation
HTTP Accept-Ranges header field parser
- Host: GitHub
- URL: https://github.com/httpland/accept-ranges-parser
- Owner: httpland
- License: mit
- Created: 2023-03-27T05:47:12.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-29T13:32:37.000Z (about 3 years ago)
- Last Synced: 2025-10-20T16:48:37.558Z (9 months ago)
- Topics: accept-ranges, bytes, deserializer, header, http, none, parse, parser, serialize, serializer, stringify
- Language: TypeScript
- Homepage: https://deno.land/x/accept_ranges_parser
- Size: 24.4 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# accept-ranges-parser
[](https://deno.land/x/accept_ranges_parser)
[](https://doc.deno.land/https/deno.land/x/accept_ranges_parser/mod.ts)
[](https://github.com/httpland/accept-ranges-parser/releases)
[](https://codecov.io/gh/httpland/accept-ranges-parser)
[](https://github.com/httpland/accept-ranges-parser/blob/main/LICENSE)
[](https://github.com/httpland/accept-ranges-parser/actions/workflows/test.yaml)
[](https://nodei.co/npm/@httpland/accept-ranges-parser/)
HTTP Accept-Ranges header field parser.
Compliant with
[RFC 9110, 14.3. Accept-Ranges](https://www.rfc-editor.org/rfc/rfc9110#section-14.3).
## Deserialization
Parses string into [AcceptRanges](#acceptranges).
```ts
import { parseAcceptRanges } from "https://deno.land/x/accept_ranges_parser@$VERSION/parse.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(parseAcceptRanges(`none`), ["none"]);
assertEquals(parseAcceptRanges(`bytes, unknown`), ["bytes", "unknown"]);
```
### Throwing error
Throws `SyntaxError` if the input is invalid
[``](https://www.rfc-editor.org/rfc/rfc9110#section-14.3-2)
syntax.
```ts
import { parseAcceptRanges } from "https://deno.land/x/accept_ranges_parser@$VERSION/parse.ts";
import { assertThrows } from "https://deno.land/std/testing/asserts.ts";
assertThrows(() => parseAcceptRanges(""));
```
## Serialization
Serialize string of array into string.
```ts
import { stringifyAcceptRanges } from "https://deno.land/x/accept_ranges_parser@$VERSION/stringify.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(stringifyAcceptRanges(["bytes"]), "bytes");
```
### Throwing error
Throws `TypeError` if the element contains invalid
[``](https://www.rfc-editor.org/rfc/rfc9110#section-14.1-3) syntax.
```ts
import { stringifyAcceptRanges } from "https://deno.land/x/accept_ranges_parser@$VERSION/stringify.ts";
import { assertThrows } from "https://deno.land/std/testing/asserts.ts";
assertThrows(() => stringifyAcceptRanges(["", "none"]));
```
## AcceptRanges
`AcceptRanges` is a subtype of array with the following characteristics.
- It has one or more elements.
- The elements are [Token](#token).
### Token
Represents a character set that compliant with
[RFC 9110, 5.6.2. Tokens](https://www.rfc-editor.org/rfc/rfc9110#section-5.6.2)
as much as possible.
## API
All APIs can be found in the
[deno doc](https://doc.deno.land/https/deno.land/x/accept_ranges_parser/mod.ts).
## License
Copyright © 2023-present [httpland](https://github.com/httpland).
Released under the [MIT](./LICENSE) license