@aidc-toolkit/gs1 1.0.42-beta → 1.0.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +19 -0
- package/dist/index.d.cts +2205 -0
- package/dist/index.d.ts +2205 -63
- package/dist/index.js +3 -36
- package/package.json +4 -4
- package/src/gcp-length.ts +55 -18
- package/test/gcp-length.test.ts +12 -7
- package/tsconfig-src.tsbuildinfo +1 -1
- package/dist/abstract-identifier-creator.d.ts +0 -41
- package/dist/abstract-identifier-creator.d.ts.map +0 -1
- package/dist/abstract-identifier-creator.js +0 -73
- package/dist/abstract-identifier-creator.js.map +0 -1
- package/dist/abstract-non-gtin-numeric-identifier-creator.d.ts +0 -36
- package/dist/abstract-non-gtin-numeric-identifier-creator.d.ts.map +0 -1
- package/dist/abstract-non-gtin-numeric-identifier-creator.js +0 -37
- package/dist/abstract-non-gtin-numeric-identifier-creator.js.map +0 -1
- package/dist/abstract-numeric-identifier-creator.d.ts +0 -34
- package/dist/abstract-numeric-identifier-creator.d.ts.map +0 -1
- package/dist/abstract-numeric-identifier-creator.js +0 -154
- package/dist/abstract-numeric-identifier-creator.js.map +0 -1
- package/dist/character-set.d.ts +0 -27
- package/dist/character-set.d.ts.map +0 -1
- package/dist/character-set.js +0 -83
- package/dist/character-set.js.map +0 -1
- package/dist/check.d.ts +0 -81
- package/dist/check.d.ts.map +0 -1
- package/dist/check.js +0 -218
- package/dist/check.js.map +0 -1
- package/dist/content-character-set-creators.d.ts +0 -4
- package/dist/content-character-set-creators.d.ts.map +0 -1
- package/dist/content-character-set-creators.js +0 -9
- package/dist/content-character-set-creators.js.map +0 -1
- package/dist/content-character-set.d.ts +0 -26
- package/dist/content-character-set.d.ts.map +0 -1
- package/dist/content-character-set.js +0 -18
- package/dist/content-character-set.js.map +0 -1
- package/dist/gcp-length-cache.d.ts +0 -86
- package/dist/gcp-length-cache.d.ts.map +0 -1
- package/dist/gcp-length-cache.js +0 -237
- package/dist/gcp-length-cache.js.map +0 -1
- package/dist/gcp-length-data.d.ts +0 -108
- package/dist/gcp-length-data.d.ts.map +0 -1
- package/dist/gcp-length-data.js +0 -53
- package/dist/gcp-length-data.js.map +0 -1
- package/dist/gcp-length-tree.d.ts +0 -33
- package/dist/gcp-length-tree.d.ts.map +0 -1
- package/dist/gcp-length-tree.js +0 -13
- package/dist/gcp-length-tree.js.map +0 -1
- package/dist/gcp-length.d.ts +0 -75
- package/dist/gcp-length.d.ts.map +0 -1
- package/dist/gcp-length.js +0 -357
- package/dist/gcp-length.js.map +0 -1
- package/dist/gtin-creator.d.ts +0 -47
- package/dist/gtin-creator.d.ts.map +0 -1
- package/dist/gtin-creator.js +0 -64
- package/dist/gtin-creator.js.map +0 -1
- package/dist/gtin-descriptor.d.ts +0 -22
- package/dist/gtin-descriptor.d.ts.map +0 -1
- package/dist/gtin-descriptor.js +0 -2
- package/dist/gtin-descriptor.js.map +0 -1
- package/dist/gtin-length.d.ts +0 -64
- package/dist/gtin-length.d.ts.map +0 -1
- package/dist/gtin-length.js +0 -36
- package/dist/gtin-length.js.map +0 -1
- package/dist/gtin-type.d.ts +0 -26
- package/dist/gtin-type.d.ts.map +0 -1
- package/dist/gtin-type.js +0 -7
- package/dist/gtin-type.js.map +0 -1
- package/dist/gtin-validator.d.ts +0 -132
- package/dist/gtin-validator.d.ts.map +0 -1
- package/dist/gtin-validator.js +0 -349
- package/dist/gtin-validator.js.map +0 -1
- package/dist/identifier-creator.d.ts +0 -31
- package/dist/identifier-creator.d.ts.map +0 -1
- package/dist/identifier-creator.js +0 -2
- package/dist/identifier-creator.js.map +0 -1
- package/dist/identifier-creators.d.ts +0 -118
- package/dist/identifier-creators.d.ts.map +0 -1
- package/dist/identifier-creators.js +0 -92
- package/dist/identifier-creators.js.map +0 -1
- package/dist/identifier-descriptor.d.ts +0 -27
- package/dist/identifier-descriptor.d.ts.map +0 -1
- package/dist/identifier-descriptor.js +0 -2
- package/dist/identifier-descriptor.js.map +0 -1
- package/dist/identifier-descriptors.d.ts +0 -106
- package/dist/identifier-descriptors.d.ts.map +0 -1
- package/dist/identifier-descriptors.js +0 -262
- package/dist/identifier-descriptors.js.map +0 -1
- package/dist/identifier-extension.d.ts +0 -82
- package/dist/identifier-extension.d.ts.map +0 -1
- package/dist/identifier-extension.js +0 -79
- package/dist/identifier-extension.js.map +0 -1
- package/dist/identifier-type.d.ts +0 -62
- package/dist/identifier-type.d.ts.map +0 -1
- package/dist/identifier-type.js +0 -54
- package/dist/identifier-type.js.map +0 -1
- package/dist/identifier-validator.d.ts +0 -85
- package/dist/identifier-validator.d.ts.map +0 -1
- package/dist/identifier-validator.js +0 -107
- package/dist/identifier-validator.js.map +0 -1
- package/dist/identifier-validators.d.ts +0 -131
- package/dist/identifier-validators.d.ts.map +0 -1
- package/dist/identifier-validators.js +0 -167
- package/dist/identifier-validators.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/leader-type.d.ts +0 -26
- package/dist/leader-type.d.ts.map +0 -1
- package/dist/leader-type.js +0 -18
- package/dist/leader-type.js.map +0 -1
- package/dist/locale/en/locale-resources.d.ts +0 -48
- package/dist/locale/en/locale-resources.d.ts.map +0 -1
- package/dist/locale/en/locale-resources.js +0 -47
- package/dist/locale/en/locale-resources.js.map +0 -1
- package/dist/locale/fr/locale-resources.d.ts +0 -48
- package/dist/locale/fr/locale-resources.d.ts.map +0 -1
- package/dist/locale/fr/locale-resources.js +0 -47
- package/dist/locale/fr/locale-resources.js.map +0 -1
- package/dist/locale/i18n.d.ts +0 -27
- package/dist/locale/i18n.d.ts.map +0 -1
- package/dist/locale/i18n.js +0 -35
- package/dist/locale/i18n.js.map +0 -1
- package/dist/non-gtin-numeric-identifier-creator.d.ts +0 -12
- package/dist/non-gtin-numeric-identifier-creator.d.ts.map +0 -1
- package/dist/non-gtin-numeric-identifier-creator.js +0 -2
- package/dist/non-gtin-numeric-identifier-creator.js.map +0 -1
- package/dist/non-gtin-numeric-identifier-descriptor.d.ts +0 -22
- package/dist/non-gtin-numeric-identifier-descriptor.d.ts.map +0 -1
- package/dist/non-gtin-numeric-identifier-descriptor.js +0 -2
- package/dist/non-gtin-numeric-identifier-descriptor.js.map +0 -1
- package/dist/non-gtin-numeric-identifier-type.d.ts +0 -26
- package/dist/non-gtin-numeric-identifier-type.d.ts.map +0 -1
- package/dist/non-gtin-numeric-identifier-type.js +0 -8
- package/dist/non-gtin-numeric-identifier-type.js.map +0 -1
- package/dist/non-gtin-numeric-identifier-validator.d.ts +0 -12
- package/dist/non-gtin-numeric-identifier-validator.d.ts.map +0 -1
- package/dist/non-gtin-numeric-identifier-validator.js +0 -10
- package/dist/non-gtin-numeric-identifier-validator.js.map +0 -1
- package/dist/non-numeric-identifier-creator.d.ts +0 -40
- package/dist/non-numeric-identifier-creator.d.ts.map +0 -1
- package/dist/non-numeric-identifier-creator.js +0 -82
- package/dist/non-numeric-identifier-creator.js.map +0 -1
- package/dist/non-numeric-identifier-descriptor.d.ts +0 -26
- package/dist/non-numeric-identifier-descriptor.d.ts.map +0 -1
- package/dist/non-numeric-identifier-descriptor.js +0 -2
- package/dist/non-numeric-identifier-descriptor.js.map +0 -1
- package/dist/non-numeric-identifier-type.d.ts +0 -26
- package/dist/non-numeric-identifier-type.d.ts.map +0 -1
- package/dist/non-numeric-identifier-type.js +0 -8
- package/dist/non-numeric-identifier-type.js.map +0 -1
- package/dist/non-numeric-identifier-validator.d.ts +0 -41
- package/dist/non-numeric-identifier-validator.d.ts.map +0 -1
- package/dist/non-numeric-identifier-validator.js +0 -69
- package/dist/non-numeric-identifier-validator.js.map +0 -1
- package/dist/non-serializable-numeric-identifier-creator.d.ts +0 -10
- package/dist/non-serializable-numeric-identifier-creator.d.ts.map +0 -1
- package/dist/non-serializable-numeric-identifier-creator.js +0 -8
- package/dist/non-serializable-numeric-identifier-creator.js.map +0 -1
- package/dist/non-serializable-numeric-identifier-descriptor.d.ts +0 -12
- package/dist/non-serializable-numeric-identifier-descriptor.d.ts.map +0 -1
- package/dist/non-serializable-numeric-identifier-descriptor.js +0 -2
- package/dist/non-serializable-numeric-identifier-descriptor.js.map +0 -1
- package/dist/non-serializable-numeric-identifier-type.d.ts +0 -26
- package/dist/non-serializable-numeric-identifier-type.d.ts.map +0 -1
- package/dist/non-serializable-numeric-identifier-type.js +0 -7
- package/dist/non-serializable-numeric-identifier-type.js.map +0 -1
- package/dist/non-serializable-numeric-identifier-validator.d.ts +0 -16
- package/dist/non-serializable-numeric-identifier-validator.d.ts.map +0 -1
- package/dist/non-serializable-numeric-identifier-validator.js +0 -17
- package/dist/non-serializable-numeric-identifier-validator.js.map +0 -1
- package/dist/numeric-identifier-creator.d.ts +0 -53
- package/dist/numeric-identifier-creator.d.ts.map +0 -1
- package/dist/numeric-identifier-creator.js +0 -2
- package/dist/numeric-identifier-creator.js.map +0 -1
- package/dist/numeric-identifier-descriptor.d.ts +0 -22
- package/dist/numeric-identifier-descriptor.d.ts.map +0 -1
- package/dist/numeric-identifier-descriptor.js +0 -2
- package/dist/numeric-identifier-descriptor.js.map +0 -1
- package/dist/numeric-identifier-type.d.ts +0 -26
- package/dist/numeric-identifier-type.d.ts.map +0 -1
- package/dist/numeric-identifier-type.js +0 -7
- package/dist/numeric-identifier-type.js.map +0 -1
- package/dist/numeric-identifier-validator.d.ts +0 -38
- package/dist/numeric-identifier-validator.d.ts.map +0 -1
- package/dist/numeric-identifier-validator.js +0 -61
- package/dist/numeric-identifier-validator.js.map +0 -1
- package/dist/prefix-manager.d.ts +0 -151
- package/dist/prefix-manager.d.ts.map +0 -1
- package/dist/prefix-manager.js +0 -297
- package/dist/prefix-manager.js.map +0 -1
- package/dist/prefix-provider.d.ts +0 -27
- package/dist/prefix-provider.d.ts.map +0 -1
- package/dist/prefix-provider.js +0 -2
- package/dist/prefix-provider.js.map +0 -1
- package/dist/prefix-type.d.ts +0 -26
- package/dist/prefix-type.d.ts.map +0 -1
- package/dist/prefix-type.js +0 -18
- package/dist/prefix-type.js.map +0 -1
- package/dist/prefix-validator.d.ts +0 -71
- package/dist/prefix-validator.d.ts.map +0 -1
- package/dist/prefix-validator.js +0 -204
- package/dist/prefix-validator.js.map +0 -1
- package/dist/serializable-numeric-identifier-creator.d.ts +0 -48
- package/dist/serializable-numeric-identifier-creator.d.ts.map +0 -1
- package/dist/serializable-numeric-identifier-creator.js +0 -93
- package/dist/serializable-numeric-identifier-creator.js.map +0 -1
- package/dist/serializable-numeric-identifier-descriptor.d.ts +0 -26
- package/dist/serializable-numeric-identifier-descriptor.d.ts.map +0 -1
- package/dist/serializable-numeric-identifier-descriptor.js +0 -2
- package/dist/serializable-numeric-identifier-descriptor.js.map +0 -1
- package/dist/serializable-numeric-identifier-type.d.ts +0 -26
- package/dist/serializable-numeric-identifier-type.d.ts.map +0 -1
- package/dist/serializable-numeric-identifier-type.js +0 -8
- package/dist/serializable-numeric-identifier-type.js.map +0 -1
- package/dist/serializable-numeric-identifier-validator.d.ts +0 -67
- package/dist/serializable-numeric-identifier-validator.d.ts.map +0 -1
- package/dist/serializable-numeric-identifier-validator.js +0 -97
- package/dist/serializable-numeric-identifier-validator.js.map +0 -1
- package/dist/variable-measure.d.ts +0 -68
- package/dist/variable-measure.d.ts.map +0 -1
- package/dist/variable-measure.js +0 -210
- package/dist/variable-measure.js.map +0 -1
- package/dist/verified-by-gs1.d.ts +0 -22
- package/dist/verified-by-gs1.d.ts.map +0 -1
- package/dist/verified-by-gs1.js +0 -46
- package/dist/verified-by-gs1.js.map +0 -1
- package/src/gcp-length-tree.ts +0 -39
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"numeric-identifier-type.d.ts","sourceRoot":"","sources":["../src/numeric-identifier-type.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;uEASlC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,MAAM,OAAO,sBAAsB,CAAC;AAE3E;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,OAAO,sBAAsB,CAAC,wBAAwB,CAAC,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { pick } from "@aidc-toolkit/core";
|
|
2
|
-
import { IdentifierTypes } from "./identifier-type.js";
|
|
3
|
-
/**
|
|
4
|
-
* Numeric identifier types.
|
|
5
|
-
*/
|
|
6
|
-
export const NumericIdentifierTypes = pick(IdentifierTypes, IdentifierTypes.GTIN, IdentifierTypes.GLN, IdentifierTypes.SSCC, IdentifierTypes.GRAI, IdentifierTypes.GSRN, IdentifierTypes.GDTI, IdentifierTypes.GSIN, IdentifierTypes.GCN);
|
|
7
|
-
//# sourceMappingURL=numeric-identifier-type.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"numeric-identifier-type.js","sourceRoot":"","sources":["../src/numeric-identifier-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC,eAAe,EACtD,eAAe,CAAC,IAAI,EACpB,eAAe,CAAC,GAAG,EACnB,eAAe,CAAC,IAAI,EACpB,eAAe,CAAC,IAAI,EACpB,eAAe,CAAC,IAAI,EACpB,eAAe,CAAC,IAAI,EACpB,eAAe,CAAC,IAAI,EACpB,eAAe,CAAC,GAAG,CACtB,CAAC"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { IdentifierTypeDescriptor } from "./identifier-descriptors.js";
|
|
2
|
-
import { type IdentifierValidation, IdentifierValidator } from "./identifier-validator.js";
|
|
3
|
-
import type { NumericIdentifierDescriptor } from "./numeric-identifier-descriptor.js";
|
|
4
|
-
import type { NumericIdentifierType } from "./numeric-identifier-type.js";
|
|
5
|
-
/**
|
|
6
|
-
* Numeric identifier validation parameters.
|
|
7
|
-
*/
|
|
8
|
-
export interface NumericIdentifierValidation extends IdentifierValidation {
|
|
9
|
-
/**
|
|
10
|
-
* Position offset within a larger string. Some numeric identifier types have the prefix offset by one.
|
|
11
|
-
*/
|
|
12
|
-
positionOffset?: number | undefined;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Numeric identifier validator.
|
|
16
|
-
*
|
|
17
|
-
* @template TNumericIdentifierType
|
|
18
|
-
* Numeric identifier type type.
|
|
19
|
-
*/
|
|
20
|
-
export declare abstract class NumericIdentifierValidator<TNumericIdentifierType extends NumericIdentifierType = NumericIdentifierType> extends IdentifierValidator<TNumericIdentifierType, NumericIdentifierValidation> implements NumericIdentifierDescriptor {
|
|
21
|
-
#private;
|
|
22
|
-
/**
|
|
23
|
-
* Constructor.
|
|
24
|
-
*
|
|
25
|
-
* @param identifierDescriptor
|
|
26
|
-
* Identifier descriptor.
|
|
27
|
-
*/
|
|
28
|
-
constructor(identifierDescriptor: IdentifierTypeDescriptor<TNumericIdentifierType>);
|
|
29
|
-
/**
|
|
30
|
-
* @inheritDoc
|
|
31
|
-
*/
|
|
32
|
-
get leaderType(): IdentifierTypeDescriptor<TNumericIdentifierType>["leaderType"];
|
|
33
|
-
/**
|
|
34
|
-
* @inheritDoc
|
|
35
|
-
*/
|
|
36
|
-
validate(identifier: string, validation?: NumericIdentifierValidation): void;
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=numeric-identifier-validator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"numeric-identifier-validator.d.ts","sourceRoot":"","sources":["../src/numeric-identifier-validator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EAAE,KAAK,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAG3F,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AACtF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,2BAA4B,SAAQ,oBAAoB;IACrE;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACvC;AAED;;;;;GAKG;AACH,8BAAsB,0BAA0B,CAAC,sBAAsB,SAAS,qBAAqB,GAAG,qBAAqB,CAAE,SAAQ,mBAAmB,CAAC,sBAAsB,EAAE,2BAA2B,CAAE,YAAW,2BAA2B;;IAWlP;;;;;OAKG;gBACS,oBAAoB,EAAE,wBAAwB,CAAC,sBAAsB,CAAC;IAOlF;;OAEG;IACH,IAAI,UAAU,IAAI,wBAAwB,CAAC,sBAAsB,CAAC,CAAC,YAAY,CAAC,CAE/E;IAED;;OAEG;IACM,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,2BAA2B,GAAG,IAAI;CAqBxF"}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { hasValidCheckDigit } from "./check.js";
|
|
2
|
-
import { IdentifierValidator } from "./identifier-validator.js";
|
|
3
|
-
import { LeaderTypes } from "./leader-type.js";
|
|
4
|
-
import { i18nextGS1 } from "./locale/i18n.js";
|
|
5
|
-
/**
|
|
6
|
-
* Numeric identifier validator.
|
|
7
|
-
*
|
|
8
|
-
* @template TNumericIdentifierType
|
|
9
|
-
* Numeric identifier type type.
|
|
10
|
-
*/
|
|
11
|
-
export class NumericIdentifierValidator extends IdentifierValidator {
|
|
12
|
-
/**
|
|
13
|
-
* Leader type.
|
|
14
|
-
*/
|
|
15
|
-
#leaderType;
|
|
16
|
-
/**
|
|
17
|
-
* Prefix position, determined by the leader type.
|
|
18
|
-
*/
|
|
19
|
-
#prefixPosition;
|
|
20
|
-
/**
|
|
21
|
-
* Constructor.
|
|
22
|
-
*
|
|
23
|
-
* @param identifierDescriptor
|
|
24
|
-
* Identifier descriptor.
|
|
25
|
-
*/
|
|
26
|
-
constructor(identifierDescriptor) {
|
|
27
|
-
super(identifierDescriptor);
|
|
28
|
-
this.#leaderType = identifierDescriptor.leaderType;
|
|
29
|
-
this.#prefixPosition = Number(this.leaderType === LeaderTypes.ExtensionDigit);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* @inheritDoc
|
|
33
|
-
*/
|
|
34
|
-
get leaderType() {
|
|
35
|
-
return this.#leaderType;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* @inheritDoc
|
|
39
|
-
*/
|
|
40
|
-
validate(identifier, validation) {
|
|
41
|
-
// Validate the prefix, with care taken for its position within the identifier.
|
|
42
|
-
if (this.#prefixPosition === 0) {
|
|
43
|
-
super.validatePrefix(identifier);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
super.validatePrefix(identifier.substring(this.#prefixPosition));
|
|
47
|
-
}
|
|
48
|
-
// Validate the length.
|
|
49
|
-
if (identifier.length !== this.length) {
|
|
50
|
-
throw new RangeError(i18nextGS1.t("Identifier.identifierTypeLength", {
|
|
51
|
-
identifierType: this.identifierType,
|
|
52
|
-
length: this.length
|
|
53
|
-
}));
|
|
54
|
-
}
|
|
55
|
-
// Validating the check digit will also validate the characters.
|
|
56
|
-
if (!hasValidCheckDigit(this.padIdentifier(identifier, validation?.positionOffset))) {
|
|
57
|
-
throw new RangeError(i18nextGS1.t("Identifier.invalidCheckDigit"));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=numeric-identifier-validator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"numeric-identifier-validator.js","sourceRoot":"","sources":["../src/numeric-identifier-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EAA6B,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAC3F,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EA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CAAC;QACvE,CAAC;IACL,CAAC;CACJ"}
|
package/dist/prefix-manager.d.ts
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import type { GTINCreator } from "./gtin-creator.js";
|
|
2
|
-
import { type IdentifierCreatorsRecord } from "./identifier-creators.js";
|
|
3
|
-
import { type IdentifierType } from "./identifier-type.js";
|
|
4
|
-
import type { NonNumericIdentifierCreator } from "./non-numeric-identifier-creator.js";
|
|
5
|
-
import type { NonSerializableNumericIdentifierCreator } from "./non-serializable-numeric-identifier-creator.js";
|
|
6
|
-
import type { PrefixProvider } from "./prefix-provider.js";
|
|
7
|
-
import { type PrefixType } from "./prefix-type.js";
|
|
8
|
-
import type { SerializableNumericIdentifierCreator } from "./serializable-numeric-identifier-creator.js";
|
|
9
|
-
/**
|
|
10
|
-
* Prefix manager. This is the core class for identifier creation.
|
|
11
|
-
*
|
|
12
|
-
* A prefix manager may be constructed for any {@link PrefixType | prefix type}. Construction may be done directly or
|
|
13
|
-
* via the static {@linkcode PrefixManager.get | get()} method, which allows for caching and reuse. As most applications
|
|
14
|
-
* work with a limited number of prefixes for creating identifiers, caching and reuse may be a more efficient option.
|
|
15
|
-
*
|
|
16
|
-
* The prefix type and prefix are normalized before the prefix manager is constructed, so they may not match the input
|
|
17
|
-
* values. For example, the GS1 Company Prefix 0614141 is equivalent to U.P.C. Company Prefix 614141; both result in a
|
|
18
|
-
* prefix manager with prefix type equal to {@linkcode PrefixTypes.UPCCompanyPrefix} and prefix equal to "614141".
|
|
19
|
-
*
|
|
20
|
-
* To support the creation of sparse identifiers, a prefix manager maintains a {@link tweakFactor | tweak factor} which
|
|
21
|
-
* is used, along with a type-specific multiplier, as the tweak when creating numeric identifiers. The default tweak
|
|
22
|
-
* factor is the numeric value of the GS1 Company Prefix representation of the prefix preceded by '1' to ensure
|
|
23
|
-
* uniqueness (i.e., so that prefixes 0 N1 N2 N3... and N1 N2 N3... produce different tweak factors). This is usually
|
|
24
|
-
* sufficient for obfuscation, but as the sparse creation algorithm is reversible and as the GS1 Company Prefix is
|
|
25
|
-
* discoverable via {@link https://www.gs1.org/services/verified-by-gs1 | Verified by GS1}, a user-defined tweak factor
|
|
26
|
-
* should be used if a higher degree of obfuscation is required. When using a tweak factor other than the default, care
|
|
27
|
-
* should be taken to restore it when resuming the application. A tweak factor of 0 creates a straight sequence.
|
|
28
|
-
*/
|
|
29
|
-
export declare class PrefixManager implements PrefixProvider {
|
|
30
|
-
#private;
|
|
31
|
-
/**
|
|
32
|
-
* Constructor.
|
|
33
|
-
*
|
|
34
|
-
* @param prefixType
|
|
35
|
-
* Prefix type.
|
|
36
|
-
*
|
|
37
|
-
* @param prefix
|
|
38
|
-
* Prefix.
|
|
39
|
-
*/
|
|
40
|
-
constructor(prefixType: PrefixType, prefix: string);
|
|
41
|
-
/**
|
|
42
|
-
* Get the prefix type.
|
|
43
|
-
*/
|
|
44
|
-
get prefixType(): PrefixType;
|
|
45
|
-
/**
|
|
46
|
-
* Get the prefix.
|
|
47
|
-
*/
|
|
48
|
-
get prefix(): string;
|
|
49
|
-
/**
|
|
50
|
-
* Get the GS1 Company Prefix.
|
|
51
|
-
*/
|
|
52
|
-
get gs1CompanyPrefix(): string;
|
|
53
|
-
/**
|
|
54
|
-
* Get the U.P.C. Company Prefix if prefix type is {@linkcode PrefixTypes.UPCCompanyPrefix} or undefined if not.
|
|
55
|
-
*/
|
|
56
|
-
get upcCompanyPrefix(): string | undefined;
|
|
57
|
-
/**
|
|
58
|
-
* Get the GS1-8 Prefix if prefix type is {@linkcode PrefixTypes.GS18Prefix} or undefined if not.
|
|
59
|
-
*/
|
|
60
|
-
get gs18Prefix(): string | undefined;
|
|
61
|
-
/**
|
|
62
|
-
* Get the tweak factor.
|
|
63
|
-
*/
|
|
64
|
-
get tweakFactor(): bigint;
|
|
65
|
-
/**
|
|
66
|
-
* Set the tweak factor.
|
|
67
|
-
*
|
|
68
|
-
* @param value
|
|
69
|
-
* Tweak factor.
|
|
70
|
-
*/
|
|
71
|
-
set tweakFactor(value: number | bigint);
|
|
72
|
-
/**
|
|
73
|
-
* Reset the tweak factor to its default (numeric value of the GS1 Company Prefix preceded by '1').
|
|
74
|
-
*/
|
|
75
|
-
resetTweakFactor(): void;
|
|
76
|
-
/**
|
|
77
|
-
* Get a prefix manager.
|
|
78
|
-
*
|
|
79
|
-
* @param prefixType
|
|
80
|
-
* Prefix type.
|
|
81
|
-
*
|
|
82
|
-
* @param prefix
|
|
83
|
-
* Prefix.
|
|
84
|
-
*
|
|
85
|
-
* @returns
|
|
86
|
-
* Prefix manager with normalized prefix type and prefix.
|
|
87
|
-
*/
|
|
88
|
-
static get(prefixType: PrefixType, prefix: string): PrefixManager;
|
|
89
|
-
/**
|
|
90
|
-
* Get an identifier creator.
|
|
91
|
-
*
|
|
92
|
-
* @template TIdentifierType
|
|
93
|
-
* Identifier type type.
|
|
94
|
-
*
|
|
95
|
-
* @param identifierType
|
|
96
|
-
* Identifier type for which to retrieve or construct identifier creator.
|
|
97
|
-
*
|
|
98
|
-
* @returns
|
|
99
|
-
* Identifier creator.
|
|
100
|
-
*/
|
|
101
|
-
getIdentifierCreator<TIdentifierType extends IdentifierType>(identifierType: TIdentifierType): IdentifierCreatorsRecord[TIdentifierType];
|
|
102
|
-
/**
|
|
103
|
-
* Get GTIN creator.
|
|
104
|
-
*/
|
|
105
|
-
get gtinCreator(): GTINCreator;
|
|
106
|
-
/**
|
|
107
|
-
* Get GLN creator.
|
|
108
|
-
*/
|
|
109
|
-
get glnCreator(): NonSerializableNumericIdentifierCreator;
|
|
110
|
-
/**
|
|
111
|
-
* Get SSCC creator.
|
|
112
|
-
*/
|
|
113
|
-
get ssccCreator(): NonSerializableNumericIdentifierCreator;
|
|
114
|
-
/**
|
|
115
|
-
* Get GRAI creator.
|
|
116
|
-
*/
|
|
117
|
-
get graiCreator(): SerializableNumericIdentifierCreator;
|
|
118
|
-
/**
|
|
119
|
-
* Get GIAI creator.
|
|
120
|
-
*/
|
|
121
|
-
get giaiCreator(): NonNumericIdentifierCreator;
|
|
122
|
-
/**
|
|
123
|
-
* Get GSRN creator.
|
|
124
|
-
*/
|
|
125
|
-
get gsrnCreator(): NonSerializableNumericIdentifierCreator;
|
|
126
|
-
/**
|
|
127
|
-
* Get GDTI creator.
|
|
128
|
-
*/
|
|
129
|
-
get gdtiCreator(): SerializableNumericIdentifierCreator;
|
|
130
|
-
/**
|
|
131
|
-
* Get GINC creator.
|
|
132
|
-
*/
|
|
133
|
-
get gincCreator(): NonNumericIdentifierCreator;
|
|
134
|
-
/**
|
|
135
|
-
* Get GSIN creator.
|
|
136
|
-
*/
|
|
137
|
-
get gsinCreator(): NonSerializableNumericIdentifierCreator;
|
|
138
|
-
/**
|
|
139
|
-
* Get GCN creator.
|
|
140
|
-
*/
|
|
141
|
-
get gcnCreator(): SerializableNumericIdentifierCreator;
|
|
142
|
-
/**
|
|
143
|
-
* Get CPID creator.
|
|
144
|
-
*/
|
|
145
|
-
get cpidCreator(): NonNumericIdentifierCreator;
|
|
146
|
-
/**
|
|
147
|
-
* Get GMN creator.
|
|
148
|
-
*/
|
|
149
|
-
get gmnCreator(): NonNumericIdentifierCreator;
|
|
150
|
-
}
|
|
151
|
-
//# sourceMappingURL=prefix-manager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prefix-manager.d.ts","sourceRoot":"","sources":["../src/prefix-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD,OAAO,EAEH,KAAK,wBAAwB,EAGhC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,cAAc,EAAmB,MAAM,sBAAsB,CAAC;AAE5E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AACvF,OAAO,KAAK,EAAE,uCAAuC,EAAE,MAAM,kDAAkD,CAAC;AAEhH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;A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H,IAAI,WAAW,IAAI,oCAAoC,CAEtD;IAED;;OAEG;IACH,IAAI,WAAW,IAAI,2BAA2B,CAE7C;IAED;;OAEG;IACH,IAAI,WAAW,IAAI,uCAAuC,CAEzD;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,oCAAoC,CAErD;IAED;;OAEG;IACH,IAAI,WAAW,IAAI,2BAA2B,CAE7C;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,2BAA2B,CAE5C;CACJ"}
|
package/dist/prefix-manager.js
DELETED
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
var _a;
|
|
2
|
-
import { GTIN_BASE_TYPES } from "./gtin-length.js";
|
|
3
|
-
import { IdentifierCreatorConstructors, isNumericIdentifierCreator } from "./identifier-creators.js";
|
|
4
|
-
import { IdentifierTypes } from "./identifier-type.js";
|
|
5
|
-
import { i18nextGS1 } from "./locale/i18n.js";
|
|
6
|
-
import { PrefixTypes } from "./prefix-type.js";
|
|
7
|
-
import { PrefixValidator } from "./prefix-validator.js";
|
|
8
|
-
/**
|
|
9
|
-
* Prefix manager. This is the core class for identifier creation.
|
|
10
|
-
*
|
|
11
|
-
* A prefix manager may be constructed for any {@link PrefixType | prefix type}. Construction may be done directly or
|
|
12
|
-
* via the static {@linkcode PrefixManager.get | get()} method, which allows for caching and reuse. As most applications
|
|
13
|
-
* work with a limited number of prefixes for creating identifiers, caching and reuse may be a more efficient option.
|
|
14
|
-
*
|
|
15
|
-
* The prefix type and prefix are normalized before the prefix manager is constructed, so they may not match the input
|
|
16
|
-
* values. For example, the GS1 Company Prefix 0614141 is equivalent to U.P.C. Company Prefix 614141; both result in a
|
|
17
|
-
* prefix manager with prefix type equal to {@linkcode PrefixTypes.UPCCompanyPrefix} and prefix equal to "614141".
|
|
18
|
-
*
|
|
19
|
-
* To support the creation of sparse identifiers, a prefix manager maintains a {@link tweakFactor | tweak factor} which
|
|
20
|
-
* is used, along with a type-specific multiplier, as the tweak when creating numeric identifiers. The default tweak
|
|
21
|
-
* factor is the numeric value of the GS1 Company Prefix representation of the prefix preceded by '1' to ensure
|
|
22
|
-
* uniqueness (i.e., so that prefixes 0 N1 N2 N3... and N1 N2 N3... produce different tweak factors). This is usually
|
|
23
|
-
* sufficient for obfuscation, but as the sparse creation algorithm is reversible and as the GS1 Company Prefix is
|
|
24
|
-
* discoverable via {@link https://www.gs1.org/services/verified-by-gs1 | Verified by GS1}, a user-defined tweak factor
|
|
25
|
-
* should be used if a higher degree of obfuscation is required. When using a tweak factor other than the default, care
|
|
26
|
-
* should be taken to restore it when resuming the application. A tweak factor of 0 creates a straight sequence.
|
|
27
|
-
*/
|
|
28
|
-
export class PrefixManager {
|
|
29
|
-
/**
|
|
30
|
-
* Cached prefix managers, keyed by GS1 Company Prefix.
|
|
31
|
-
*/
|
|
32
|
-
static #PREFIX_MANAGERS_MAP = new Map();
|
|
33
|
-
/**
|
|
34
|
-
* Creator tweak factors. Different numeric identifier types have different tweak factors so that sparse creation
|
|
35
|
-
* generates different sequences for each.
|
|
36
|
-
*/
|
|
37
|
-
static #CREATOR_TWEAK_FACTORS = {
|
|
38
|
-
GTIN: 1987n,
|
|
39
|
-
GLN: 4241n,
|
|
40
|
-
SSCC: 8087n,
|
|
41
|
-
GRAI: 3221n,
|
|
42
|
-
GSRN: 2341n,
|
|
43
|
-
GDTI: 7333n,
|
|
44
|
-
GSIN: 5623n,
|
|
45
|
-
GCN: 6869n
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Normalized prefix type.
|
|
49
|
-
*/
|
|
50
|
-
#prefixType;
|
|
51
|
-
/**
|
|
52
|
-
* Normalized prefix.
|
|
53
|
-
*/
|
|
54
|
-
#prefix;
|
|
55
|
-
/**
|
|
56
|
-
* Prefix as GS1 Company Prefix.
|
|
57
|
-
*/
|
|
58
|
-
#gs1CompanyPrefix;
|
|
59
|
-
/**
|
|
60
|
-
* U.P.C. Company Prefix if prefix type is {@linkcode PrefixTypes.UPCCompanyPrefix}.
|
|
61
|
-
*/
|
|
62
|
-
#upcCompanyPrefix;
|
|
63
|
-
/**
|
|
64
|
-
* GS1-8 Prefix if prefix type is {@linkcode PrefixTypes.GS18Prefix}.
|
|
65
|
-
*/
|
|
66
|
-
#gs18Prefix;
|
|
67
|
-
/**
|
|
68
|
-
* Default tweak factor.
|
|
69
|
-
*/
|
|
70
|
-
#defaultTweakFactor;
|
|
71
|
-
/**
|
|
72
|
-
* Tweak factor.
|
|
73
|
-
*/
|
|
74
|
-
#tweakFactor = 0n;
|
|
75
|
-
/**
|
|
76
|
-
* Cached identifier creators.
|
|
77
|
-
*/
|
|
78
|
-
#identifierCreators = {};
|
|
79
|
-
/**
|
|
80
|
-
* Constructor.
|
|
81
|
-
*
|
|
82
|
-
* @param prefixType
|
|
83
|
-
* Prefix type.
|
|
84
|
-
*
|
|
85
|
-
* @param prefix
|
|
86
|
-
* Prefix.
|
|
87
|
-
*/
|
|
88
|
-
constructor(prefixType, prefix) {
|
|
89
|
-
const normalizedPrefixProvider = PrefixValidator.normalize(prefixType, prefix);
|
|
90
|
-
this.#prefixType = normalizedPrefixProvider.prefixType;
|
|
91
|
-
this.#prefix = normalizedPrefixProvider.prefix;
|
|
92
|
-
this.#gs1CompanyPrefix = normalizedPrefixProvider.gs1CompanyPrefix;
|
|
93
|
-
this.#upcCompanyPrefix = normalizedPrefixProvider.upcCompanyPrefix;
|
|
94
|
-
this.#gs18Prefix = normalizedPrefixProvider.gs18Prefix;
|
|
95
|
-
// Default tweak factor is the numeric value of the GS1 Company Prefix preceded by '1'.
|
|
96
|
-
this.#defaultTweakFactor = BigInt(`1${this.gs1CompanyPrefix}`);
|
|
97
|
-
this.resetTweakFactor();
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Get the prefix type.
|
|
101
|
-
*/
|
|
102
|
-
get prefixType() {
|
|
103
|
-
return this.#prefixType;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Get the prefix.
|
|
107
|
-
*/
|
|
108
|
-
get prefix() {
|
|
109
|
-
return this.#prefix;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Get the GS1 Company Prefix.
|
|
113
|
-
*/
|
|
114
|
-
get gs1CompanyPrefix() {
|
|
115
|
-
return this.#gs1CompanyPrefix;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Get the U.P.C. Company Prefix if prefix type is {@linkcode PrefixTypes.UPCCompanyPrefix} or undefined if not.
|
|
119
|
-
*/
|
|
120
|
-
get upcCompanyPrefix() {
|
|
121
|
-
return this.#upcCompanyPrefix;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Get the GS1-8 Prefix if prefix type is {@linkcode PrefixTypes.GS18Prefix} or undefined if not.
|
|
125
|
-
*/
|
|
126
|
-
get gs18Prefix() {
|
|
127
|
-
return this.#gs18Prefix;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Set the tweak for an identifier creator if it's a numeric identifier creator.
|
|
131
|
-
*
|
|
132
|
-
* @param identifierCreator
|
|
133
|
-
* Identifier creator.
|
|
134
|
-
*/
|
|
135
|
-
#setCreatorTweak(identifierCreator) {
|
|
136
|
-
if (isNumericIdentifierCreator(identifierCreator)) {
|
|
137
|
-
// eslint-disable-next-line no-param-reassign -- Method purpose is to set the tweak.
|
|
138
|
-
identifierCreator.tweak = this.tweakFactor * _a.#CREATOR_TWEAK_FACTORS[identifierCreator.identifierType];
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Get the tweak factor.
|
|
143
|
-
*/
|
|
144
|
-
get tweakFactor() {
|
|
145
|
-
return this.#tweakFactor;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Set the tweak factor.
|
|
149
|
-
*
|
|
150
|
-
* @param value
|
|
151
|
-
* Tweak factor.
|
|
152
|
-
*/
|
|
153
|
-
set tweakFactor(value) {
|
|
154
|
-
const tweakFactor = BigInt(value);
|
|
155
|
-
if (this.#tweakFactor !== tweakFactor) {
|
|
156
|
-
this.#tweakFactor = tweakFactor;
|
|
157
|
-
for (const creator of Object.values(this.#identifierCreators)) {
|
|
158
|
-
this.#setCreatorTweak(creator);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Reset the tweak factor to its default (numeric value of the GS1 Company Prefix preceded by '1').
|
|
164
|
-
*/
|
|
165
|
-
resetTweakFactor() {
|
|
166
|
-
this.tweakFactor = this.#defaultTweakFactor;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Get a prefix manager.
|
|
170
|
-
*
|
|
171
|
-
* @param prefixType
|
|
172
|
-
* Prefix type.
|
|
173
|
-
*
|
|
174
|
-
* @param prefix
|
|
175
|
-
* Prefix.
|
|
176
|
-
*
|
|
177
|
-
* @returns
|
|
178
|
-
* Prefix manager with normalized prefix type and prefix.
|
|
179
|
-
*/
|
|
180
|
-
static get(prefixType, prefix) {
|
|
181
|
-
// Normalization will occur in constructor as well, but it's necessary here for the map.
|
|
182
|
-
const normalizedPrefixProvider = PrefixValidator.normalize(prefixType, prefix);
|
|
183
|
-
let prefixManager = _a.#PREFIX_MANAGERS_MAP.get(normalizedPrefixProvider.gs1CompanyPrefix);
|
|
184
|
-
if (prefixManager === undefined) {
|
|
185
|
-
prefixManager = new _a(normalizedPrefixProvider.prefixType, normalizedPrefixProvider.prefix);
|
|
186
|
-
_a.#PREFIX_MANAGERS_MAP.set(normalizedPrefixProvider.gs1CompanyPrefix, prefixManager);
|
|
187
|
-
}
|
|
188
|
-
return prefixManager;
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Get an identifier creator.
|
|
192
|
-
*
|
|
193
|
-
* @template TIdentifierType
|
|
194
|
-
* Identifier type type.
|
|
195
|
-
*
|
|
196
|
-
* @param identifierType
|
|
197
|
-
* Identifier type for which to retrieve or construct identifier creator.
|
|
198
|
-
*
|
|
199
|
-
* @returns
|
|
200
|
-
* Identifier creator.
|
|
201
|
-
*/
|
|
202
|
-
getIdentifierCreator(identifierType) {
|
|
203
|
-
let creator = this.#identifierCreators[identifierType];
|
|
204
|
-
if (creator === undefined) {
|
|
205
|
-
if (identifierType === IdentifierTypes.GTIN) {
|
|
206
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Types are known to match.
|
|
207
|
-
creator = new IdentifierCreatorConstructors.GTIN(this, GTIN_BASE_TYPES[this.prefixType]);
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
if (this.prefixType === PrefixTypes.GS18Prefix) {
|
|
211
|
-
throw new RangeError(i18nextGS1.t("Prefix.identifierTypeNotSupportedByGS18Prefix", {
|
|
212
|
-
identifierType
|
|
213
|
-
}));
|
|
214
|
-
}
|
|
215
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Types are known to match.
|
|
216
|
-
creator = new IdentifierCreatorConstructors[identifierType](this, identifierType);
|
|
217
|
-
}
|
|
218
|
-
this.#setCreatorTweak(creator);
|
|
219
|
-
this.#identifierCreators[identifierType] = creator;
|
|
220
|
-
}
|
|
221
|
-
return creator;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Get GTIN creator.
|
|
225
|
-
*/
|
|
226
|
-
get gtinCreator() {
|
|
227
|
-
return this.getIdentifierCreator(IdentifierTypes.GTIN);
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Get GLN creator.
|
|
231
|
-
*/
|
|
232
|
-
get glnCreator() {
|
|
233
|
-
return this.getIdentifierCreator(IdentifierTypes.GLN);
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Get SSCC creator.
|
|
237
|
-
*/
|
|
238
|
-
get ssccCreator() {
|
|
239
|
-
return this.getIdentifierCreator(IdentifierTypes.SSCC);
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Get GRAI creator.
|
|
243
|
-
*/
|
|
244
|
-
get graiCreator() {
|
|
245
|
-
return this.getIdentifierCreator(IdentifierTypes.GRAI);
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Get GIAI creator.
|
|
249
|
-
*/
|
|
250
|
-
get giaiCreator() {
|
|
251
|
-
return this.getIdentifierCreator(IdentifierTypes.GIAI);
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Get GSRN creator.
|
|
255
|
-
*/
|
|
256
|
-
get gsrnCreator() {
|
|
257
|
-
return this.getIdentifierCreator(IdentifierTypes.GSRN);
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Get GDTI creator.
|
|
261
|
-
*/
|
|
262
|
-
get gdtiCreator() {
|
|
263
|
-
return this.getIdentifierCreator(IdentifierTypes.GDTI);
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Get GINC creator.
|
|
267
|
-
*/
|
|
268
|
-
get gincCreator() {
|
|
269
|
-
return this.getIdentifierCreator(IdentifierTypes.GINC);
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Get GSIN creator.
|
|
273
|
-
*/
|
|
274
|
-
get gsinCreator() {
|
|
275
|
-
return this.getIdentifierCreator(IdentifierTypes.GSIN);
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Get GCN creator.
|
|
279
|
-
*/
|
|
280
|
-
get gcnCreator() {
|
|
281
|
-
return this.getIdentifierCreator(IdentifierTypes.GCN);
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Get CPID creator.
|
|
285
|
-
*/
|
|
286
|
-
get cpidCreator() {
|
|
287
|
-
return this.getIdentifierCreator(IdentifierTypes.CPID);
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Get GMN creator.
|
|
291
|
-
*/
|
|
292
|
-
get gmnCreator() {
|
|
293
|
-
return this.getIdentifierCreator(IdentifierTypes.GMN);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
_a = PrefixManager;
|
|
297
|
-
//# sourceMappingURL=prefix-manager.js.map
|
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;QACX,OAAO,IAAI,CAAC,oBAAoB,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAC3D,CAAC;IAED;;OAEG;IACH,IAAI,WAAW;QACX,OAAO,IAAI,CAAC,oBAAoB,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAC3D,CAAC;IAED;;OAEG;IACH,IAAI,WAAW;QACX,OAAO,IAAI,CAAC,oBAAoB,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAC3D,CAAC;IAED;;OAEG;IACH,IAAI,UAAU;QACV,OAAO,IAAI,CAAC,oBAAoB,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;IAC1D,CAAC;IAED;;OAEG;IACH,IAAI,WAAW;QACX,OAAO,IAAI,CAAC,oBAAoB,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAC3D,CAAC;IAED;;OAEG;IACH,IAAI,UAAU;QACV,OAAO,IAAI,CAAC,oBAAoB,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;IAC1D,CAAC"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { PrefixType } from "./prefix-type.js";
|
|
2
|
-
/**
|
|
3
|
-
* Prefix provider.
|
|
4
|
-
*/
|
|
5
|
-
export interface PrefixProvider {
|
|
6
|
-
/**
|
|
7
|
-
* Prefix type.
|
|
8
|
-
*/
|
|
9
|
-
readonly prefixType: PrefixType;
|
|
10
|
-
/**
|
|
11
|
-
* Prefix appropriate to the prefix type.
|
|
12
|
-
*/
|
|
13
|
-
readonly prefix: string;
|
|
14
|
-
/**
|
|
15
|
-
* Prefix as GS1 Company Prefix.
|
|
16
|
-
*/
|
|
17
|
-
readonly gs1CompanyPrefix: string;
|
|
18
|
-
/**
|
|
19
|
-
* Prefix as U.P.C. Company Prefix if prefix type is {@linkcode PrefixTypes.UPCCompanyPrefix} or undefined if not.
|
|
20
|
-
*/
|
|
21
|
-
readonly upcCompanyPrefix: string | undefined;
|
|
22
|
-
/**
|
|
23
|
-
* Prefix as GS1-8 Prefix if prefix type is {@linkcode PrefixTypes.GS18Prefix} or undefined if not.
|
|
24
|
-
*/
|
|
25
|
-
readonly gs18Prefix: string | undefined;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=prefix-provider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prefix-provider.d.ts","sourceRoot":"","sources":["../src/prefix-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAEhC;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAElC;;OAEG;IACH,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;IAE9C;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3C"}
|
package/dist/prefix-provider.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prefix-provider.js","sourceRoot":"","sources":["../src/prefix-provider.ts"],"names":[],"mappings":""}
|
package/dist/prefix-type.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Prefix types.
|
|
3
|
-
*/
|
|
4
|
-
export declare const PrefixTypes: {
|
|
5
|
-
/**
|
|
6
|
-
* GS1 Company Prefix.
|
|
7
|
-
*/
|
|
8
|
-
readonly GS1CompanyPrefix: "GS1 Company Prefix";
|
|
9
|
-
/**
|
|
10
|
-
* U.P.C. Company Prefix.
|
|
11
|
-
*/
|
|
12
|
-
readonly UPCCompanyPrefix: "U.P.C. Company Prefix";
|
|
13
|
-
/**
|
|
14
|
-
* GS1-8 Prefix.
|
|
15
|
-
*/
|
|
16
|
-
readonly GS18Prefix: "GS1-8 Prefix";
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Prefix type key.
|
|
20
|
-
*/
|
|
21
|
-
export type PrefixTypeKey = keyof typeof PrefixTypes;
|
|
22
|
-
/**
|
|
23
|
-
* Prefix type.
|
|
24
|
-
*/
|
|
25
|
-
export type PrefixType = typeof PrefixTypes[PrefixTypeKey];
|
|
26
|
-
//# sourceMappingURL=prefix-type.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prefix-type.d.ts","sourceRoot":"","sources":["../src/prefix-type.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,WAAW;IACpB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;CAEG,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,WAAW,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,WAAW,CAAC,aAAa,CAAC,CAAC"}
|