@hugoalh/http-header-value-handler
v0.2.1
Published
A module to handle the HTTP header value.
Readme
HTTP Header Value Handler (ES)
🔗 DistBoard @hugoalh ● GitHub ● JSR ● NPM
An ECMAScript module to handle the HTTP header value.
This serves most of the HTTP header value with general functions of syntax check, parse, and stringify; but not value check and validation.
🎯 Runtime Targets
Any runtime which support ECMAScript should able to use this; These runtimes are officially supported:
🛡️ Runtime Permissions
This does not request any runtime permission.
#️⃣ Sources & Entrypoints
- GitHub Raw
https://raw.githubusercontent.com/hugoalh/http-header-value-handler-es/{Tag}/mod.ts - JSR
jsr:@hugoalh/http-header-value-handler[@{Tag}] - NPM
npm:@hugoalh/http-header-value-handler[@{Tag}]
| Name | Path | Description |
|:--|:--|:--|
| . | ./mod.ts | Default. |
| ./encode | ./encode.ts | Utilities for encode and decode. |
| ./handle | ./handle.ts | Utilities for parse and stringify. |
| ./quote | ./quote.ts | Utilities for quote. |
| ./split | ./split.ts | Utilities for split. |
[!NOTE]
- Different runtimes have vary support for the sources and entrypoints, visit the runtime documentation for more information.
- It is recommended to include tag for immutability.
- These are not part of the public APIs hence should not be used:
- Benchmark/Test file (e.g.:
example.bench.ts,example.test.ts).- Entrypoint name or path include any underscore prefix (e.g.:
_example.ts,foo/_example.ts).- Identifier/Namespace/Symbol include any underscore prefix (e.g.:
_example,Foo._example).
🧩 APIs
function parseHTTPHeaderValue(input: string, options?: HTTPHeaderValueHandlerOptions): HTTPHeaderValueElementContext[];function parseHTTPHeaderValueIterate(input: string, options?: HTTPHeaderValueHandlerOptions): Generator<HTTPHeaderValueElementContext>;function splitHTTPHeaderValue(input: string): (string | HTTPHeaderValueParameterPair)[][];function splitHTTPHeaderValueIterate(input: string): Generator<(string | HTTPHeaderValueParameterPair)[]>;function stringifyHTTPHeaderValue(input: readonly HTTPHeaderValueElementContext[] | readonly (readonly (string | HTTPHeaderValueParameterPair)[])[], options?: HTTPHeaderValueHandlerOptions): string;interface HTTPHeaderValueElementContext { value?: string; parameters: Record<string, string | undefined>; }interface HTTPHeaderValueHandlerOptions { parametersKeyCaseSensitive?: boolean; }interface HTTPHeaderValueParameterPair { key: string; value: string; }
[!NOTE]
- For the full or prettier documentation, can visit via:
✍️ Examples
splitHTTPHeaderValue(`text/html, application/xhtml+xml, application/xml;q=0.9, image/webp`); //=> // [ // ["text/html"], // ["application/xhtml+xml"], // ["application/xml", { key: "q", value: "0.9" }], // ["image/webp"] // ]
