@aidc-toolkit/gs1 0.9.20-beta → 1.0.22-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/character-set.d.ts +4 -4
- package/dist/character-set.d.ts.map +1 -1
- package/dist/character-set.js +7 -7
- package/dist/character-set.js.map +1 -1
- package/dist/gtin-creator.d.ts +68 -0
- package/dist/gtin-creator.d.ts.map +1 -0
- package/dist/gtin-creator.js +158 -0
- package/dist/gtin-creator.js.map +1 -0
- package/dist/gtin-validator.d.ts +202 -0
- package/dist/gtin-validator.d.ts.map +1 -0
- package/dist/gtin-validator.js +470 -0
- package/dist/gtin-validator.js.map +1 -0
- package/dist/identifier-creator.d.ts +72 -0
- package/dist/identifier-creator.d.ts.map +1 -0
- package/dist/identifier-creator.js +50 -0
- package/dist/identifier-creator.js.map +1 -0
- package/dist/identifier-type.d.ts +58 -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 +174 -0
- package/dist/identifier-validator.d.ts.map +1 -0
- package/dist/identifier-validator.js +145 -0
- package/dist/identifier-validator.js.map +1 -0
- package/dist/index.d.ts +16 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/dist/locale/en/locale-strings.d.ts +3 -3
- package/dist/locale/en/locale-strings.js +3 -3
- package/dist/locale/en/locale-strings.js.map +1 -1
- package/dist/locale/fr/locale-strings.d.ts +3 -3
- package/dist/locale/fr/locale-strings.js +3 -3
- package/dist/locale/fr/locale-strings.js.map +1 -1
- package/dist/non-gtin-numeric-identifier-creator.d.ts +30 -0
- package/dist/non-gtin-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-creator.js +30 -0
- package/dist/non-gtin-numeric-identifier-creator.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-validator.d.ts +41 -0
- package/dist/non-gtin-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-validator.js +40 -0
- package/dist/non-gtin-numeric-identifier-validator.js.map +1 -0
- package/dist/non-numeric-identifier-creator.d.ts +55 -0
- package/dist/non-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/non-numeric-identifier-creator.js +93 -0
- package/dist/non-numeric-identifier-creator.js.map +1 -0
- package/dist/non-numeric-identifier-validator.d.ts +78 -0
- package/dist/non-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/non-numeric-identifier-validator.js +95 -0
- package/dist/non-numeric-identifier-validator.js.map +1 -0
- package/dist/numeric-identifier-creator.d.ts +121 -0
- package/dist/numeric-identifier-creator.d.ts.map +1 -0
- package/dist/numeric-identifier-creator.js +135 -0
- package/dist/numeric-identifier-creator.js.map +1 -0
- package/dist/numeric-identifier-validator.d.ts +76 -0
- package/dist/numeric-identifier-validator.d.ts.map +1 -0
- package/dist/numeric-identifier-validator.js +84 -0
- package/dist/numeric-identifier-validator.js.map +1 -0
- package/dist/prefix-manager.d.ts +224 -0
- package/dist/prefix-manager.d.ts.map +1 -0
- package/dist/prefix-manager.js +369 -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 +22 -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 +58 -0
- package/dist/prefix-validator.d.ts.map +1 -0
- package/dist/prefix-validator.js +154 -0
- package/dist/prefix-validator.js.map +1 -0
- package/dist/serializable-numeric-identifier-creator.d.ts +86 -0
- package/dist/serializable-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-creator.js +116 -0
- package/dist/serializable-numeric-identifier-creator.js.map +1 -0
- package/dist/serializable-numeric-identifier-validator.d.ts +79 -0
- package/dist/serializable-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-validator.js +99 -0
- package/dist/serializable-numeric-identifier-validator.js.map +1 -0
- package/gs1.iml +4 -1
- package/package.json +2 -3
- package/src/character-set.ts +7 -7
- package/src/gtin-creator.ts +195 -0
- package/src/gtin-validator.ts +564 -0
- package/src/identifier-creator.ts +97 -0
- package/src/identifier-type.ts +69 -0
- package/src/identifier-validator.ts +235 -0
- package/src/index.ts +16 -1
- package/src/locale/en/locale-strings.ts +3 -3
- package/src/locale/fr/locale-strings.ts +3 -3
- package/src/non-gtin-numeric-identifier-creator.ts +33 -0
- package/src/non-gtin-numeric-identifier-validator.ts +54 -0
- package/src/non-numeric-identifier-creator.ts +111 -0
- package/src/non-numeric-identifier-validator.ts +128 -0
- package/src/numeric-identifier-creator.ts +200 -0
- package/src/numeric-identifier-validator.ts +128 -0
- package/src/prefix-manager.ts +446 -0
- package/src/prefix-provider.ts +31 -0
- package/src/prefix-type.ts +24 -0
- package/src/prefix-validator.ts +191 -0
- package/src/serializable-numeric-identifier-creator.ts +128 -0
- package/src/serializable-numeric-identifier-validator.ts +124 -0
- package/test/check.test.ts +0 -4
- package/test/creator.test.ts +30 -0
- package/test/gtin-creator.ts +239 -0
- package/test/gtin-validator.test.ts +149 -0
- package/test/identifier-creator.ts +84 -0
- package/test/identifier-validator.ts +8 -0
- package/test/non-gtin-numeric-identifier-creator.ts +98 -0
- package/test/non-gtin-numeric-identifier-validator.ts +6 -0
- package/test/non-numeric-identifier-validator.ts +24 -0
- package/test/numeric-identifier-creator.ts +132 -0
- package/test/numeric-identifier-validator.ts +23 -0
- package/test/prefix-manager.test.ts +112 -0
- package/test/serializable-numeric-identifier-creator.ts +56 -0
- package/test/serializable-numeric-identifier-validator.ts +24 -0
- package/test/setup.ts +4 -0
- package/test/sparse.test.ts +56 -0
- package/test/utility.ts +22 -0
- package/test/validator.test.ts +52 -0
- package/test/variable-measure-rcn.test.ts +201 -0
- package/vitest.config.ts +7 -0
- package/dist/idkey.d.ts +0 -1346
- package/dist/idkey.d.ts.map +0 -1
- package/dist/idkey.js +0 -2024
- package/dist/idkey.js.map +0 -1
- package/src/idkey.ts +0 -2532
- package/test/idkey.test.ts +0 -1247
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
import { NUMERIC_CREATOR } from "@aidc-toolkit/utility";
|
|
2
|
+
import { checkDigit, hasValidCheckDigit, isValidPriceOrWeightCheckDigit } from "./check.js";
|
|
3
|
+
import { IdentifierTypes } from "./identifier-type.js";
|
|
4
|
+
import { i18nextGS1 } from "./locale/i18n.js";
|
|
5
|
+
import { AbstractNumericIdentifierValidator, LeaderTypes } from "./numeric-identifier-validator.js";
|
|
6
|
+
import { PrefixTypes } from "./prefix-type.js";
|
|
7
|
+
import { PrefixValidator } from "./prefix-validator.js";
|
|
8
|
+
/**
|
|
9
|
+
* GTIN types. The numeric values are equal to the lengths of the GTIN types.
|
|
10
|
+
*/
|
|
11
|
+
export const GTINTypes = {
|
|
12
|
+
/**
|
|
13
|
+
* GTIN-13.
|
|
14
|
+
*/
|
|
15
|
+
GTIN13: 13,
|
|
16
|
+
/**
|
|
17
|
+
* GTIN-12.
|
|
18
|
+
*/
|
|
19
|
+
GTIN12: 12,
|
|
20
|
+
/**
|
|
21
|
+
* GTIN-8.
|
|
22
|
+
*/
|
|
23
|
+
GTIN8: 8,
|
|
24
|
+
/**
|
|
25
|
+
* GTIN-14.
|
|
26
|
+
*/
|
|
27
|
+
GTIN14: 14
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Levels at which GTIN is to be validated.
|
|
31
|
+
*/
|
|
32
|
+
export const GTINLevels = {
|
|
33
|
+
/**
|
|
34
|
+
* Any level (level is ignored).
|
|
35
|
+
*/
|
|
36
|
+
Any: 0,
|
|
37
|
+
/**
|
|
38
|
+
* Retail consumer trade item level, supporting GTIN-13, GTIN-12 (optionally zero-suppressed), and GTIN-8.
|
|
39
|
+
*/
|
|
40
|
+
RetailConsumer: 1,
|
|
41
|
+
/**
|
|
42
|
+
* Other than retail consumer trade item level, supporting GTIN-13, GTIN-12 (not zero-suppressed), and GTIN-14.
|
|
43
|
+
*/
|
|
44
|
+
OtherThanRetailConsumer: 2
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* GTIN validator.
|
|
48
|
+
*/
|
|
49
|
+
export class GTINValidator extends AbstractNumericIdentifierValidator {
|
|
50
|
+
/**
|
|
51
|
+
* Validation parameters for optional indicator digit.
|
|
52
|
+
*/
|
|
53
|
+
static OPTIONAL_INDICATOR_DIGIT_VALIDATION = {
|
|
54
|
+
minimumLength: 0,
|
|
55
|
+
maximumLength: 1,
|
|
56
|
+
component: () => i18nextGS1.t("Identifier.indicatorDigit")
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Validation parameters for zero-suppressed GTIN-12.
|
|
60
|
+
*/
|
|
61
|
+
static ZERO_SUPPRESSED_GTIN12_VALIDATION = {
|
|
62
|
+
minimumLength: 8,
|
|
63
|
+
maximumLength: 8
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Constructor.
|
|
67
|
+
*
|
|
68
|
+
* @param gtinType
|
|
69
|
+
* GTIN type.
|
|
70
|
+
*/
|
|
71
|
+
constructor(gtinType) {
|
|
72
|
+
let prefixType;
|
|
73
|
+
// Determine the prefix type based on the GTIN type.
|
|
74
|
+
switch (gtinType) {
|
|
75
|
+
case GTINTypes.GTIN13:
|
|
76
|
+
prefixType = PrefixTypes.GS1CompanyPrefix;
|
|
77
|
+
break;
|
|
78
|
+
case GTINTypes.GTIN12:
|
|
79
|
+
prefixType = PrefixTypes.UPCCompanyPrefix;
|
|
80
|
+
break;
|
|
81
|
+
case GTINTypes.GTIN8:
|
|
82
|
+
prefixType = PrefixTypes.GS18Prefix;
|
|
83
|
+
break;
|
|
84
|
+
default:
|
|
85
|
+
// Should never get here.
|
|
86
|
+
throw new Error("Not supported");
|
|
87
|
+
}
|
|
88
|
+
super(IdentifierTypes.GTIN, prefixType, gtinType, LeaderTypes.IndicatorDigit);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* @inheritDoc
|
|
92
|
+
*/
|
|
93
|
+
get gtinType() {
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Length maps to GTIN type.
|
|
95
|
+
return this.length;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* @inheritDoc
|
|
99
|
+
*/
|
|
100
|
+
validatePrefix(partialIdentifier, positionOffset) {
|
|
101
|
+
// Delegate to prefix validator requiring exact match for prefix type.
|
|
102
|
+
PrefixValidator.validate(this.prefixType, false, false, partialIdentifier, true, true, positionOffset);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Zero suppress a GTIN-12.
|
|
106
|
+
*
|
|
107
|
+
* @param gtin12
|
|
108
|
+
* GTIN-12.
|
|
109
|
+
*
|
|
110
|
+
* @returns
|
|
111
|
+
* Zero-suppressed GTIN-12.
|
|
112
|
+
*/
|
|
113
|
+
static zeroSuppress(gtin12) {
|
|
114
|
+
GTIN12_VALIDATOR.validate(gtin12);
|
|
115
|
+
// Convert to individual digits.
|
|
116
|
+
const d = Array.from(gtin12);
|
|
117
|
+
let zeroSuppressedGTIN12;
|
|
118
|
+
// All rules require that digits in positions 1, 5, and 6 be zero.
|
|
119
|
+
if (d[0] === "0" && d[6] === "0" && d[7] === "0") {
|
|
120
|
+
if (d[10] >= "5" && d[8] === "0" && d[9] === "0" && d[5] !== "0") {
|
|
121
|
+
zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[3]}${d[4]}${d[5]}${d[10]}${d[11]}`;
|
|
122
|
+
}
|
|
123
|
+
else if (d[5] === "0" && d[8] === "0" && d[9] === "0" && d[4] !== "0") {
|
|
124
|
+
zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[3]}${d[4]}${d[10]}4${d[11]}`;
|
|
125
|
+
}
|
|
126
|
+
else if (d[3] <= "2" && d[4] === "0" && d[5] === "0") {
|
|
127
|
+
zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[8]}${d[9]}${d[10]}${d[3]}${d[11]}`;
|
|
128
|
+
}
|
|
129
|
+
else if (d[3] >= "3" && d[4] === "0" && d[5] === "0" && d[8] === "0") {
|
|
130
|
+
zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[3]}${d[9]}${d[10]}3${d[11]}`;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (zeroSuppressedGTIN12 === undefined) {
|
|
134
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidZeroSuppressibleGTIN12"));
|
|
135
|
+
}
|
|
136
|
+
return zeroSuppressedGTIN12;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Zero expand a zero-suppressed GTIN-12.
|
|
140
|
+
*
|
|
141
|
+
* @param zeroSuppressedGTIN12
|
|
142
|
+
* Zero-suppressed GTIN-12.
|
|
143
|
+
*
|
|
144
|
+
* @returns
|
|
145
|
+
* GTIN-12.
|
|
146
|
+
*/
|
|
147
|
+
static zeroExpand(zeroSuppressedGTIN12) {
|
|
148
|
+
NUMERIC_CREATOR.validate(zeroSuppressedGTIN12, GTINValidator.ZERO_SUPPRESSED_GTIN12_VALIDATION);
|
|
149
|
+
// Convert to individual digits.
|
|
150
|
+
const d = Array.from(zeroSuppressedGTIN12);
|
|
151
|
+
let gtin12;
|
|
152
|
+
// Zero-suppressed GTIN-12 always starts with 0.
|
|
153
|
+
if (d[0] === "0") {
|
|
154
|
+
if (d[6] >= "5" && d[5] !== "0") {
|
|
155
|
+
gtin12 = `0${d[1]}${d[2]}${d[3]}${d[4]}${d[5]}0000${d[6]}${d[7]}`;
|
|
156
|
+
}
|
|
157
|
+
else if (d[6] === "4" && d[4] !== "0") {
|
|
158
|
+
gtin12 = `0${d[1]}${d[2]}${d[3]}${d[4]}00000${d[5]}${d[7]}`;
|
|
159
|
+
}
|
|
160
|
+
else if (d[6] <= "2") {
|
|
161
|
+
gtin12 = `0${d[1]}${d[2]}${d[6]}0000${d[3]}${d[4]}${d[5]}${d[7]}`;
|
|
162
|
+
}
|
|
163
|
+
else if (d[6] === "3" && d[3] >= "3") {
|
|
164
|
+
gtin12 = `0${d[1]}${d[2]}${d[3]}00000${d[4]}${d[5]}${d[7]}`;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (gtin12 === undefined) {
|
|
168
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidZeroSuppressedGTIN12"));
|
|
169
|
+
}
|
|
170
|
+
// Make sure that resulting GTIN-12 is valid.
|
|
171
|
+
GTIN12_VALIDATOR.validate(gtin12);
|
|
172
|
+
return gtin12;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Convert a GTIN of any length to a GTIN-14 with an optional indicator digit.
|
|
176
|
+
*
|
|
177
|
+
* @param indicatorDigit
|
|
178
|
+
* Indicator digit. If blank, assumes "0" if the GTIN is not already a GTIN-14.
|
|
179
|
+
*
|
|
180
|
+
* @param gtin
|
|
181
|
+
* GTIN.
|
|
182
|
+
*
|
|
183
|
+
* @returns
|
|
184
|
+
* GTIN-14.
|
|
185
|
+
*/
|
|
186
|
+
static convertToGTIN14(indicatorDigit, gtin) {
|
|
187
|
+
GTINValidator.validateAny(gtin);
|
|
188
|
+
NUMERIC_CREATOR.validate(indicatorDigit, GTINValidator.OPTIONAL_INDICATOR_DIGIT_VALIDATION);
|
|
189
|
+
// Check digit doesn't change by prepending zeros.
|
|
190
|
+
let gtin14 = gtin.padStart(GTINTypes.GTIN14, "0");
|
|
191
|
+
// If indicator digit provided and is different, recalculate the check digit.
|
|
192
|
+
if (indicatorDigit.length !== 0 && indicatorDigit !== gtin14.charAt(0)) {
|
|
193
|
+
const partialGTIN14 = indicatorDigit + gtin14.substring(1, GTINTypes.GTIN14 - 1);
|
|
194
|
+
gtin14 = partialGTIN14 + checkDigit(partialGTIN14);
|
|
195
|
+
}
|
|
196
|
+
return gtin14;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Normalize a GTIN of any length.
|
|
200
|
+
* - A GTIN-14 that starts with six zeros or a GTIN-13 that starts with five zeros is normalized to GTIN-8.
|
|
201
|
+
* - A GTIN-14 that starts with two zeros or a GTIN-13 that starts with one zero is normalized to GTIN-12.
|
|
202
|
+
* - A GTIN-14 that starts with one zero is normalized to GTIN-13.
|
|
203
|
+
* - Otherwise, the GTIN is unchanged.
|
|
204
|
+
*
|
|
205
|
+
* @param gtin
|
|
206
|
+
* GTIN.
|
|
207
|
+
*
|
|
208
|
+
* @returns
|
|
209
|
+
* Normalized GTIN.
|
|
210
|
+
*/
|
|
211
|
+
static normalize(gtin) {
|
|
212
|
+
const gtinLength = gtin.length;
|
|
213
|
+
let normalizedGTIN;
|
|
214
|
+
switch (gtinLength) {
|
|
215
|
+
case GTINTypes.GTIN13:
|
|
216
|
+
if (!gtin.startsWith("0")) {
|
|
217
|
+
// GTIN is GTIN-13.
|
|
218
|
+
normalizedGTIN = gtin;
|
|
219
|
+
}
|
|
220
|
+
else if (!gtin.startsWith("00000")) {
|
|
221
|
+
// GTIN is GTIN-12.
|
|
222
|
+
normalizedGTIN = gtin.substring(1);
|
|
223
|
+
}
|
|
224
|
+
else if (!gtin.startsWith("000000")) {
|
|
225
|
+
// GTIN is GTIN-8.
|
|
226
|
+
normalizedGTIN = gtin.substring(5);
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidZeroSuppressedGTIN12AsGTIN13"));
|
|
230
|
+
}
|
|
231
|
+
break;
|
|
232
|
+
case GTINTypes.GTIN12:
|
|
233
|
+
// GTIN is GTIN-12.
|
|
234
|
+
normalizedGTIN = gtin;
|
|
235
|
+
break;
|
|
236
|
+
case GTINTypes.GTIN8:
|
|
237
|
+
if (!gtin.startsWith("0")) {
|
|
238
|
+
// GTIN is GTIN-8.
|
|
239
|
+
normalizedGTIN = gtin;
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
// GTIN is zero-suppressed GTIN-12.
|
|
243
|
+
normalizedGTIN = GTINValidator.zeroExpand(gtin);
|
|
244
|
+
}
|
|
245
|
+
break;
|
|
246
|
+
case GTINTypes.GTIN14:
|
|
247
|
+
if (!gtin.startsWith("0")) {
|
|
248
|
+
// GTIN is GTIN-14.
|
|
249
|
+
normalizedGTIN = gtin;
|
|
250
|
+
}
|
|
251
|
+
else if (!gtin.startsWith("00")) {
|
|
252
|
+
// GTIN is GTIN-13.
|
|
253
|
+
normalizedGTIN = gtin.substring(1);
|
|
254
|
+
}
|
|
255
|
+
else if (!gtin.startsWith("000000")) {
|
|
256
|
+
// GTIN is GTIN-12.
|
|
257
|
+
normalizedGTIN = gtin.substring(2);
|
|
258
|
+
}
|
|
259
|
+
else if (!gtin.startsWith("0000000")) {
|
|
260
|
+
// GTIN is GTIN-8.
|
|
261
|
+
normalizedGTIN = gtin.substring(6);
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidZeroSuppressedGTIN12AsGTIN14"));
|
|
265
|
+
}
|
|
266
|
+
break;
|
|
267
|
+
default:
|
|
268
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidGTINLength"));
|
|
269
|
+
}
|
|
270
|
+
// Validation applies to the normalized GTIN.
|
|
271
|
+
GTINValidator.validateAny(normalizedGTIN);
|
|
272
|
+
return normalizedGTIN;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Validate any GTIN, optionally against a level.
|
|
276
|
+
*
|
|
277
|
+
* @param gtin
|
|
278
|
+
* GTIN.
|
|
279
|
+
*
|
|
280
|
+
* @param gtinLevel
|
|
281
|
+
* Level at which GTIN is to be validated.
|
|
282
|
+
*/
|
|
283
|
+
static validateAny(gtin, gtinLevel = GTINLevels.Any) {
|
|
284
|
+
// Assume length-validated GTIN is the GTIN (true for all except zero-suppressed GTIN-12).
|
|
285
|
+
let lengthValidatedGTIN = gtin;
|
|
286
|
+
let gtinLevelRestriction;
|
|
287
|
+
switch (gtin.length) {
|
|
288
|
+
case GTINTypes.GTIN13:
|
|
289
|
+
if (gtin.startsWith("0")) {
|
|
290
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidGTIN13AtRetail"));
|
|
291
|
+
}
|
|
292
|
+
// Validate prefix requiring exact match for prefix type.
|
|
293
|
+
PrefixValidator.validate(PrefixTypes.GS1CompanyPrefix, false, false, gtin, true, true);
|
|
294
|
+
gtinLevelRestriction = GTINLevels.Any;
|
|
295
|
+
break;
|
|
296
|
+
case GTINTypes.GTIN12:
|
|
297
|
+
// Validate prefix requiring exact match for prefix type.
|
|
298
|
+
PrefixValidator.validate(PrefixTypes.UPCCompanyPrefix, false, false, gtin, true, true);
|
|
299
|
+
gtinLevelRestriction = GTINLevels.Any;
|
|
300
|
+
break;
|
|
301
|
+
case GTINTypes.GTIN8:
|
|
302
|
+
// Zero-suppressed GTIN-12 always starts with 0.
|
|
303
|
+
if (!gtin.startsWith("0")) {
|
|
304
|
+
// Validate prefix requiring exact match for prefix type.
|
|
305
|
+
PrefixValidator.validate(PrefixTypes.GS18Prefix, false, false, gtin, true, true);
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
lengthValidatedGTIN = GTINValidator.zeroExpand(gtin);
|
|
309
|
+
}
|
|
310
|
+
gtinLevelRestriction = GTINLevels.RetailConsumer;
|
|
311
|
+
break;
|
|
312
|
+
case GTINTypes.GTIN14:
|
|
313
|
+
// Validate prefix supporting any prefix type.
|
|
314
|
+
PrefixValidator.validate(PrefixTypes.GS1CompanyPrefix, true, true, gtin.substring(1), true, true);
|
|
315
|
+
gtinLevelRestriction = GTINLevels.OtherThanRetailConsumer;
|
|
316
|
+
break;
|
|
317
|
+
default:
|
|
318
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidGTINLength"));
|
|
319
|
+
}
|
|
320
|
+
// Validating the check digit will also validate the characters.
|
|
321
|
+
if (!hasValidCheckDigit(lengthValidatedGTIN)) {
|
|
322
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidCheckDigit"));
|
|
323
|
+
}
|
|
324
|
+
// Validate against level if required.
|
|
325
|
+
if (gtinLevel !== GTINLevels.Any && gtinLevelRestriction !== GTINLevels.Any && gtinLevelRestriction !== gtinLevel) {
|
|
326
|
+
throw new RangeError(i18nextGS1.t(gtinLevel === GTINLevels.RetailConsumer ? "Identifier.invalidGTINAtRetail" : "Identifier.invalidGTINAtOtherThanRetail"));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Validate a GTIN-14.
|
|
331
|
+
*
|
|
332
|
+
* @param gtin14
|
|
333
|
+
* GTIN-14.
|
|
334
|
+
*/
|
|
335
|
+
static validateGTIN14(gtin14) {
|
|
336
|
+
if (gtin14.length !== GTINTypes.GTIN14) {
|
|
337
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidGTIN14Length"));
|
|
338
|
+
}
|
|
339
|
+
GTINValidator.validateAny(gtin14);
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Parse a Restricted Circulation Number (RCN) using a variable measure trade item format. The format is a 12- or
|
|
343
|
+
* 13-character string (for RCN-12 or RCN-13 respectively), containing the following:
|
|
344
|
+
*
|
|
345
|
+
* - '2' - The first character of the RCN.
|
|
346
|
+
* - '0'-'9' - The second character of the RCN (RCN-13 only).
|
|
347
|
+
* - 'I' - One or more, in sequence, for the item reference.
|
|
348
|
+
* - 'P' - One or more, in sequence, for the price or weight.
|
|
349
|
+
* - 'V' - Zero or one, for the price or weight check digit.
|
|
350
|
+
* - 'C' - The check digit of the entire RCN.
|
|
351
|
+
*
|
|
352
|
+
* The 'I', 'P', and 'V' formats may be in any order.
|
|
353
|
+
*
|
|
354
|
+
* Some examples:
|
|
355
|
+
*
|
|
356
|
+
* - 2IIIIIVPPPPC - RCN-12 with a five-digit item reference, a price or weight check digit, and a four-digit price
|
|
357
|
+
* or weight.
|
|
358
|
+
* - 23IIIIVPPPPPC - RCN-13 with a four-digit item reference, a price or weight check digit, and a five-digit price
|
|
359
|
+
* or weight.
|
|
360
|
+
* - 2IIIIIIPPPPC - RCN-12 with a six-digit item reference and a four-digit price or eight.
|
|
361
|
+
* - 29IIIIIPPPPPC - RCN-13 with a five-digit item reference and a five-digit price or weight.
|
|
362
|
+
*
|
|
363
|
+
* @param format
|
|
364
|
+
* Format.
|
|
365
|
+
*
|
|
366
|
+
* @param rcn
|
|
367
|
+
* RCN.
|
|
368
|
+
*
|
|
369
|
+
* @returns
|
|
370
|
+
* RCN reference.
|
|
371
|
+
*/
|
|
372
|
+
static parseVariableMeasureRCN(format, rcn) {
|
|
373
|
+
const formatLength = format.length;
|
|
374
|
+
if (rcn.length !== formatLength) {
|
|
375
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidRCNLength"));
|
|
376
|
+
}
|
|
377
|
+
let validFormat = formatLength === 12 || formatLength === 13;
|
|
378
|
+
let validRCNPrefix = true;
|
|
379
|
+
let buildingItemReference = false;
|
|
380
|
+
let itemReference = "";
|
|
381
|
+
let buildingPriceOrWeight = false;
|
|
382
|
+
let priceOrWeight = "";
|
|
383
|
+
let priceOrWeightCheckDigit = "";
|
|
384
|
+
for (let index = 0; validFormat && index < formatLength; index++) {
|
|
385
|
+
const formatChar = format.charAt(index);
|
|
386
|
+
const rcnChar = rcn.charAt(index);
|
|
387
|
+
if (index === 0) {
|
|
388
|
+
validFormat = formatChar === "2";
|
|
389
|
+
validRCNPrefix = rcnChar === "2";
|
|
390
|
+
}
|
|
391
|
+
else if (formatLength === 13 && index === 1) {
|
|
392
|
+
validFormat = NUMERIC_CREATOR.characterIndex(formatChar) !== undefined;
|
|
393
|
+
validRCNPrefix = rcnChar === formatChar;
|
|
394
|
+
}
|
|
395
|
+
else if (index === formatLength - 1) {
|
|
396
|
+
validFormat = formatChar === "C";
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
switch (formatChar) {
|
|
400
|
+
case "I":
|
|
401
|
+
if (!buildingItemReference) {
|
|
402
|
+
// Item reference can't appear more than once.
|
|
403
|
+
validFormat = itemReference === "";
|
|
404
|
+
buildingItemReference = true;
|
|
405
|
+
buildingPriceOrWeight = false;
|
|
406
|
+
}
|
|
407
|
+
itemReference += rcnChar;
|
|
408
|
+
break;
|
|
409
|
+
case "P":
|
|
410
|
+
if (!buildingPriceOrWeight) {
|
|
411
|
+
// Price or weight can't appear more than once.
|
|
412
|
+
validFormat = priceOrWeight === "";
|
|
413
|
+
buildingPriceOrWeight = true;
|
|
414
|
+
buildingItemReference = false;
|
|
415
|
+
}
|
|
416
|
+
priceOrWeight += rcnChar;
|
|
417
|
+
break;
|
|
418
|
+
case "V":
|
|
419
|
+
// Price or weight check digit can't appear more than once.
|
|
420
|
+
validFormat = priceOrWeightCheckDigit === "";
|
|
421
|
+
buildingItemReference = false;
|
|
422
|
+
buildingPriceOrWeight = false;
|
|
423
|
+
priceOrWeightCheckDigit = rcnChar;
|
|
424
|
+
break;
|
|
425
|
+
default:
|
|
426
|
+
validFormat = false;
|
|
427
|
+
break;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
validFormat &&= itemReference !== "" && priceOrWeight !== "";
|
|
432
|
+
if (!validFormat) {
|
|
433
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidVariableMeasureRCNFormat"));
|
|
434
|
+
}
|
|
435
|
+
if (!validRCNPrefix) {
|
|
436
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidVariableMeasureRCNPrefix"));
|
|
437
|
+
}
|
|
438
|
+
if (priceOrWeightCheckDigit !== "" && !isValidPriceOrWeightCheckDigit(priceOrWeight, priceOrWeightCheckDigit)) {
|
|
439
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidVariableMeasurePriceOrWeight"));
|
|
440
|
+
}
|
|
441
|
+
if (!hasValidCheckDigit(rcn)) {
|
|
442
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidCheckDigit"));
|
|
443
|
+
}
|
|
444
|
+
return {
|
|
445
|
+
itemReference: Number(itemReference),
|
|
446
|
+
priceOrWeight: Number(priceOrWeight)
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* GTIN-13 validator.
|
|
452
|
+
*/
|
|
453
|
+
export const GTIN13_VALIDATOR = new GTINValidator(GTINTypes.GTIN13);
|
|
454
|
+
/**
|
|
455
|
+
* GTIN-12 validator.
|
|
456
|
+
*/
|
|
457
|
+
export const GTIN12_VALIDATOR = new GTINValidator(GTINTypes.GTIN12);
|
|
458
|
+
/**
|
|
459
|
+
* GTIN-8 validator.
|
|
460
|
+
*/
|
|
461
|
+
export const GTIN8_VALIDATOR = new GTINValidator(GTINTypes.GTIN8);
|
|
462
|
+
/**
|
|
463
|
+
* GTIN validators indexed by prefix type.
|
|
464
|
+
*/
|
|
465
|
+
export const GTIN_VALIDATORS = {
|
|
466
|
+
[PrefixTypes.GS1CompanyPrefix]: GTIN13_VALIDATOR,
|
|
467
|
+
[PrefixTypes.UPCCompanyPrefix]: GTIN12_VALIDATOR,
|
|
468
|
+
[PrefixTypes.GS18Prefix]: GTIN8_VALIDATOR
|
|
469
|
+
};
|
|
470
|
+
//# sourceMappingURL=gtin-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gtin-validator.js","sourceRoot":"","sources":["../src/gtin-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,kCAAkC,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AACpG,OAAO,EA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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,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,aAAa,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAEpE;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,aAAa,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAEpE;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,aAAa,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAElE;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAsC;IAC9D,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAE,gBAAgB;IAChD,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAE,gBAAgB;IAChD,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,eAAe;CAC5C,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { CharacterSetCreator } from "@aidc-toolkit/utility";
|
|
2
|
+
import type { IdentifierType } from "./identifier-type.js";
|
|
3
|
+
import type { ContentCharacterSet, IdentifierValidation, IdentifierValidator } from "./identifier-validator.js";
|
|
4
|
+
import type { PrefixProvider } from "./prefix-provider";
|
|
5
|
+
import type { PrefixType } from "./prefix-type.js";
|
|
6
|
+
/**
|
|
7
|
+
* Identifier creator. Creates an identifier based on its definition in section 3 of the {@link
|
|
8
|
+
* https://www.gs1.org/genspecs | GS1 General Specifications}.
|
|
9
|
+
*
|
|
10
|
+
* Keys are created based on a prefix defined in a prefix manager to which the identifier creator is bound.
|
|
11
|
+
*/
|
|
12
|
+
export interface IdentifierCreator extends IdentifierValidator {
|
|
13
|
+
/**
|
|
14
|
+
* Get the prefix provider to which this identifier creator is bound.
|
|
15
|
+
*/
|
|
16
|
+
get prefixProvider(): PrefixProvider;
|
|
17
|
+
/**
|
|
18
|
+
* Get the prefix, equivalent to calling {@linkcode PrefixProvider.prefix | prefixProvider.prefix} for a GTIN or
|
|
19
|
+
* {@linkcode PrefixProvider.gs1CompanyPrefix | prefixProvider.gs1CompanyPrefix} for all other identifier types.
|
|
20
|
+
*/
|
|
21
|
+
get prefix(): string;
|
|
22
|
+
/**
|
|
23
|
+
* Get the reference length.
|
|
24
|
+
*/
|
|
25
|
+
get referenceLength(): number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Abstract identifier creator. Implements common functionality for an identifier creator, bound to a
|
|
29
|
+
* {@link PrefixProvider}.
|
|
30
|
+
*/
|
|
31
|
+
export declare abstract class AbstractIdentifierCreator implements IdentifierCreator {
|
|
32
|
+
/**
|
|
33
|
+
* Prefix provider.
|
|
34
|
+
*/
|
|
35
|
+
private _prefixProvider;
|
|
36
|
+
/**
|
|
37
|
+
* Reference length.
|
|
38
|
+
*/
|
|
39
|
+
private _referenceLength;
|
|
40
|
+
/**
|
|
41
|
+
* Initialize the prefix manager. This method is in lieu of a constructor due to the mixin architecture.
|
|
42
|
+
*
|
|
43
|
+
* @param prefixProvider
|
|
44
|
+
* Prefix provider.
|
|
45
|
+
*
|
|
46
|
+
* @param prefix
|
|
47
|
+
* Prefix within prefix manager to use to calculate reference length.
|
|
48
|
+
*
|
|
49
|
+
* @param checkAllowance
|
|
50
|
+
* Number of characters to allow for check digit or check character pair.
|
|
51
|
+
*/
|
|
52
|
+
protected init(prefixProvider: PrefixProvider, prefix: string, checkAllowance: number): void;
|
|
53
|
+
abstract get identifierType(): IdentifierType;
|
|
54
|
+
abstract get prefixType(): PrefixType;
|
|
55
|
+
abstract get length(): number;
|
|
56
|
+
abstract get referenceCharacterSet(): ContentCharacterSet;
|
|
57
|
+
abstract get referenceCreator(): CharacterSetCreator;
|
|
58
|
+
/**
|
|
59
|
+
* @inheritDoc
|
|
60
|
+
*/
|
|
61
|
+
get prefixProvider(): PrefixProvider;
|
|
62
|
+
/**
|
|
63
|
+
* @inheritDoc
|
|
64
|
+
*/
|
|
65
|
+
get prefix(): string;
|
|
66
|
+
/**
|
|
67
|
+
* @inheritDoc
|
|
68
|
+
*/
|
|
69
|
+
get referenceLength(): number;
|
|
70
|
+
abstract validate(identifier: string, validation?: IdentifierValidation): void;
|
|
71
|
+
}
|
|
72
|
+
//# 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,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,WAAW,iBAAkB,SAAQ,mBAAmB;IAC1D;;OAEG;IACH,IAAI,cAAc,IAAI,cAAc,CAAC;IAErC;;;OAGG;IACH,IAAI,MAAM,IAAI,MAAM,CAAC;IAErB;;OAEG;IACH,IAAI,eAAe,IAAI,MAAM,CAAC;CACjC;AAED;;;GAGG;AACH,8BAAsB,yBAA0B,YAAW,iBAAiB;IACxE;;OAEG;IACH,OAAO,CAAC,eAAe,CAAkB;IAEzC;;OAEG;IACH,OAAO,CAAC,gBAAgB,CAAU;IAElC;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,IAAI,CAAC,cAAc,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,IAAI;IAO5F,QAAQ,KAAK,cAAc,IAAI,cAAc,CAAC;IAE9C,QAAQ,KAAK,UAAU,IAAI,UAAU,CAAC;IAEtC,QAAQ,KAAK,MAAM,IAAI,MAAM,CAAC;IAE9B,QAAQ,KAAK,qBAAqB,IAAI,mBAAmB,CAAC;IAE1D,QAAQ,KAAK,gBAAgB,IAAI,mBAAmB,CAAC;IAErD;;OAEG;IACH,IAAI,cAAc,IAAI,cAAc,CAEnC;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;OAEG;IACH,IAAI,eAAe,IAAI,MAAM,CAE5B;IAED,QAAQ,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,oBAAoB,GAAG,IAAI;CACjF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract identifier creator. Implements common functionality for an identifier creator, bound to a
|
|
3
|
+
* {@link PrefixProvider}.
|
|
4
|
+
*/
|
|
5
|
+
export class AbstractIdentifierCreator {
|
|
6
|
+
/**
|
|
7
|
+
* Prefix provider.
|
|
8
|
+
*/
|
|
9
|
+
_prefixProvider;
|
|
10
|
+
/**
|
|
11
|
+
* Reference length.
|
|
12
|
+
*/
|
|
13
|
+
_referenceLength;
|
|
14
|
+
/**
|
|
15
|
+
* Initialize the prefix manager. This method is in lieu of a constructor due to the mixin architecture.
|
|
16
|
+
*
|
|
17
|
+
* @param prefixProvider
|
|
18
|
+
* Prefix provider.
|
|
19
|
+
*
|
|
20
|
+
* @param prefix
|
|
21
|
+
* Prefix within prefix manager to use to calculate reference length.
|
|
22
|
+
*
|
|
23
|
+
* @param checkAllowance
|
|
24
|
+
* Number of characters to allow for check digit or check character pair.
|
|
25
|
+
*/
|
|
26
|
+
init(prefixProvider, prefix, checkAllowance) {
|
|
27
|
+
this._prefixProvider = prefixProvider;
|
|
28
|
+
// Reference length allows for prefix and optionally check digit or check character pair.
|
|
29
|
+
this._referenceLength = this.length - prefix.length - checkAllowance;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @inheritDoc
|
|
33
|
+
*/
|
|
34
|
+
get prefixProvider() {
|
|
35
|
+
return this._prefixProvider;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @inheritDoc
|
|
39
|
+
*/
|
|
40
|
+
get prefix() {
|
|
41
|
+
return this.prefixProvider.gs1CompanyPrefix;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @inheritDoc
|
|
45
|
+
*/
|
|
46
|
+
get referenceLength() {
|
|
47
|
+
return this._referenceLength;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=identifier-creator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifier-creator.js","sourceRoot":"","sources":["../src/identifier-creator.ts"],"names":[],"mappings":"AA8BA;;;GAGG;AACH,MAAM,OAAgB,yBAAyB;IAC3C;;OAEG;IACK,eAAe,CAAkB;IAEzC;;OAEG;IACK,gBAAgB,CAAU;IAElC;;;;;;;;;;;OAWG;IACO,IAAI,CAAC,cAA8B,EAAE,MAAc,EAAE,cAAsB;QACjF,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;QAEtC,yFAAyF;QACzF,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,GAAG,cAAc,CAAC;IACzE,CAAC;IAYD;;OAEG;IACH,IAAI,cAAc;QACd,OAAO,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,cAAc,CAAC,gBAAgB,CAAC;IAChD,CAAC;IAED;;OAEG;IACH,IAAI,eAAe;QACf,OAAO,IAAI,CAAC,gBAAgB,CAAC;IACjC,CAAC;CAGJ"}
|
|
@@ -0,0 +1,58 @@
|
|
|
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.
|
|
56
|
+
*/
|
|
57
|
+
export type IdentifierType = typeof IdentifierTypes[keyof typeof IdentifierTypes];
|
|
58
|
+
//# sourceMappingURL=identifier-type.d.ts.map
|