Skip to main content

Built and signed on GitHub Actions

🏷️ RFC 4151 Tag URI parser and generator

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
a week ago (0.1.2)
Package root>README.md
<h1 align="center">@cptpiepmatz/tag-uri</h1> <p align="center"> <b> <a href="https://taguri.org">RFC 4151 Tag URI</a> parser and generator </b> </p> <br> <p align="center"> <a href="https://jsr.io/@cptpiepmatz/tag-uri"> <img alt="JSR Version" src="https://jsr.io/badges/@cptpiepmatz/tag-uri?style=for-the-badge"/> </a> <a href="https://github.com/cptpiepmatz/tag-uri/blob/main/LICENSE"> <img alt="License" src="https://img.shields.io/github/license/cptpiepmatz/tag-uri?style=for-the-badge"/> </a> </p> ## About 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](https://taguri.org) by parsing them into their components or allowing you to construct new ones programmatically. ## Features - **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](https://deno.com), [Node.js](https://nodejs.org), and modern browsers using [baseline web compatibility](https://developer.mozilla.org/en-US/docs/Glossary/Baseline/Compatibility). ## Usage ### Parsing Tag URIs ```ts 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"); ``` ### Constructing Tag URIs ```ts 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"); ```