@ndn/naming-convention2
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";
import { Name } from "@ndn/packet";
import { strict as assert } from "assert";
let name = new Name(["A", Keyword.create("metadata")]);
assert.equal(name.toString(), "/8=A/32=metadata");
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");
assert.equal(Segment.match(name.at(-1)), true);
assert.equal(Version.match(name.at(-1)), false);
assert.equal(name.at(-1).is(Segment), true);
assert.equal(name.at(-1).is(Version), false);
assert.equal(Keyword.parse(name.at(-3)), "metadata");
assert.equal(Version.parse(name.at(-2)), 3);
assert.equal(Segment.parse(name.at(-1)), 0);
assert.equal(name.at(-3).as(Keyword), "metadata");
assert.equal(name.at(-2).as(Version), 3);
assert.equal(name.at(-1).as(Segment), 0);
assert.equal(AltUri.ofName(name), "/A/32=metadata/v=3/seg=0");
assert.equal(AltUri.ofComponent(name.at(2)), "v=3");
assert(AltUri.parseName("/A/32=metadata/v=3/seg=0").equals(name));
assert(AltUri.parseComponent("v=3").equals(name.at(2)));