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)
class TagUri

Data structure containing the contents of a tag: URI.

Instances of this class hold the data for tag: URIs as defined by the RFC 4151 or otherwise described by taguri.org.

Getting an instance of this can either be done by manually constructing one by passing all the necessary data into the constructor or by parsing a tag: URI string with parse.

By using TagUri.prototype.get, you can get the string representation of the tag. Other contained values can be accessed via the various getters. Some getters may return null as not every tag has to contain them (e.g. the day of the date).

Examples

Get a instance via parse

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");

Constructors

new
TagUri(data: TagUriData)

Properties

private
[internal]: TagUriData

Authority name of the tag: URI.

Represents the authorityName part of the RFC.

readonly
date: string

Date of the tag: URI.

Represents the date part of the RFC.

readonly
day: string | null

Day of the tag: URI.

Represents the day part of the RFC.

This value is nullable as date might contain only a month and year or only a year.

readonly
dnsName: string | null

DNS name of the authority name of the tag: URI.

Represents the DNSname part of the RFC.

This value is nullable as authorityName can be either a dns name or an email address.

readonly
emailAddress: string | null

Email address of the authority name of the tag: URI.

Represents the emailAddress part of the RFC.

This value is nullable as authorityName can be either a dns name or an email address.

readonly
fragment: string | null

Fragment of the tag: URI.

Represents the fragment part of the RFC.

Might be an empty string as they are valid according to the RFC. Might also be null if the # is omitted.

readonly
month: string | null

Month of the tag: URI.

Represents the month part of the RFC.

This value is nullable as date might contain only a year. The day will then be also null.

readonly
specific: string

Specific of the tag: URI.

Represents the specific part of the RFC.

Might be an empty string as they are valid according to the RFC.

Tagging entity of the tag: URI.

Represents the taggingEntity part of the RFC.

readonly
year: string

Year of the tag: URI.

Represents the year part of the RFC.

Methods

Compare two TagUri instances for equality.

This does a equality check on all fields in the internal, deconstructed representation. This allows comparing two instances without getting the string representation first.

Get the string representation of this tag: URI.

As the string is internally held in a deconstructed way, will this construct a new string every time this method is called.

Get the string representation of this instance.

Static Methods

Tries to parse a tag: URI.

Add Package

deno add jsr:@cptpiepmatz/tag-uri

Import symbol

import { TagUri } from "@cptpiepmatz/tag-uri";

---- OR ----

Import directly with a jsr specifier

import { TagUri } from "jsr:@cptpiepmatz/tag-uri";

Add Package

npx jsr add @cptpiepmatz/tag-uri

Import symbol

import { TagUri } from "@cptpiepmatz/tag-uri";

Add Package

yarn dlx jsr add @cptpiepmatz/tag-uri

Import symbol

import { TagUri } from "@cptpiepmatz/tag-uri";

Add Package

pnpm dlx jsr add @cptpiepmatz/tag-uri

Import symbol

import { TagUri } from "@cptpiepmatz/tag-uri";

Add Package

bunx jsr add @cptpiepmatz/tag-uri

Import symbol

import { TagUri } from "@cptpiepmatz/tag-uri";