1.0.0
HTTP ETag header field parser
Attributes
Includes Deno configuration
Repository
Current version released
a year ago
Dependencies
deno.land/x
etag-parser
HTTP ETag header field parser.
Compliant with RFC 9110, 8.8.3. ETag.
Deserialization
Parses string into ETag.
import { parse } from "https://deno.land/x/etag_parser@$VERSION/mod.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(parse(`W/"123456789"`), { tag: "123456789", weak: true });
assertEquals(parse(`"123456789"`), { tag: "123456789", weak: false });
Throwing error
Throws SyntaxError
if the input is invalid
<entity-tag>
.
import { parse } from "https://deno.land/x/etag_parser@$VERSION/mod.ts";
import { assertThrows } from "https://deno.land/std/testing/asserts.ts";
assertThrows(() => parse("<invalid>"));
Serialization
Serialize ETag into string.
import { stringify } from "https://deno.land/x/etag_parser@$VERSION/mod.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(stringify({ weak: true, tag: "123456789" }), `W/"123456789"`);
assertEquals(stringify({ weak: false, tag: "123456789" }), `"123456789"`);
Throwing error
Throws TypeError
if ETag contains invalid value.
import { stringify } from "https://deno.land/x/etag_parser@$VERSION/mod.ts";
import { assertThrows } from "https://deno.land/std/testing/asserts.ts";
assertThrows(() => stringify({ tag: "aあ亜", weak: true }));
ETag
ETag is a structured object for ETag
header.
Name | Type | Description |
---|---|---|
tag | string |
Representation of <etagc> . |
weak | boolean |
Whether this is weak validator or not. |
API
All APIs can be found in the deno doc.
License
Copyright © 2023-present httpland.
Released under the MIT license