@cptpiepmatz/tag-uri@0.1.2Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
latest
cptpiepmatz/tag-uri🏷️ RFC 4151 Tag URI parser and generator
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
JSR Score
100%
Published
a week ago (0.1.2)
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283<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"); ```