RFC 4151 Tag URI parser and generator
The main entry point and default export of this library is the TagUri
class,
which is all you’ll usually need. It simplifies working with
RFC 4151 Tag URIs by parsing them into their components or
allowing you to construct new ones programmatically.
-
Parsing Tag URIs: Extract structured components like the authority name, date, and specific part.
-
Helpful Errors: Parsing failures include errors pointing to where the issue occurred.
-
Tag URI Construction: Create tag URIs using the
TagUri
constructor (note: validation is not yet implemented). -
Platform Agnostic: Fully dependency-free, works with Deno, Node.js, and modern browsers using baseline web compatibility.
import { TagUri } from "@cptpiepmatz/tag-uri";
import { expect } from "jsr:@std/expect";
// Parse a tag URI
const tag = TagUri.parse("tag:[email protected],2001:web/externalHome");
// Access different parts of the tag URI
expect(tag.get()).toBe("tag:[email protected],2001:web/externalHome");
expect(tag.authorityName).toBe("[email protected]");
expect(tag.date).toBe("2001");
expect(tag.specific).toBe("web/externalHome");
import { TagUri } from "@cptpiepmatz/tag-uri";
import { expect } from "jsr:@std/expect";
// Create a new tag URI
const tag = new TagUri({
authorityName: {
emailAddress: "[email protected]",
dnsName: null,
},
date: {
year: "2001",
month: null,
day: null,
},
specific: "web/externalHome",
fragment: null,
});
expect(tag.get()).toBe("tag:[email protected],2001:web/externalHome");