New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ndn/naming-convention2

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ndn/naming-convention2 - npm Package Compare versions

Comparing version

to
0.0.20230121

36

lib/conventions_browser.js

@@ -1,4 +0,5 @@

import { Component } from "@ndn/packet";
import { Component, TT } from "@ndn/packet";
import { Encoder, NNI } from "@ndn/tlv";
class Typed {
tt;
constructor(tt) {

@@ -20,6 +21,8 @@ this.tt = tt;

class TypedNumberBase extends Typed {
altUriPrefix;
altUriRegex;
constructor(tt, altUriPrefix) {
super(tt);
this.altUriPrefix = altUriPrefix;
this.altUriRegex = new RegExp(`^${altUriPrefix}=(\\d+)$`);
this.altUriRegex = new RegExp(`^${altUriPrefix}(\\d+)$`);
}

@@ -36,3 +39,3 @@ create(v) {

toAltUri(comp) {
return `${this.altUriPrefix}=${this.parseRaw(comp)}`;
return `${this.altUriPrefix}${this.parseRaw(comp)}`;
}

@@ -62,6 +65,9 @@ fromAltUri(input) {

}
big;
}
class TypedTimestamp extends TypedNumber {
unit;
max;
constructor(tt, unit, max = Number.MAX_SAFE_INTEGER) {
super(tt, "t");
super(tt, "t=");
this.unit = unit;

@@ -96,20 +102,26 @@ this.max = max;

}
/**
* GenericNameComponent enclosing a number.
*
* This is not really a naming convention, but it's used in several protocols.
*/
export const GenericNumber = new TypedNumberBig(TT.GenericNameComponent, "");
/** KeywordNameComponent (rev2 & rev3), interpreted as string. */
export const Keyword = new TypedString(0x20);
/** SegmentNameComponent (rev2), interpreted as number. */
export const Segment2 = new TypedNumberBig(0x21, "seg");
export const Segment2 = new TypedNumberBig(0x21, "seg=");
/** SegmentNameComponent (rev3), interpreted as number. */
export const Segment3 = new TypedNumberBig(0x32, "seg");
export const Segment3 = new TypedNumberBig(0x32, "seg=");
/** SegmentNameComponent (default format, currently rev3). */
export const Segment = Segment3;
/** ByteOffsetNameComponent (rev2), interpreted as number. */
export const ByteOffset2 = new TypedNumberBig(0x22, "off");
export const ByteOffset2 = new TypedNumberBig(0x22, "off=");
/** ByteOffsetNameComponent (rev3), interpreted as number. */
export const ByteOffset3 = new TypedNumberBig(0x34, "off");
export const ByteOffset3 = new TypedNumberBig(0x34, "off=");
/** ByteOffsetNameComponent (default format, currently rev3). */
export const ByteOffset = ByteOffset3;
/** VersionNameComponent (rev2), interpreted as number. */
export const Version2 = new TypedNumberBig(0x23, "v");
export const Version2 = new TypedNumberBig(0x23, "v=");
/** VersionNameComponent (rev3), interpreted as number. */
export const Version3 = new TypedNumberBig(0x36, "v");
export const Version3 = new TypedNumberBig(0x36, "v=");
/** VersionNameComponent (default format, currently rev3). */

@@ -124,6 +136,6 @@ export const Version = Version3;

/** SequenceNumNameComponent (rev2), interpreted as number. */
export const SequenceNum2 = new TypedNumberBig(0x25, "seq");
export const SequenceNum2 = new TypedNumberBig(0x25, "seq=");
/** SequenceNumNameComponent (rev3), interpreted as number. */
export const SequenceNum3 = new TypedNumberBig(0x3A, "seq");
export const SequenceNum3 = new TypedNumberBig(0x3A, "seq=");
/** SequenceNumNameComponent (default format, currently rev3). */
export const SequenceNum = SequenceNum3;

@@ -1,4 +0,5 @@

import { Component } from "@ndn/packet";
import { Component, TT } from "@ndn/packet";
import { Encoder, NNI } from "@ndn/tlv";
class Typed {
tt;
constructor(tt) {

@@ -20,6 +21,8 @@ this.tt = tt;

class TypedNumberBase extends Typed {
altUriPrefix;
altUriRegex;
constructor(tt, altUriPrefix) {
super(tt);
this.altUriPrefix = altUriPrefix;
this.altUriRegex = new RegExp(`^${altUriPrefix}=(\\d+)$`);
this.altUriRegex = new RegExp(`^${altUriPrefix}(\\d+)$`);
}

@@ -36,3 +39,3 @@ create(v) {

toAltUri(comp) {
return `${this.altUriPrefix}=${this.parseRaw(comp)}`;
return `${this.altUriPrefix}${this.parseRaw(comp)}`;
}

@@ -62,6 +65,9 @@ fromAltUri(input) {

}
big;
}
class TypedTimestamp extends TypedNumber {
unit;
max;
constructor(tt, unit, max = Number.MAX_SAFE_INTEGER) {
super(tt, "t");
super(tt, "t=");
this.unit = unit;

@@ -96,20 +102,26 @@ this.max = max;

}
/**
* GenericNameComponent enclosing a number.
*
* This is not really a naming convention, but it's used in several protocols.
*/
export const GenericNumber = new TypedNumberBig(TT.GenericNameComponent, "");
/** KeywordNameComponent (rev2 & rev3), interpreted as string. */
export const Keyword = new TypedString(0x20);
/** SegmentNameComponent (rev2), interpreted as number. */
export const Segment2 = new TypedNumberBig(0x21, "seg");
export const Segment2 = new TypedNumberBig(0x21, "seg=");
/** SegmentNameComponent (rev3), interpreted as number. */
export const Segment3 = new TypedNumberBig(0x32, "seg");
export const Segment3 = new TypedNumberBig(0x32, "seg=");
/** SegmentNameComponent (default format, currently rev3). */
export const Segment = Segment3;
/** ByteOffsetNameComponent (rev2), interpreted as number. */
export const ByteOffset2 = new TypedNumberBig(0x22, "off");
export const ByteOffset2 = new TypedNumberBig(0x22, "off=");
/** ByteOffsetNameComponent (rev3), interpreted as number. */
export const ByteOffset3 = new TypedNumberBig(0x34, "off");
export const ByteOffset3 = new TypedNumberBig(0x34, "off=");
/** ByteOffsetNameComponent (default format, currently rev3). */
export const ByteOffset = ByteOffset3;
/** VersionNameComponent (rev2), interpreted as number. */
export const Version2 = new TypedNumberBig(0x23, "v");
export const Version2 = new TypedNumberBig(0x23, "v=");
/** VersionNameComponent (rev3), interpreted as number. */
export const Version3 = new TypedNumberBig(0x36, "v");
export const Version3 = new TypedNumberBig(0x36, "v=");
/** VersionNameComponent (default format, currently rev3). */

@@ -124,6 +136,6 @@ export const Version = Version3;

/** SequenceNumNameComponent (rev2), interpreted as number. */
export const SequenceNum2 = new TypedNumberBig(0x25, "seq");
export const SequenceNum2 = new TypedNumberBig(0x25, "seq=");
/** SequenceNumNameComponent (rev3), interpreted as number. */
export const SequenceNum3 = new TypedNumberBig(0x3A, "seq");
export const SequenceNum3 = new TypedNumberBig(0x3A, "seq=");
/** SequenceNumNameComponent (default format, currently rev3). */
export const SequenceNum = SequenceNum3;

@@ -13,2 +13,8 @@ import { type NamingConvention } from "@ndn/packet";

}
/**
* GenericNameComponent enclosing a number.
*
* This is not really a naming convention, but it's used in several protocols.
*/
export declare const GenericNumber: NumberBigConvention;
/** KeywordNameComponent (rev2 & rev3), interpreted as string. */

@@ -15,0 +21,0 @@ export declare const Keyword: NamingConvention<string>;

@@ -1,2 +0,2 @@

export * from "./conventions";
export * from "./alt-uri";
export * from "./conventions.js";
export * from "./alt-uri.js";
{
"name": "@ndn/naming-convention2",
"version": "0.0.20220501",
"version": "0.0.20230121",
"description": "NDNts: Naming Convention rev2 and rev3",

@@ -25,8 +25,7 @@ "keywords": [

"dependencies": {
"@ndn/packet": "0.0.20220501",
"@ndn/tlv": "0.0.20220501",
"tslib": "^2.4.0"
"@ndn/packet": "0.0.20230121",
"@ndn/tlv": "0.0.20230121",
"tslib": "^2.4.1"
},
"types": "lib/mod.d.ts",
"readme": "# @ndn/naming-convention2\n\nThis package is part of [NDNts](https://yoursunny.com/p/NDNts/), Named Data Networking libraries for the modern web.\n\nThis package implements NDN naming conventions based on typed components.\n\nThe current format, sometimes known as **rev3 format**, is specified in [NDN-TR-0022 revision 3](https://named-data.net/publications/techreports/ndn-tr-22-3-ndn-memo-naming-conventions/) and [Name Component Type Assignment rev28](https://redmine.named-data.net/projects/ndn-tlv/wiki/NameComponentType/28), published in 2021.\nIt is supported in most other libraries and recommended for new applications.\n\n```ts\nimport { Keyword, Version, Segment, AltUri } from \"@ndn/naming-convention2\";\n// We also have ByteOffset, Timestamp, SequenceNum.\n\n// other imports for examples\nimport { Name } from \"@ndn/packet\";\nimport { strict as assert } from \"node:assert\";\n\n// convention.create() returns a Component.\nlet name = new Name([\"A\", Keyword.create(\"metadata\")]);\nassert.equal(name.toString(), \"/8=A/32=metadata\");\n\n// name.append() has an overload for convention component.\nname = name.append(Version, 3);\nassert.equal(name.toString(), \"/8=A/32=metadata/54=%03\");\nname = name.append(Segment, 0);\nassert.equal(name.toString(), \"/8=A/32=metadata/54=%03/50=%00\");\n\n// convention.match() checks whether a Component follows the convention.\nassert.equal(Segment.match(name.at(-1)), true);\nassert.equal(Version.match(name.at(-1)), false);\n\n// Or you can use component.is().\nassert.equal(name.at(-1).is(Segment), true);\nassert.equal(name.at(-1).is(Version), false);\n\n// convention.parse() extracts the value from a Component.\nassert.equal(Keyword.parse(name.at(-3)), \"metadata\");\nassert.equal(Version.parse(name.at(-2)), 3);\nassert.equal(Segment.parse(name.at(-1)), 0);\n\n// Or you can use component.as().\nassert.equal(name.at(-3).as(Keyword), \"metadata\");\nassert.equal(name.at(-2).as(Version), 3);\nassert.equal(name.at(-1).as(Segment), 0);\n\n// If you need alternate URI syntax, use AltUri.ofName() or AltUri.ofComponent().\n// Make sure you are importing AltUri from this package, not from @ndn/packet package.\nassert.equal(AltUri.ofName(name), \"/A/32=metadata/v=3/seg=0\");\nassert.equal(AltUri.ofComponent(name.at(2)), \"v=3\");\n// This feature is not in the regular component.toString() and name.toString() methods,\n// because not every application would adopt this particular set of naming conventions.\n// It is incorrect to interpret \"54=%03\" as \"version 3\" everywhere, because in some applications\n// it could mean something completely different.\n// Using AltUri from this package indicates you have adopted these naming conventions.\n\n// Use AltUri.parseName() and AltUri.parseComponent() to parse from alternate URI syntax.\nassert(AltUri.parseName(\"/A/32=metadata/v=3/seg=0\").equals(name));\nassert(AltUri.parseComponent(\"v=3\").equals(name.at(2)));\n```\n\nThis package also implements **rev2 format**, as specified in [NDN-TR-0022 revision 2](https://named-data.net/publications/techreports/ndn-tr-22-2-ndn-memo-naming-conventions/) and [Name Component Type Assignment rev17](https://redmine.named-data.net/projects/ndn-tlv/wiki/NameComponentType/17), published in 2019.\nImport `Segment2`, `ByteOffset2`, `Version2`, `Timestamp2`, `SequenceNum2`, `AltUri2` to access this format.\nYou should not use this outdated and obsolete format in new applications, except for accessing old data.\n"
"types": "lib/mod.d.ts"
}

@@ -12,3 +12,4 @@ # @ndn/naming-convention2

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

@@ -15,0 +16,0 @@ // other imports for examples

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

@@ -42,3 +43,3 @@ // other imports for examples

// because not every application would adopt this particular set of naming conventions.
// It is incorrect to interpret "54=%03" as a "version 3" everywhere, because in some application
// It is incorrect to interpret "54=%03" as "version 3" everywhere, because in some applications
// it could mean something completely different.

@@ -45,0 +46,0 @@ // Using AltUri from this package indicates you have adopted these naming conventions.

Sorry, the diff of this file is not supported yet