• Public
  • Public/Protected
  • All


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

This package implements 2019-version NDN naming conventions as specified in NDN-TR-0022 revision 2 and Name Component Type Assignment rev12. For 2014-version naming conventions, use @ndn/naming-convention1 package.

import { Keyword, Version, Segment, AltUri } from "@ndn/naming-convention2";
// We also have ByteOffset, Timestamp, and SequenceNum.

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

// 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/35=%03");
name = name.append(Segment, 0);
assert.equal(name.toString(), "/8=A/32=metadata/35=%03/33=%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 "35=%03" as a "version 3" everywhere, because in some application
// 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.




Re-exports AltUri


Re-exports ByteOffset


Re-exports Keyword


Re-exports Segment


Re-exports SequenceNum


Re-exports Timestamp


Re-exports Version

Type aliases


NumberConvention: NamingConvention<number> & WithAltUri


TimestampConvention: NamingConvention<number | Date, number> & WithAltUri


Const AltUri

AltUri: AltUriConverter = new AltUriConverter([Segment,ByteOffset,Version,Timestamp,SequenceNum,...baseAltUri.conventions,])

Print conventions from this package in alternate URI syntax.

Const ByteOffset

ByteOffset: NumberConvention = new TypedNumber(0x22, "off")

ByteOffsetNameComponent, interpreted as number.

Const Keyword

Keyword: NamingConvention<string> = new TypedString(0x20)

KeywordNameComponent, interpreted as string.

Const Segment

Segment: NumberConvention = new TypedNumber(0x21, "seg")

SegmentNameComponent, interpreted as number.

Const SequenceNum

SequenceNum: NumberConvention = new TypedNumber(0x25, "seq")

SequenceNumNameComponent, interpreted as number.

Const Timestamp

Timestamp: NamingConvention<TimestampInput, number> & WithAltUri & { ms: TimestampConvention; us: TimestampConvention } = Object.assign(timestampMs,{/** TimestampNameComponent, interpreted as number in milliseconds. */ms: timestampMs,/** TimestampNameComponent, interpreted as number in microseconds. */us: new TypedTimestamp(1) as TimestampConvention,})

TimestampNameComponent, interpreted as number in milliseconds.

Const Version

Version: NumberConvention = new TypedNumber(0x23, "v")

VersionNameComponent, interpreted as number.

Const timestampMs

timestampMs: TimestampConvention = new TypedTimestamp(1000, 8787511468039992) as TimestampConvention

Const timestampNumber

timestampNumber: TypedNumber = new TypedNumber(0x24, "t")


  • Namespace
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Type alias
  • Type alias with type parameter
  • Interface
  • Interface with type parameter
  • Class
  • Class with type parameter
  • Enumeration

Generated using TypeDoc