@aidc-toolkit/gs1 1.0.24-beta → 1.0.26-beta
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/abstract-identifier-creator.d.ts +75 -0
- package/dist/abstract-identifier-creator.d.ts.map +1 -0
- package/dist/abstract-identifier-creator.js +56 -0
- package/dist/abstract-identifier-creator.js.map +1 -0
- package/dist/abstract-identifier-validator.d.ts +95 -0
- package/dist/abstract-identifier-validator.d.ts.map +1 -0
- package/dist/abstract-identifier-validator.js +123 -0
- package/dist/abstract-identifier-validator.js.map +1 -0
- package/dist/abstract-numeric-identifier-creator.d.ts +92 -0
- package/dist/abstract-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/abstract-numeric-identifier-creator.js +137 -0
- package/dist/abstract-numeric-identifier-creator.js.map +1 -0
- package/dist/abstract-numeric-identifier-validator.d.ts +35 -0
- package/dist/abstract-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/abstract-numeric-identifier-validator.js +61 -0
- package/dist/abstract-numeric-identifier-validator.js.map +1 -0
- package/dist/character-set.d.ts +27 -0
- package/dist/character-set.d.ts.map +1 -0
- package/dist/character-set.js +50 -0
- package/dist/character-set.js.map +1 -0
- package/dist/check.d.ts +81 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +218 -0
- package/dist/check.js.map +1 -0
- package/dist/content-character-set.d.ts +26 -0
- package/dist/content-character-set.d.ts.map +1 -0
- package/dist/content-character-set.js +18 -0
- package/dist/content-character-set.js.map +1 -0
- package/dist/creators.d.ts +81 -0
- package/dist/creators.d.ts.map +1 -0
- package/dist/creators.js +62 -0
- package/dist/creators.js.map +1 -0
- package/dist/descriptors.d.ts +96 -0
- package/dist/descriptors.d.ts.map +1 -0
- package/dist/descriptors.js +266 -0
- package/dist/descriptors.js.map +1 -0
- package/dist/gtin-creator.d.ts +69 -0
- package/dist/gtin-creator.d.ts.map +1 -0
- package/dist/gtin-creator.js +159 -0
- package/dist/gtin-creator.js.map +1 -0
- package/dist/gtin-descriptor.d.ts +17 -0
- package/dist/gtin-descriptor.d.ts.map +1 -0
- package/dist/gtin-descriptor.js +2 -0
- package/dist/gtin-descriptor.js.map +1 -0
- package/dist/gtin-type.d.ts +39 -0
- package/dist/gtin-type.d.ts.map +1 -0
- package/dist/gtin-type.js +31 -0
- package/dist/gtin-type.js.map +1 -0
- package/dist/gtin-validator.d.ts +191 -0
- package/dist/gtin-validator.d.ts.map +1 -0
- package/dist/gtin-validator.js +450 -0
- package/dist/gtin-validator.js.map +1 -0
- package/dist/identifier-creator.d.ts +31 -0
- package/dist/identifier-creator.d.ts.map +1 -0
- package/dist/identifier-creator.js +2 -0
- package/dist/identifier-creator.js.map +1 -0
- package/dist/identifier-descriptor.d.ts +27 -0
- package/dist/identifier-descriptor.d.ts.map +1 -0
- package/dist/identifier-descriptor.js +2 -0
- package/dist/identifier-descriptor.js.map +1 -0
- package/dist/identifier-type.d.ts +62 -0
- package/dist/identifier-type.d.ts.map +1 -0
- package/dist/identifier-type.js +54 -0
- package/dist/identifier-type.js.map +1 -0
- package/dist/identifier-validator.d.ts +53 -0
- package/dist/identifier-validator.d.ts.map +1 -0
- package/dist/identifier-validator.js +2 -0
- package/dist/identifier-validator.js.map +1 -0
- package/dist/index.d.ts +52 -1588
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -4541
- package/dist/index.js.map +1 -1
- package/dist/locale/en/locale-resources.d.ts +42 -0
- package/dist/locale/en/locale-resources.d.ts.map +1 -0
- package/dist/locale/en/locale-resources.js +41 -0
- package/dist/locale/en/locale-resources.js.map +1 -0
- package/dist/locale/fr/locale-resources.d.ts +42 -0
- package/dist/locale/fr/locale-resources.d.ts.map +1 -0
- package/dist/locale/fr/locale-resources.js +41 -0
- package/dist/locale/fr/locale-resources.js.map +1 -0
- package/dist/locale/i18n.d.ts +27 -0
- package/dist/locale/i18n.d.ts.map +1 -0
- package/dist/locale/i18n.js +36 -0
- package/dist/locale/i18n.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-creator.d.ts +24 -0
- package/dist/non-gtin-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-creator.js +23 -0
- package/dist/non-gtin-numeric-identifier-creator.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-descriptor.d.ts +22 -0
- package/dist/non-gtin-numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-descriptor.js +2 -0
- package/dist/non-gtin-numeric-identifier-descriptor.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-type.d.ts +7 -0
- package/dist/non-gtin-numeric-identifier-type.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-type.js +2 -0
- package/dist/non-gtin-numeric-identifier-type.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-validator.d.ts +17 -0
- package/dist/non-gtin-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-validator.js +17 -0
- package/dist/non-gtin-numeric-identifier-validator.js.map +1 -0
- package/dist/non-numeric-identifier-creator.d.ts +45 -0
- package/dist/non-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/non-numeric-identifier-creator.js +84 -0
- package/dist/non-numeric-identifier-creator.js.map +1 -0
- package/dist/non-numeric-identifier-descriptor.d.ts +26 -0
- package/dist/non-numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/non-numeric-identifier-descriptor.js +2 -0
- package/dist/non-numeric-identifier-descriptor.js.map +1 -0
- package/dist/non-numeric-identifier-type.d.ts +7 -0
- package/dist/non-numeric-identifier-type.d.ts.map +1 -0
- package/dist/non-numeric-identifier-type.js +2 -0
- package/dist/non-numeric-identifier-type.js.map +1 -0
- package/dist/non-numeric-identifier-validator.d.ts +49 -0
- package/dist/non-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/non-numeric-identifier-validator.js +69 -0
- package/dist/non-numeric-identifier-validator.js.map +1 -0
- package/dist/numeric-identifier-creator.d.ts +53 -0
- package/dist/numeric-identifier-creator.d.ts.map +1 -0
- package/dist/numeric-identifier-creator.js +2 -0
- package/dist/numeric-identifier-creator.js.map +1 -0
- package/dist/numeric-identifier-descriptor.d.ts +21 -0
- package/dist/numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/numeric-identifier-descriptor.js +2 -0
- package/dist/numeric-identifier-descriptor.js.map +1 -0
- package/dist/numeric-identifier-type.d.ts +31 -0
- package/dist/numeric-identifier-type.d.ts.map +1 -0
- package/dist/numeric-identifier-type.js +18 -0
- package/dist/numeric-identifier-type.js.map +1 -0
- package/dist/numeric-identifier-validator.d.ts +24 -0
- package/dist/numeric-identifier-validator.d.ts.map +1 -0
- package/dist/numeric-identifier-validator.js +2 -0
- package/dist/numeric-identifier-validator.js.map +1 -0
- package/dist/prefix-manager.d.ts +232 -0
- package/dist/prefix-manager.d.ts.map +1 -0
- package/dist/prefix-manager.js +334 -0
- package/dist/prefix-manager.js.map +1 -0
- package/dist/prefix-provider.d.ts +27 -0
- package/dist/prefix-provider.d.ts.map +1 -0
- package/dist/prefix-provider.js +2 -0
- package/dist/prefix-provider.js.map +1 -0
- package/dist/prefix-type.d.ts +26 -0
- package/dist/prefix-type.d.ts.map +1 -0
- package/dist/prefix-type.js +18 -0
- package/dist/prefix-type.js.map +1 -0
- package/dist/prefix-validator.d.ts +70 -0
- package/dist/prefix-validator.d.ts.map +1 -0
- package/dist/prefix-validator.js +208 -0
- package/dist/prefix-validator.js.map +1 -0
- package/dist/serializable-numeric-identifier-creator.d.ts +76 -0
- package/dist/serializable-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-creator.js +107 -0
- package/dist/serializable-numeric-identifier-creator.js.map +1 -0
- package/dist/serializable-numeric-identifier-descriptor.d.ts +26 -0
- package/dist/serializable-numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-descriptor.js +2 -0
- package/dist/serializable-numeric-identifier-descriptor.js.map +1 -0
- package/dist/serializable-numeric-identifier-type.d.ts +6 -0
- package/dist/serializable-numeric-identifier-type.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-type.js +2 -0
- package/dist/serializable-numeric-identifier-type.js.map +1 -0
- package/dist/serializable-numeric-identifier-validator.d.ts +56 -0
- package/dist/serializable-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-validator.js +77 -0
- package/dist/serializable-numeric-identifier-validator.js.map +1 -0
- package/dist/validators.d.ts +96 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +140 -0
- package/dist/validators.js.map +1 -0
- package/package.json +12 -8
- package/src/abstract-identifier-creator.ts +97 -0
- package/src/abstract-identifier-validator.ts +140 -0
- package/src/abstract-numeric-identifier-creator.ts +168 -0
- package/src/abstract-numeric-identifier-validator.ts +69 -0
- package/src/character-set.ts +10 -10
- package/src/check.ts +9 -9
- package/src/content-character-set.ts +29 -0
- package/src/creators.ts +113 -0
- package/src/descriptors.ts +332 -0
- package/src/gtin-creator.ts +10 -9
- package/src/gtin-descriptor.ts +18 -0
- package/src/gtin-type.ts +50 -0
- package/src/gtin-validator.ts +40 -64
- package/src/identifier-creator.ts +12 -76
- package/src/identifier-descriptor.ts +30 -0
- package/src/identifier-type.ts +6 -1
- package/src/identifier-validator.ts +12 -188
- package/src/index.ts +44 -19
- package/src/locale/en/locale-resources.ts +0 -1
- package/src/locale/fr/locale-resources.ts +0 -1
- package/src/locale/i18n.ts +3 -3
- package/src/locale/i18next.d.ts +1 -1
- package/src/non-gtin-numeric-identifier-creator.ts +7 -13
- package/src/non-gtin-numeric-identifier-descriptor.ts +24 -0
- package/src/non-gtin-numeric-identifier-type.ts +7 -0
- package/src/non-gtin-numeric-identifier-validator.ts +8 -42
- package/src/non-numeric-identifier-creator.ts +9 -19
- package/src/non-numeric-identifier-descriptor.ts +29 -0
- package/src/non-numeric-identifier-type.ts +7 -0
- package/src/non-numeric-identifier-validator.ts +17 -55
- package/src/numeric-identifier-creator.ts +20 -163
- package/src/numeric-identifier-descriptor.ts +23 -0
- package/src/numeric-identifier-type.ts +44 -0
- package/src/numeric-identifier-validator.ts +13 -116
- package/src/prefix-manager.ts +94 -152
- package/src/prefix-provider.ts +3 -3
- package/src/prefix-type.ts +6 -1
- package/src/prefix-validator.ts +143 -81
- package/src/serializable-numeric-identifier-creator.ts +6 -16
- package/src/serializable-numeric-identifier-descriptor.ts +29 -0
- package/src/serializable-numeric-identifier-type.ts +9 -0
- package/src/serializable-numeric-identifier-validator.ts +18 -46
- package/src/validators.ts +203 -0
- package/test/check.test.ts +1 -1
- package/test/creator.test.ts +5 -7
- package/test/gtin-creator.ts +6 -2
- package/test/gtin-validator.test.ts +7 -10
- package/test/identifier-creator.ts +6 -5
- package/test/identifier-validator.ts +2 -2
- package/test/non-gtin-numeric-identifier-creator.ts +9 -93
- package/test/non-gtin-numeric-identifier-validator.ts +3 -3
- package/test/non-numeric-identifier-creator.ts +93 -0
- package/test/non-numeric-identifier-validator.ts +3 -3
- package/test/numeric-identifier-creator.ts +11 -5
- package/test/numeric-identifier-validator.ts +5 -9
- package/test/prefix-manager.test.ts +2 -2
- package/test/serializable-numeric-identifier-creator.ts +11 -3
- package/test/serializable-numeric-identifier-validator.ts +3 -3
- package/test/setup.ts +1 -1
- package/test/sparse.test.ts +1 -1
- package/test/utility.ts +1 -1
- package/test/validator.test.ts +64 -40
- package/test/variable-measure-rcn.test.ts +1 -1
- package/tsconfig-config.json +4 -0
- package/tsconfig-src.json +8 -0
- package/tsconfig-test.json +9 -0
- package/tsconfig.json +12 -1
- package/tsup.config.ts +3 -2
- package/dist/index.cjs +0 -4624
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -1588
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import { NUMERIC_CREATOR } from "@aidc-toolkit/utility";
|
|
2
|
+
import { AbstractNumericIdentifierValidator } from "./abstract-numeric-identifier-validator.js";
|
|
3
|
+
import { checkDigit, hasValidCheckDigit, isValidPriceOrWeightCheckDigit } from "./check.js";
|
|
4
|
+
import { IdentifierDescriptors } from "./descriptors.js";
|
|
5
|
+
import { GTINTypes } from "./gtin-type.js";
|
|
6
|
+
import { i18nextGS1 } from "./locale/i18n.js";
|
|
7
|
+
import { PrefixTypes } from "./prefix-type.js";
|
|
8
|
+
import { PrefixValidator } from "./prefix-validator.js";
|
|
9
|
+
/**
|
|
10
|
+
* Levels at which GTIN is to be validated.
|
|
11
|
+
*/
|
|
12
|
+
export const GTINLevels = {
|
|
13
|
+
/**
|
|
14
|
+
* Any level (level is ignored).
|
|
15
|
+
*/
|
|
16
|
+
Any: 0,
|
|
17
|
+
/**
|
|
18
|
+
* Retail consumer trade item level, supporting GTIN-13, GTIN-12 (optionally zero-suppressed), and GTIN-8.
|
|
19
|
+
*/
|
|
20
|
+
RetailConsumer: 1,
|
|
21
|
+
/**
|
|
22
|
+
* Other than retail consumer trade item level, supporting GTIN-13, GTIN-12 (not zero-suppressed), and GTIN-14.
|
|
23
|
+
*/
|
|
24
|
+
OtherThanRetailConsumer: 2
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* GTIN validator.
|
|
28
|
+
*/
|
|
29
|
+
export class GTINValidator extends AbstractNumericIdentifierValidator {
|
|
30
|
+
/**
|
|
31
|
+
* Validation parameters for optional indicator digit.
|
|
32
|
+
*/
|
|
33
|
+
static OPTIONAL_INDICATOR_DIGIT_VALIDATION = {
|
|
34
|
+
minimumLength: 0,
|
|
35
|
+
maximumLength: 1,
|
|
36
|
+
component: () => i18nextGS1.t("Identifier.indicatorDigit")
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Validation parameters for zero-suppressed GTIN-12.
|
|
40
|
+
*/
|
|
41
|
+
static ZERO_SUPPRESSED_GTIN12_VALIDATION = {
|
|
42
|
+
minimumLength: 8,
|
|
43
|
+
maximumLength: 8
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Prefix type.
|
|
47
|
+
*/
|
|
48
|
+
_prefixType;
|
|
49
|
+
/**
|
|
50
|
+
* Constructor.
|
|
51
|
+
*
|
|
52
|
+
* @param gtinBaseType
|
|
53
|
+
* GTIN base type (all except GTIN-14).
|
|
54
|
+
*/
|
|
55
|
+
constructor(gtinBaseType) {
|
|
56
|
+
const identifierDescriptor = IdentifierDescriptors.GTIN[gtinBaseType];
|
|
57
|
+
super(identifierDescriptor);
|
|
58
|
+
this._prefixType = identifierDescriptor.prefixType;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @inheritDoc
|
|
62
|
+
*/
|
|
63
|
+
get prefixType() {
|
|
64
|
+
return this._prefixType;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* @inheritDoc
|
|
68
|
+
*/
|
|
69
|
+
get gtinType() {
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Length maps to GTIN type.
|
|
71
|
+
return this.length;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* @inheritDoc
|
|
75
|
+
*/
|
|
76
|
+
validatePrefix(partialIdentifier, positionOffset) {
|
|
77
|
+
// Delegate to prefix validator requiring exact match for prefix type.
|
|
78
|
+
PrefixValidator.validate(this.prefixType, false, false, partialIdentifier, true, true, positionOffset);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Zero suppress a GTIN-12.
|
|
82
|
+
*
|
|
83
|
+
* @param gtin12
|
|
84
|
+
* GTIN-12.
|
|
85
|
+
*
|
|
86
|
+
* @returns
|
|
87
|
+
* Zero-suppressed GTIN-12.
|
|
88
|
+
*/
|
|
89
|
+
static zeroSuppress(gtin12) {
|
|
90
|
+
GTIN12_VALIDATOR.validate(gtin12);
|
|
91
|
+
// Convert to individual digits.
|
|
92
|
+
const d = Array.from(gtin12);
|
|
93
|
+
let zeroSuppressedGTIN12;
|
|
94
|
+
// All rules require that digits in positions 1, 5, and 6 be zero.
|
|
95
|
+
if (d[0] === "0" && d[6] === "0" && d[7] === "0") {
|
|
96
|
+
if (d[10] >= "5" && d[8] === "0" && d[9] === "0" && d[5] !== "0") {
|
|
97
|
+
zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[3]}${d[4]}${d[5]}${d[10]}${d[11]}`;
|
|
98
|
+
}
|
|
99
|
+
else if (d[5] === "0" && d[8] === "0" && d[9] === "0" && d[4] !== "0") {
|
|
100
|
+
zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[3]}${d[4]}${d[10]}4${d[11]}`;
|
|
101
|
+
}
|
|
102
|
+
else if (d[3] <= "2" && d[4] === "0" && d[5] === "0") {
|
|
103
|
+
zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[8]}${d[9]}${d[10]}${d[3]}${d[11]}`;
|
|
104
|
+
}
|
|
105
|
+
else if (d[3] >= "3" && d[4] === "0" && d[5] === "0" && d[8] === "0") {
|
|
106
|
+
zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[3]}${d[9]}${d[10]}3${d[11]}`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (zeroSuppressedGTIN12 === undefined) {
|
|
110
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidZeroSuppressibleGTIN12"));
|
|
111
|
+
}
|
|
112
|
+
return zeroSuppressedGTIN12;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Zero expand a zero-suppressed GTIN-12.
|
|
116
|
+
*
|
|
117
|
+
* @param zeroSuppressedGTIN12
|
|
118
|
+
* Zero-suppressed GTIN-12.
|
|
119
|
+
*
|
|
120
|
+
* @returns
|
|
121
|
+
* GTIN-12.
|
|
122
|
+
*/
|
|
123
|
+
static zeroExpand(zeroSuppressedGTIN12) {
|
|
124
|
+
NUMERIC_CREATOR.validate(zeroSuppressedGTIN12, GTINValidator.ZERO_SUPPRESSED_GTIN12_VALIDATION);
|
|
125
|
+
// Convert to individual digits.
|
|
126
|
+
const d = Array.from(zeroSuppressedGTIN12);
|
|
127
|
+
let gtin12;
|
|
128
|
+
// Zero-suppressed GTIN-12 always starts with 0.
|
|
129
|
+
if (d[0] === "0") {
|
|
130
|
+
if (d[6] >= "5" && d[5] !== "0") {
|
|
131
|
+
gtin12 = `0${d[1]}${d[2]}${d[3]}${d[4]}${d[5]}0000${d[6]}${d[7]}`;
|
|
132
|
+
}
|
|
133
|
+
else if (d[6] === "4" && d[4] !== "0") {
|
|
134
|
+
gtin12 = `0${d[1]}${d[2]}${d[3]}${d[4]}00000${d[5]}${d[7]}`;
|
|
135
|
+
}
|
|
136
|
+
else if (d[6] <= "2") {
|
|
137
|
+
gtin12 = `0${d[1]}${d[2]}${d[6]}0000${d[3]}${d[4]}${d[5]}${d[7]}`;
|
|
138
|
+
}
|
|
139
|
+
else if (d[6] === "3" && d[3] >= "3") {
|
|
140
|
+
gtin12 = `0${d[1]}${d[2]}${d[3]}00000${d[4]}${d[5]}${d[7]}`;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (gtin12 === undefined) {
|
|
144
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidZeroSuppressedGTIN12"));
|
|
145
|
+
}
|
|
146
|
+
// Make sure that resulting GTIN-12 is valid.
|
|
147
|
+
GTIN12_VALIDATOR.validate(gtin12);
|
|
148
|
+
return gtin12;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Convert a GTIN of any length to a GTIN-14 with an optional indicator digit.
|
|
152
|
+
*
|
|
153
|
+
* @param indicatorDigit
|
|
154
|
+
* Indicator digit. If blank, assumes "0" if the GTIN is not already a GTIN-14.
|
|
155
|
+
*
|
|
156
|
+
* @param gtin
|
|
157
|
+
* GTIN.
|
|
158
|
+
*
|
|
159
|
+
* @returns
|
|
160
|
+
* GTIN-14.
|
|
161
|
+
*/
|
|
162
|
+
static convertToGTIN14(indicatorDigit, gtin) {
|
|
163
|
+
GTINValidator.validateAny(gtin);
|
|
164
|
+
NUMERIC_CREATOR.validate(indicatorDigit, GTINValidator.OPTIONAL_INDICATOR_DIGIT_VALIDATION);
|
|
165
|
+
// Check digit doesn't change by prepending zeros.
|
|
166
|
+
let gtin14 = gtin.padStart(GTINTypes.GTIN14, "0");
|
|
167
|
+
// If indicator digit provided and is different, recalculate the check digit.
|
|
168
|
+
if (indicatorDigit.length !== 0 && indicatorDigit !== gtin14.charAt(0)) {
|
|
169
|
+
const partialGTIN14 = indicatorDigit + gtin14.substring(1, GTINTypes.GTIN14 - 1);
|
|
170
|
+
gtin14 = partialGTIN14 + checkDigit(partialGTIN14);
|
|
171
|
+
}
|
|
172
|
+
return gtin14;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Normalize a GTIN of any length.
|
|
176
|
+
* - A GTIN-14 that starts with six zeros or a GTIN-13 that starts with five zeros is normalized to GTIN-8.
|
|
177
|
+
* - A GTIN-14 that starts with two zeros or a GTIN-13 that starts with one zero is normalized to GTIN-12.
|
|
178
|
+
* - A GTIN-14 that starts with one zero is normalized to GTIN-13.
|
|
179
|
+
* - Otherwise, the GTIN is unchanged.
|
|
180
|
+
*
|
|
181
|
+
* @param gtin
|
|
182
|
+
* GTIN.
|
|
183
|
+
*
|
|
184
|
+
* @returns
|
|
185
|
+
* Normalized GTIN.
|
|
186
|
+
*/
|
|
187
|
+
static normalize(gtin) {
|
|
188
|
+
const gtinLength = gtin.length;
|
|
189
|
+
let normalizedGTIN;
|
|
190
|
+
switch (gtinLength) {
|
|
191
|
+
case GTINTypes.GTIN13:
|
|
192
|
+
if (!gtin.startsWith("0")) {
|
|
193
|
+
// GTIN is GTIN-13.
|
|
194
|
+
normalizedGTIN = gtin;
|
|
195
|
+
}
|
|
196
|
+
else if (!gtin.startsWith("00000")) {
|
|
197
|
+
// GTIN is GTIN-12.
|
|
198
|
+
normalizedGTIN = gtin.substring(1);
|
|
199
|
+
}
|
|
200
|
+
else if (!gtin.startsWith("000000")) {
|
|
201
|
+
// GTIN is GTIN-8.
|
|
202
|
+
normalizedGTIN = gtin.substring(5);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidZeroSuppressedGTIN12AsGTIN13"));
|
|
206
|
+
}
|
|
207
|
+
break;
|
|
208
|
+
case GTINTypes.GTIN12:
|
|
209
|
+
// GTIN is GTIN-12.
|
|
210
|
+
normalizedGTIN = gtin;
|
|
211
|
+
break;
|
|
212
|
+
case GTINTypes.GTIN8:
|
|
213
|
+
if (!gtin.startsWith("0")) {
|
|
214
|
+
// GTIN is GTIN-8.
|
|
215
|
+
normalizedGTIN = gtin;
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
// GTIN is zero-suppressed GTIN-12.
|
|
219
|
+
normalizedGTIN = GTINValidator.zeroExpand(gtin);
|
|
220
|
+
}
|
|
221
|
+
break;
|
|
222
|
+
case GTINTypes.GTIN14:
|
|
223
|
+
if (!gtin.startsWith("0")) {
|
|
224
|
+
// GTIN is GTIN-14.
|
|
225
|
+
normalizedGTIN = gtin;
|
|
226
|
+
}
|
|
227
|
+
else if (!gtin.startsWith("00")) {
|
|
228
|
+
// GTIN is GTIN-13.
|
|
229
|
+
normalizedGTIN = gtin.substring(1);
|
|
230
|
+
}
|
|
231
|
+
else if (!gtin.startsWith("000000")) {
|
|
232
|
+
// GTIN is GTIN-12.
|
|
233
|
+
normalizedGTIN = gtin.substring(2);
|
|
234
|
+
}
|
|
235
|
+
else if (!gtin.startsWith("0000000")) {
|
|
236
|
+
// GTIN is GTIN-8.
|
|
237
|
+
normalizedGTIN = gtin.substring(6);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidZeroSuppressedGTIN12AsGTIN14"));
|
|
241
|
+
}
|
|
242
|
+
break;
|
|
243
|
+
default:
|
|
244
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidGTINLength"));
|
|
245
|
+
}
|
|
246
|
+
// Validation applies to the normalized GTIN.
|
|
247
|
+
GTINValidator.validateAny(normalizedGTIN);
|
|
248
|
+
return normalizedGTIN;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Validate any GTIN, optionally against a level.
|
|
252
|
+
*
|
|
253
|
+
* @param gtin
|
|
254
|
+
* GTIN.
|
|
255
|
+
*
|
|
256
|
+
* @param gtinLevel
|
|
257
|
+
* Level at which GTIN is to be validated.
|
|
258
|
+
*/
|
|
259
|
+
static validateAny(gtin, gtinLevel = GTINLevels.Any) {
|
|
260
|
+
// Assume length-validated GTIN is the GTIN (true for all except zero-suppressed GTIN-12).
|
|
261
|
+
let lengthValidatedGTIN = gtin;
|
|
262
|
+
let gtinLevelRestriction;
|
|
263
|
+
switch (gtin.length) {
|
|
264
|
+
case GTINTypes.GTIN13:
|
|
265
|
+
if (gtin.startsWith("0")) {
|
|
266
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidGTIN13AtRetail"));
|
|
267
|
+
}
|
|
268
|
+
// Validate prefix requiring exact match for prefix type.
|
|
269
|
+
PrefixValidator.validate(PrefixTypes.GS1CompanyPrefix, false, false, gtin, true, true);
|
|
270
|
+
gtinLevelRestriction = GTINLevels.Any;
|
|
271
|
+
break;
|
|
272
|
+
case GTINTypes.GTIN12:
|
|
273
|
+
// Validate prefix requiring exact match for prefix type.
|
|
274
|
+
PrefixValidator.validate(PrefixTypes.UPCCompanyPrefix, false, false, gtin, true, true);
|
|
275
|
+
gtinLevelRestriction = GTINLevels.Any;
|
|
276
|
+
break;
|
|
277
|
+
case GTINTypes.GTIN8:
|
|
278
|
+
// Zero-suppressed GTIN-12 always starts with 0.
|
|
279
|
+
if (!gtin.startsWith("0")) {
|
|
280
|
+
// Validate prefix requiring exact match for prefix type.
|
|
281
|
+
PrefixValidator.validate(PrefixTypes.GS18Prefix, false, false, gtin, true, true);
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
lengthValidatedGTIN = GTINValidator.zeroExpand(gtin);
|
|
285
|
+
}
|
|
286
|
+
gtinLevelRestriction = GTINLevels.RetailConsumer;
|
|
287
|
+
break;
|
|
288
|
+
case GTINTypes.GTIN14:
|
|
289
|
+
// Validate prefix supporting any prefix type.
|
|
290
|
+
PrefixValidator.validate(PrefixTypes.GS1CompanyPrefix, true, true, gtin.substring(1), true, true);
|
|
291
|
+
gtinLevelRestriction = GTINLevels.OtherThanRetailConsumer;
|
|
292
|
+
break;
|
|
293
|
+
default:
|
|
294
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidGTINLength"));
|
|
295
|
+
}
|
|
296
|
+
// Validating the check digit will also validate the characters.
|
|
297
|
+
if (!hasValidCheckDigit(lengthValidatedGTIN)) {
|
|
298
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidCheckDigit"));
|
|
299
|
+
}
|
|
300
|
+
// Validate against level if required.
|
|
301
|
+
if (gtinLevel !== GTINLevels.Any && gtinLevelRestriction !== GTINLevels.Any && gtinLevelRestriction !== gtinLevel) {
|
|
302
|
+
throw new RangeError(i18nextGS1.t(gtinLevel === GTINLevels.RetailConsumer ? "Identifier.invalidGTINAtRetail" : "Identifier.invalidGTINAtOtherThanRetail"));
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Validate a GTIN-14.
|
|
307
|
+
*
|
|
308
|
+
* @param gtin14
|
|
309
|
+
* GTIN-14.
|
|
310
|
+
*/
|
|
311
|
+
static validateGTIN14(gtin14) {
|
|
312
|
+
if (gtin14.length !== GTINTypes.GTIN14) {
|
|
313
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidGTIN14Length"));
|
|
314
|
+
}
|
|
315
|
+
GTINValidator.validateAny(gtin14);
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Parse a Restricted Circulation Number (RCN) using a variable measure trade item format. The format is a 12- or
|
|
319
|
+
* 13-character string (for RCN-12 or RCN-13 respectively), containing the following:
|
|
320
|
+
*
|
|
321
|
+
* - '2' - The first character of the RCN.
|
|
322
|
+
* - '0'-'9' - The second character of the RCN (RCN-13 only).
|
|
323
|
+
* - 'I' - One or more, in sequence, for the item reference.
|
|
324
|
+
* - 'P' - One or more, in sequence, for the price or weight.
|
|
325
|
+
* - 'V' - Zero or one, for the price or weight check digit.
|
|
326
|
+
* - 'C' - The check digit of the entire RCN.
|
|
327
|
+
*
|
|
328
|
+
* The 'I', 'P', and 'V' formats may be in any order.
|
|
329
|
+
*
|
|
330
|
+
* Some examples:
|
|
331
|
+
*
|
|
332
|
+
* - 2IIIIIVPPPPC - RCN-12 with a five-digit item reference, a price or weight check digit, and a four-digit price
|
|
333
|
+
* or weight.
|
|
334
|
+
* - 23IIIIVPPPPPC - RCN-13 with a four-digit item reference, a price or weight check digit, and a five-digit price
|
|
335
|
+
* or weight.
|
|
336
|
+
* - 2IIIIIIPPPPC - RCN-12 with a six-digit item reference and a four-digit price or eight.
|
|
337
|
+
* - 29IIIIIPPPPPC - RCN-13 with a five-digit item reference and a five-digit price or weight.
|
|
338
|
+
*
|
|
339
|
+
* @param format
|
|
340
|
+
* Format.
|
|
341
|
+
*
|
|
342
|
+
* @param rcn
|
|
343
|
+
* RCN.
|
|
344
|
+
*
|
|
345
|
+
* @returns
|
|
346
|
+
* RCN reference.
|
|
347
|
+
*/
|
|
348
|
+
static parseVariableMeasureRCN(format, rcn) {
|
|
349
|
+
const formatLength = format.length;
|
|
350
|
+
if (rcn.length !== formatLength) {
|
|
351
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidRCNLength"));
|
|
352
|
+
}
|
|
353
|
+
let validFormat = formatLength === 12 || formatLength === 13;
|
|
354
|
+
let validRCNPrefix = true;
|
|
355
|
+
let buildingItemReference = false;
|
|
356
|
+
let itemReference = "";
|
|
357
|
+
let buildingPriceOrWeight = false;
|
|
358
|
+
let priceOrWeight = "";
|
|
359
|
+
let priceOrWeightCheckDigit = "";
|
|
360
|
+
for (let index = 0; validFormat && index < formatLength; index++) {
|
|
361
|
+
const formatChar = format.charAt(index);
|
|
362
|
+
const rcnChar = rcn.charAt(index);
|
|
363
|
+
if (index === 0) {
|
|
364
|
+
validFormat = formatChar === "2";
|
|
365
|
+
validRCNPrefix = rcnChar === "2";
|
|
366
|
+
}
|
|
367
|
+
else if (formatLength === 13 && index === 1) {
|
|
368
|
+
validFormat = NUMERIC_CREATOR.characterIndex(formatChar) !== undefined;
|
|
369
|
+
validRCNPrefix = rcnChar === formatChar;
|
|
370
|
+
}
|
|
371
|
+
else if (index === formatLength - 1) {
|
|
372
|
+
validFormat = formatChar === "C";
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
switch (formatChar) {
|
|
376
|
+
case "I":
|
|
377
|
+
if (!buildingItemReference) {
|
|
378
|
+
// Item reference can't appear more than once.
|
|
379
|
+
validFormat = itemReference === "";
|
|
380
|
+
buildingItemReference = true;
|
|
381
|
+
buildingPriceOrWeight = false;
|
|
382
|
+
}
|
|
383
|
+
itemReference += rcnChar;
|
|
384
|
+
break;
|
|
385
|
+
case "P":
|
|
386
|
+
if (!buildingPriceOrWeight) {
|
|
387
|
+
// Price or weight can't appear more than once.
|
|
388
|
+
validFormat = priceOrWeight === "";
|
|
389
|
+
buildingPriceOrWeight = true;
|
|
390
|
+
buildingItemReference = false;
|
|
391
|
+
}
|
|
392
|
+
priceOrWeight += rcnChar;
|
|
393
|
+
break;
|
|
394
|
+
case "V":
|
|
395
|
+
// Price or weight check digit can't appear more than once.
|
|
396
|
+
validFormat = priceOrWeightCheckDigit === "";
|
|
397
|
+
buildingItemReference = false;
|
|
398
|
+
buildingPriceOrWeight = false;
|
|
399
|
+
priceOrWeightCheckDigit = rcnChar;
|
|
400
|
+
break;
|
|
401
|
+
default:
|
|
402
|
+
validFormat = false;
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
validFormat &&= itemReference !== "" && priceOrWeight !== "";
|
|
408
|
+
if (!validFormat) {
|
|
409
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidVariableMeasureRCNFormat"));
|
|
410
|
+
}
|
|
411
|
+
if (!validRCNPrefix) {
|
|
412
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidVariableMeasureRCNPrefix"));
|
|
413
|
+
}
|
|
414
|
+
if (priceOrWeightCheckDigit !== "" && !isValidPriceOrWeightCheckDigit(priceOrWeight, priceOrWeightCheckDigit)) {
|
|
415
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidVariableMeasurePriceOrWeight"));
|
|
416
|
+
}
|
|
417
|
+
if (!hasValidCheckDigit(rcn)) {
|
|
418
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidCheckDigit"));
|
|
419
|
+
}
|
|
420
|
+
return {
|
|
421
|
+
itemReference: Number(itemReference),
|
|
422
|
+
priceOrWeight: Number(priceOrWeight)
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* GTIN-13 validator.
|
|
428
|
+
*/
|
|
429
|
+
// Defined here because of circular reference.
|
|
430
|
+
export const GTIN13_VALIDATOR = new GTINValidator(GTINTypes.GTIN13);
|
|
431
|
+
/**
|
|
432
|
+
* GTIN-12 validator.
|
|
433
|
+
*/
|
|
434
|
+
// Defined here because of circular reference.
|
|
435
|
+
export const GTIN12_VALIDATOR = new GTINValidator(GTINTypes.GTIN12);
|
|
436
|
+
/**
|
|
437
|
+
* GTIN-8 validator.
|
|
438
|
+
*/
|
|
439
|
+
// Defined here because of circular reference.
|
|
440
|
+
export const GTIN8_VALIDATOR = new GTINValidator(GTINTypes.GTIN8);
|
|
441
|
+
/**
|
|
442
|
+
* GTIN validators indexed by prefix type.
|
|
443
|
+
*/
|
|
444
|
+
// Defined here because of circular reference.
|
|
445
|
+
export const GTIN_VALIDATORS = {
|
|
446
|
+
[GTINTypes.GTIN13]: GTIN13_VALIDATOR,
|
|
447
|
+
[GTINTypes.GTIN12]: GTIN12_VALIDATOR,
|
|
448
|
+
[GTINTypes.GTIN8]: GTIN8_VALIDATOR
|
|
449
|
+
};
|
|
450
|
+
//# sourceMappingURL=gtin-validator.js.map
|
|
@@ -0,0 +1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,GAAG,CAAC,EAAE,CAAC;YAC3B,MAAM,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,8BAA8B,CAAC,CAAC,CAAC;QACvE,CAAC;QAED,OAAO;YACH,aAAa,EAAE,MAAM,CAAC,aAAa,CAAC;YACpC,aAAa,EAAE,MAAM,CAAC,aAAa,CAAC;SACvC,CAAC;IACN,CAAC;;AAGL;;GAEG;AACH,8CAA8C;AAC9C,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,aAAa,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAEpE;;GAEG;AACH,8CAA8C;AAC9C,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,aAAa,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAEpE;;GAEG;AACH,8CAA8C;AAC9C,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,aAAa,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAElE;;GAEG;AACH,8CAA8C;AAC9C,MAAM,CAAC,MAAM,eAAe,GAAkD;IAC1E,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,gBAAgB;IACpC,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,gBAAgB;IACpC,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,eAAe;CACrC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { IdentifierDescriptor } from "./identifier-descriptor.js";
|
|
2
|
+
import type { IdentifierValidation, IdentifierValidator } from "./identifier-validator.js";
|
|
3
|
+
import type { PrefixProvider } from "./prefix-provider.js";
|
|
4
|
+
/**
|
|
5
|
+
* Identifier creator. Creates an identifier based on its definition in section 3 of the {@link
|
|
6
|
+
* https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}.
|
|
7
|
+
*
|
|
8
|
+
* Keys are created based on a prefix defined in a prefix provider to which the identifier creator is bound.
|
|
9
|
+
*
|
|
10
|
+
* @template TIdentifierDescriptor
|
|
11
|
+
* Identifier descriptor type.
|
|
12
|
+
*
|
|
13
|
+
* @template TIdentifierValidation
|
|
14
|
+
* Identifier validation type.
|
|
15
|
+
*/
|
|
16
|
+
export interface IdentifierCreator<TIdentifierDescriptor extends IdentifierDescriptor = IdentifierDescriptor, TIdentifierValidation extends IdentifierValidation = IdentifierValidation> extends IdentifierValidator<TIdentifierDescriptor, TIdentifierValidation> {
|
|
17
|
+
/**
|
|
18
|
+
* Get the prefix provider to which this identifier creator is bound.
|
|
19
|
+
*/
|
|
20
|
+
get prefixProvider(): PrefixProvider;
|
|
21
|
+
/**
|
|
22
|
+
* Get the prefix, equivalent to calling {@linkcode PrefixProvider.prefix | prefixProvider.prefix} for a GTIN or
|
|
23
|
+
* {@linkcode PrefixProvider.gs1CompanyPrefix | prefixProvider.gs1CompanyPrefix} for all other identifier types.
|
|
24
|
+
*/
|
|
25
|
+
get prefix(): string;
|
|
26
|
+
/**
|
|
27
|
+
* Get the reference length.
|
|
28
|
+
*/
|
|
29
|
+
get referenceLength(): number;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=identifier-creator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifier-creator.d.ts","sourceRoot":"","sources":["../src/identifier-creator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAC3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,iBAAiB,CAAC,qBAAqB,SAAS,oBAAoB,GAAG,oBAAoB,EAAE,qBAAqB,SAAS,oBAAoB,GAAG,oBAAoB,CAAE,SAAQ,mBAAmB,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;IAC9P;;OAEG;IACH,IAAI,cAAc,IAAI,cAAc,CAAC;IAErC;;;OAGG;IACH,IAAI,MAAM,IAAI,MAAM,CAAC;IAErB;;OAEG;IACH,IAAI,eAAe,IAAI,MAAM,CAAC;CACjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifier-creator.js","sourceRoot":"","sources":["../src/identifier-creator.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ContentCharacterSet } from "./content-character-set.js";
|
|
2
|
+
import type { IdentifierType } from "./identifier-type.js";
|
|
3
|
+
import type { PrefixType } from "./prefix-type.js";
|
|
4
|
+
/**
|
|
5
|
+
* Identifier descriptor. Instantiations of this type are used to parameterize validators and creators.
|
|
6
|
+
*/
|
|
7
|
+
export interface IdentifierDescriptor {
|
|
8
|
+
/**
|
|
9
|
+
* Identifier type. Per the GS1 General Specifications, the identifier type determines the remaining properties.
|
|
10
|
+
*/
|
|
11
|
+
readonly identifierType: IdentifierType;
|
|
12
|
+
/**
|
|
13
|
+
* Prefix type supported by the identifier type. For all identifier types except the GTIN, this is a GS1 Company
|
|
14
|
+
* Prefix. For the GTIN, the prefix type determines the length.
|
|
15
|
+
*/
|
|
16
|
+
readonly prefixType: PrefixType;
|
|
17
|
+
/**
|
|
18
|
+
* Length. For numeric identifier types, the length is fixed; for non-numeric identifier types, the length is the
|
|
19
|
+
* maximum.
|
|
20
|
+
*/
|
|
21
|
+
readonly length: number;
|
|
22
|
+
/**
|
|
23
|
+
* Reference character set.
|
|
24
|
+
*/
|
|
25
|
+
readonly referenceCharacterSet: ContentCharacterSet;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=identifier-descriptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifier-descriptor.d.ts","sourceRoot":"","sources":["../src/identifier-descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC;;OAEG;IACH,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IAExC;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAEhC;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,qBAAqB,EAAE,mBAAmB,CAAC;CACvD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifier-descriptor.js","sourceRoot":"","sources":["../src/identifier-descriptor.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identifier types.
|
|
3
|
+
*/
|
|
4
|
+
export declare const IdentifierTypes: {
|
|
5
|
+
/**
|
|
6
|
+
* Global Trade Item Number.
|
|
7
|
+
*/
|
|
8
|
+
readonly GTIN: "GTIN";
|
|
9
|
+
/**
|
|
10
|
+
* Global Location Number.
|
|
11
|
+
*/
|
|
12
|
+
readonly GLN: "GLN";
|
|
13
|
+
/**
|
|
14
|
+
* Serial Shipping Container Code.
|
|
15
|
+
*/
|
|
16
|
+
readonly SSCC: "SSCC";
|
|
17
|
+
/**
|
|
18
|
+
* Global Returnable Asset Identifier.
|
|
19
|
+
*/
|
|
20
|
+
readonly GRAI: "GRAI";
|
|
21
|
+
/**
|
|
22
|
+
* Global Individual Asset Identifier.
|
|
23
|
+
*/
|
|
24
|
+
readonly GIAI: "GIAI";
|
|
25
|
+
/**
|
|
26
|
+
* Global Service Relation Number.
|
|
27
|
+
*/
|
|
28
|
+
readonly GSRN: "GSRN";
|
|
29
|
+
/**
|
|
30
|
+
* Global Document Type Identifier.
|
|
31
|
+
*/
|
|
32
|
+
readonly GDTI: "GDTI";
|
|
33
|
+
/**
|
|
34
|
+
* Global Identification Number for Consignment.
|
|
35
|
+
*/
|
|
36
|
+
readonly GINC: "GINC";
|
|
37
|
+
/**
|
|
38
|
+
* Global Shipment Identification Number.
|
|
39
|
+
*/
|
|
40
|
+
readonly GSIN: "GSIN";
|
|
41
|
+
/**
|
|
42
|
+
* Global Coupon Number.
|
|
43
|
+
*/
|
|
44
|
+
readonly GCN: "GCN";
|
|
45
|
+
/**
|
|
46
|
+
* Component/Part Identifier.
|
|
47
|
+
*/
|
|
48
|
+
readonly CPID: "CPID";
|
|
49
|
+
/**
|
|
50
|
+
* Global Model Number.
|
|
51
|
+
*/
|
|
52
|
+
readonly GMN: "GMN";
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Identifier type key.
|
|
56
|
+
*/
|
|
57
|
+
export type IdentifierTypeKey = keyof typeof IdentifierTypes;
|
|
58
|
+
/**
|
|
59
|
+
* Identifier type.
|
|
60
|
+
*/
|
|
61
|
+
export type IdentifierType = typeof IdentifierTypes[IdentifierTypeKey];
|
|
62
|
+
//# sourceMappingURL=identifier-type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifier-type.d.ts","sourceRoot":"","sources":["../src/identifier-type.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,eAAe;IACxB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;CAEG,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,eAAe,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,eAAe,CAAC,iBAAiB,CAAC,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identifier types.
|
|
3
|
+
*/
|
|
4
|
+
export const IdentifierTypes = {
|
|
5
|
+
/**
|
|
6
|
+
* Global Trade Item Number.
|
|
7
|
+
*/
|
|
8
|
+
GTIN: "GTIN",
|
|
9
|
+
/**
|
|
10
|
+
* Global Location Number.
|
|
11
|
+
*/
|
|
12
|
+
GLN: "GLN",
|
|
13
|
+
/**
|
|
14
|
+
* Serial Shipping Container Code.
|
|
15
|
+
*/
|
|
16
|
+
SSCC: "SSCC",
|
|
17
|
+
/**
|
|
18
|
+
* Global Returnable Asset Identifier.
|
|
19
|
+
*/
|
|
20
|
+
GRAI: "GRAI",
|
|
21
|
+
/**
|
|
22
|
+
* Global Individual Asset Identifier.
|
|
23
|
+
*/
|
|
24
|
+
GIAI: "GIAI",
|
|
25
|
+
/**
|
|
26
|
+
* Global Service Relation Number.
|
|
27
|
+
*/
|
|
28
|
+
GSRN: "GSRN",
|
|
29
|
+
/**
|
|
30
|
+
* Global Document Type Identifier.
|
|
31
|
+
*/
|
|
32
|
+
GDTI: "GDTI",
|
|
33
|
+
/**
|
|
34
|
+
* Global Identification Number for Consignment.
|
|
35
|
+
*/
|
|
36
|
+
GINC: "GINC",
|
|
37
|
+
/**
|
|
38
|
+
* Global Shipment Identification Number.
|
|
39
|
+
*/
|
|
40
|
+
GSIN: "GSIN",
|
|
41
|
+
/**
|
|
42
|
+
* Global Coupon Number.
|
|
43
|
+
*/
|
|
44
|
+
GCN: "GCN",
|
|
45
|
+
/**
|
|
46
|
+
* Component/Part Identifier.
|
|
47
|
+
*/
|
|
48
|
+
CPID: "CPID",
|
|
49
|
+
/**
|
|
50
|
+
* Global Model Number.
|
|
51
|
+
*/
|
|
52
|
+
GMN: "GMN"
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=identifier-type.js.map
|