npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ndn/naming-convention2

v0.0.20240113

Published

NDNts: Naming Convention rev2 and rev3

Downloads

33

Readme

@ndn/naming-convention2

This package is part of NDNts, Named Data Networking libraries for the modern web.

This package implements NDN naming conventions based on typed components.

The current format, sometimes known as rev3 format, is specified in NDN-TR-0022 revision 3 and Name Component Type Assignment rev29, published in 2021. It is supported in most other libraries and recommended for new applications.

import { Keyword, Version, Segment, AltUri } from "@ndn/naming-convention2";
// We also have ByteOffset, Timestamp, SequenceNum conventions,
// as well as GenericNumber that puts NonNegativeInteger into GenericNameComponent.

// other imports for examples
import { Name } from "@ndn/packet";
import assert from "node:assert/strict";

// convention.create() returns a Component.
let name = new Name(["A", Keyword.create("metadata")]);
assert.equal(name.toString(), "/8=A/32=metadata");

// name.append() has an overload for convention component.
name = name.append(Version, 3);
assert.equal(name.toString(), "/8=A/32=metadata/54=%03");
name = name.append(Segment, 0);
assert.equal(name.toString(), "/8=A/32=metadata/54=%03/50=%00");

// convention.match() checks whether a Component follows the convention.
assert.equal(Segment.match(name.at(-1)), true);
assert.equal(Version.match(name.at(-1)), false);

// Or you can use component.is().
assert.equal(name.at(-1).is(Segment), true);
assert.equal(name.at(-1).is(Version), false);

// convention.parse() extracts the value from a Component.
assert.equal(Keyword.parse(name.at(-3)), "metadata");
assert.equal(Version.parse(name.at(-2)), 3);
assert.equal(Segment.parse(name.at(-1)), 0);

// Or you can use component.as().
assert.equal(name.at(-3).as(Keyword), "metadata");
assert.equal(name.at(-2).as(Version), 3);
assert.equal(name.at(-1).as(Segment), 0);

// If you need alternate URI syntax, use AltUri.ofName() or AltUri.ofComponent().
// Make sure you are importing AltUri from this package, not from @ndn/packet package.
assert.equal(AltUri.ofName(name), "/A/32=metadata/v=3/seg=0");
assert.equal(AltUri.ofComponent(name.at(2)), "v=3");
// This feature is not in the regular component.toString() and name.toString() methods,
// because not every application would adopt this particular set of naming conventions.
// It is incorrect to interpret "54=%03" as "version 3" everywhere, because in some applications
// it could mean something completely different.
// Using AltUri from this package indicates you have adopted these naming conventions.

// Use AltUri.parseName() and AltUri.parseComponent() to parse from alternate URI syntax.
assert(AltUri.parseName("/A/32=metadata/v=3/seg=0").equals(name));
assert(AltUri.parseComponent("v=3").equals(name.at(2)));

This package also implements rev2 format, as specified in NDN-TR-0022 revision 2 and Name Component Type Assignment rev17, published in 2019. Import Segment2, ByteOffset2, Version2, Timestamp2, SequenceNum2, AltUri2 to access this format. You should not use this outdated and obsolete format in new applications, except for accessing old data.