@aidc-toolkit/gs1 0.9.15-beta → 0.9.17-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/index.cjs DELETED
@@ -1,2067 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- AI39_CREATOR: () => AI39_CREATOR,
34
- AI82_CREATOR: () => AI82_CREATOR,
35
- CPID_VALIDATOR: () => CPID_VALIDATOR,
36
- ContentCharacterSet: () => ContentCharacterSet,
37
- GCN_VALIDATOR: () => GCN_VALIDATOR,
38
- GDTI_VALIDATOR: () => GDTI_VALIDATOR,
39
- GIAI_VALIDATOR: () => GIAI_VALIDATOR,
40
- GINC_VALIDATOR: () => GINC_VALIDATOR,
41
- GLN_VALIDATOR: () => GLN_VALIDATOR,
42
- GMN_VALIDATOR: () => GMN_VALIDATOR,
43
- GRAI_VALIDATOR: () => GRAI_VALIDATOR,
44
- GSIN_VALIDATOR: () => GSIN_VALIDATOR,
45
- GSRN_VALIDATOR: () => GSRN_VALIDATOR,
46
- GTIN12_VALIDATOR: () => GTIN12_VALIDATOR,
47
- GTIN13_VALIDATOR: () => GTIN13_VALIDATOR,
48
- GTIN8_VALIDATOR: () => GTIN8_VALIDATOR,
49
- GTINCreator: () => GTINCreator,
50
- GTINLevel: () => GTINLevel,
51
- GTINType: () => GTINType,
52
- GTINValidator: () => GTINValidator,
53
- GTIN_VALIDATORS: () => GTIN_VALIDATORS,
54
- IdentificationKeyType: () => IdentificationKeyType,
55
- LeaderType: () => LeaderType,
56
- NonGTINNumericIdentificationKeyCreator: () => NonGTINNumericIdentificationKeyCreator,
57
- NonGTINNumericIdentificationKeyValidator: () => NonGTINNumericIdentificationKeyValidator,
58
- NonNumericIdentificationKeyCreator: () => NonNumericIdentificationKeyCreator,
59
- NonNumericIdentificationKeyValidator: () => NonNumericIdentificationKeyValidator,
60
- PrefixManager: () => PrefixManager,
61
- PrefixType: () => PrefixType,
62
- SSCC_VALIDATOR: () => SSCC_VALIDATOR,
63
- SerializableNumericIdentificationKeyCreator: () => SerializableNumericIdentificationKeyCreator,
64
- SerializableNumericIdentificationKeyValidator: () => SerializableNumericIdentificationKeyValidator,
65
- checkCharacterPair: () => checkCharacterPair,
66
- checkDigit: () => checkDigit,
67
- checkDigitSum: () => checkDigitSum,
68
- fiveDigitPriceWeightCheckDigit: () => fiveDigitPriceWeightCheckDigit,
69
- fourDigitPriceWeightCheckDigit: () => fourDigitPriceWeightCheckDigit,
70
- gs1NS: () => gs1NS,
71
- gs1Resources: () => gs1Resources,
72
- hasValidCheckCharacterPair: () => hasValidCheckCharacterPair,
73
- hasValidCheckDigit: () => hasValidCheckDigit,
74
- i18nGS1Init: () => i18nGS1Init,
75
- i18nextGS1: () => i18nextGS1
76
- });
77
- module.exports = __toCommonJS(index_exports);
78
-
79
- // src/locale/i18n.ts
80
- var import_core = require("@aidc-toolkit/core");
81
- var import_utility = require("@aidc-toolkit/utility");
82
- var import_i18next = __toESM(require("i18next"), 1);
83
-
84
- // src/locale/en/locale-strings.ts
85
- var localeStrings = {
86
- Check: {
87
- lengthOfStringForPriceOrWeightMustBeExactly: "Length {{length}} of string for price or weight sum must be exactly {{exactLength}}",
88
- priceOrWeightComponent: "price or weight",
89
- lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "Length {{length}} of string for check character pair must be less than or equal to {{maximumLength}}"
90
- },
91
- IdentificationKey: {
92
- identificationKeyTypeLength: "{{identificationKeyType}} must be {{length}} digits long",
93
- invalidCheckDigit: "Invalid check digit",
94
- invalidGTINLength: "GTIN must be 13, 12, 8, or 14 digits long",
95
- invalidGTIN14Length: "GTIN must be 14 digits long",
96
- invalidZeroSuppressedGTIN12: "Invalid zero-suppressed GTIN-12",
97
- invalidZeroSuppressibleGTIN12: "GTIN-12 not zero-suppressible",
98
- invalidZeroSuppressedGTIN12AsGTIN13: "Invalid zero-suppressed GTIN-12 as GTIN-13",
99
- invalidZeroSuppressedGTIN12AsGTIN14: "Invalid zero-suppressed GTIN-12 as GTIN-14",
100
- invalidGTIN13AtRetail: "GTIN-13 at retail consumer trade item level can't start with zero",
101
- invalidGTINAtRetail: "GTIN not supported at retail consumer trade item level",
102
- invalidGTINAtOtherThanRetail: "GTIN not supported at other than retail consumer trade item level",
103
- indicatorDigit: "indicator digit",
104
- serialComponent: "serial component",
105
- reference: "reference",
106
- referenceCantBeAllNumeric: "Reference can't be all-numeric",
107
- invalidCheckCharacterPair: "Invalid check character pair"
108
- },
109
- Prefix: {
110
- gs1CompanyPrefix: "GS1 Company Prefix",
111
- upcCompanyPrefix: "U.P.C. Company Prefix",
112
- gs18Prefix: "GS1-8 Prefix",
113
- invalidPrefixType: "Invalid prefix type",
114
- gs1CompanyPrefixCantStartWith0: `GS1 Company Prefix can't start with "0"`,
115
- gs1CompanyPrefixCantStartWith00000: `GS1 Company Prefix can't start with "00000"`,
116
- gs1CompanyPrefixCantStartWith000000: `GS1 Company Prefix can't start with "000000"`,
117
- upcCompanyPrefixCantStartWith0000: `U.P.C. Company Prefix can't start with "0000"`,
118
- gs18PrefixCantStartWith0: `GS1-8 Prefix can't start with "0"`,
119
- identificationKeyTypeNotSupportedByGS18Prefix: "{{identificationKeyType}} not supported by GS1-8 Prefix"
120
- }
121
- };
122
-
123
- // src/locale/fr/locale-strings.ts
124
- var localeStrings2 = {
125
- Check: {
126
- lengthOfStringForPriceOrWeightMustBeExactly: "La longueur {{longueur}} de la cha\xEEne pour le prix ou la somme du poids doit \xEAtre exactement {{exactLength}}",
127
- priceOrWeightComponent: "prix ou poids",
128
- lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "La longueur {{length}} de la cha\xEEne pour la paire de caract\xE8res de v\xE9rification doit \xEAtre inf\xE9rieure ou \xE9gale \xE0 {{maximum Length}}"
129
- },
130
- IdentificationKey: {
131
- identificationKeyTypeLength: "{{identificationKeyType}} doit comporter {{length}} chiffres",
132
- invalidCheckDigit: "Chiffre de contr\xF4le non valide",
133
- invalidGTINLength: "Le GTIN doit comporter 13, 12, 8 ou 14 chiffres",
134
- invalidGTIN14Length: "Le GTIN doit comporter 14 chiffres",
135
- invalidZeroSuppressedGTIN12: "Code GTIN-12 non valide avec z\xE9ro supprim\xE9",
136
- invalidZeroSuppressibleGTIN12: "Le GTIN-12 ne peut pas \xEAtre supprim\xE9 par z\xE9ro",
137
- invalidZeroSuppressedGTIN12AsGTIN13: "GTIN-12 non valide avec z\xE9ro supprim\xE9 en tant que GTIN-13",
138
- invalidZeroSuppressedGTIN12AsGTIN14: "GTIN-12 non valide avec z\xE9ro supprim\xE9 en tant que GTIN-14",
139
- invalidGTIN13AtRetail: "Le GTIN-13 au niveau des articles de consommation au d\xE9tail ne peut pas commencer par z\xE9ro",
140
- invalidGTINAtRetail: "Le GTIN n'est pas pris en charge au niveau des articles de consommation au d\xE9tail",
141
- invalidGTINAtOtherThanRetail: "Le GTIN n'est pas pris en charge \xE0 d'autres niveaux que ceux des articles de consommation au d\xE9tail",
142
- indicatorDigit: "chiffre indicateur",
143
- serialComponent: "composant s\xE9rie",
144
- reference: "r\xE9f\xE9rence",
145
- referenceCantBeAllNumeric: "La r\xE9f\xE9rence ne peut pas \xEAtre enti\xE8rement num\xE9rique",
146
- invalidCheckCharacterPair: "Paire de caract\xE8res de contr\xF4le non valide"
147
- },
148
- Prefix: {
149
- gs1CompanyPrefix: "Pr\xE9fixe de l'entreprise GS1",
150
- upcCompanyPrefix: "Pr\xE9fixe de l'entreprise U.P.C.",
151
- gs18Prefix: "Pr\xE9fixe GS1-8",
152
- invalidPrefixType: "Type de pr\xE9fixe invalide",
153
- gs1CompanyPrefixCantStartWith0: `Le pr\xE9fixe de l'entreprise GS1 ne peut pas commencer par "0"`,
154
- gs1CompanyPrefixCantStartWith00000: `Le pr\xE9fixe de l'entreprise GS1 ne peut pas commencer par "00000"`,
155
- gs1CompanyPrefixCantStartWith000000: `Le pr\xE9fixe de l'entreprise GS1 ne peut pas commencer par "000000"`,
156
- upcCompanyPrefixCantStartWith0000: `Le pr\xE9fixe de l'entreprise U.P.C. ne peut pas commencer par "0000"`,
157
- gs18PrefixCantStartWith0: 'Le pr\xE9fixe GS1-8 ne peut pas commencer par "0"',
158
- identificationKeyTypeNotSupportedByGS18Prefix: "{{identificationKeyType}} non pris en charge par le pr\xE9fixe GS1-8"
159
- }
160
- };
161
-
162
- // src/locale/i18n.ts
163
- var gs1NS = "aidct_gs1";
164
- (0, import_core.i18nAssertValidResources)(localeStrings, "fr", localeStrings2);
165
- var gs1Resources = {
166
- en: {
167
- aidct_gs1: localeStrings
168
- },
169
- fr: {
170
- aidct_gs1: localeStrings2
171
- }
172
- };
173
- var i18nextGS1 = import_i18next.default.createInstance();
174
- async function i18nGS1Init(environment, debug = false) {
175
- await (0, import_utility.i18nUtilityInit)(environment, debug);
176
- await (0, import_core.i18nCoreInit)(i18nextGS1, environment, debug, gs1NS, import_utility.utilityResources, gs1Resources);
177
- }
178
-
179
- // src/character-set.ts
180
- var import_utility2 = require("@aidc-toolkit/utility");
181
- var AI82_CREATOR = new import_utility2.CharacterSetCreator([
182
- "!",
183
- '"',
184
- "%",
185
- "&",
186
- "'",
187
- "(",
188
- ")",
189
- "*",
190
- "+",
191
- ",",
192
- "-",
193
- ".",
194
- "/",
195
- "0",
196
- "1",
197
- "2",
198
- "3",
199
- "4",
200
- "5",
201
- "6",
202
- "7",
203
- "8",
204
- "9",
205
- ":",
206
- ";",
207
- "<",
208
- "=",
209
- ">",
210
- "?",
211
- "A",
212
- "B",
213
- "C",
214
- "D",
215
- "E",
216
- "F",
217
- "G",
218
- "H",
219
- "I",
220
- "J",
221
- "K",
222
- "L",
223
- "M",
224
- "N",
225
- "O",
226
- "P",
227
- "Q",
228
- "R",
229
- "S",
230
- "T",
231
- "U",
232
- "V",
233
- "W",
234
- "X",
235
- "Y",
236
- "Z",
237
- "_",
238
- "a",
239
- "b",
240
- "c",
241
- "d",
242
- "e",
243
- "f",
244
- "g",
245
- "h",
246
- "i",
247
- "j",
248
- "k",
249
- "l",
250
- "m",
251
- "n",
252
- "o",
253
- "p",
254
- "q",
255
- "r",
256
- "s",
257
- "t",
258
- "u",
259
- "v",
260
- "w",
261
- "x",
262
- "y",
263
- "z"
264
- ], import_utility2.Exclusion.AllNumeric);
265
- var AI39_CREATOR = new import_utility2.CharacterSetCreator([
266
- "#",
267
- "-",
268
- "/",
269
- "0",
270
- "1",
271
- "2",
272
- "3",
273
- "4",
274
- "5",
275
- "6",
276
- "7",
277
- "8",
278
- "9",
279
- "A",
280
- "B",
281
- "C",
282
- "D",
283
- "E",
284
- "F",
285
- "G",
286
- "H",
287
- "I",
288
- "J",
289
- "K",
290
- "L",
291
- "M",
292
- "N",
293
- "O",
294
- "P",
295
- "Q",
296
- "R",
297
- "S",
298
- "T",
299
- "U",
300
- "V",
301
- "W",
302
- "X",
303
- "Y",
304
- "Z"
305
- ], import_utility2.Exclusion.AllNumeric);
306
-
307
- // src/check.ts
308
- var import_utility3 = require("@aidc-toolkit/utility");
309
- var THREE_WEIGHT_RESULTS = [
310
- 0,
311
- 3,
312
- 6,
313
- 9,
314
- 12,
315
- 15,
316
- 18,
317
- 21,
318
- 24,
319
- 27
320
- ];
321
- var TWO_MINUS_WEIGHT_RESULTS = [
322
- 0,
323
- 2,
324
- 4,
325
- 6,
326
- 8,
327
- 9,
328
- 1,
329
- 3,
330
- 5,
331
- 7
332
- ];
333
- var FIVE_PLUS_WEIGHT_RESULTS = [
334
- 0,
335
- 5,
336
- 1,
337
- 6,
338
- 2,
339
- 7,
340
- 3,
341
- 8,
342
- 4,
343
- 9
344
- ];
345
- var FIVE_MINUS_WEIGHT_RESULTS = [
346
- 0,
347
- 5,
348
- 9,
349
- 4,
350
- 8,
351
- 3,
352
- 7,
353
- 2,
354
- 6,
355
- 1
356
- ];
357
- var INVERSE_FIVE_MINUS_WEIGHT_RESULTS = [
358
- 0,
359
- 9,
360
- 7,
361
- 5,
362
- 3,
363
- 1,
364
- 8,
365
- 6,
366
- 4,
367
- 2
368
- ];
369
- function checkDigitSum(exchangeWeights, s) {
370
- let weight3 = (s.length + Number(exchangeWeights)) % 2 === 0;
371
- return import_utility3.NUMERIC_CREATOR.characterIndexes(s).reduce((accumulator, characterIndex, index) => {
372
- if (characterIndex === void 0) {
373
- throw new RangeError(i18nextGS1.t("CharacterSetValidator.invalidCharacterAtPosition", {
374
- ns: import_utility3.utilityNS,
375
- c: s.charAt(index),
376
- position: index + 1
377
- }));
378
- }
379
- weight3 = !weight3;
380
- return accumulator + (weight3 ? THREE_WEIGHT_RESULTS[characterIndex] : characterIndex);
381
- }, 0);
382
- }
383
- function checkDigit(s) {
384
- return import_utility3.NUMERIC_CREATOR.character(9 - (checkDigitSum(false, s) + 9) % 10);
385
- }
386
- function hasValidCheckDigit(s) {
387
- return checkDigitSum(true, s) % 10 === 0;
388
- }
389
- function priceWeightSum(weightsResults, s) {
390
- if (s.length !== weightsResults.length) {
391
- throw new RangeError(i18nextGS1.t("Check.lengthOfStringForPriceOrWeightMustBeExactly", {
392
- length: s.length,
393
- exactLength: weightsResults.length
394
- }));
395
- }
396
- const characterIndexes = import_utility3.NUMERIC_CREATOR.characterIndexes(s);
397
- return characterIndexes.reduce((accumulator, characterIndex, index) => {
398
- if (characterIndex === void 0) {
399
- throw new RangeError(i18nextGS1.t("CharacterSetValidator.invalidCharacterAtPositionOfComponent", {
400
- ns: import_utility3.utilityNS,
401
- c: s.charAt(index),
402
- position: index + 1,
403
- component: i18nextGS1.t("Check.priceOrWeightComponent")
404
- }));
405
- }
406
- return accumulator + weightsResults[index][characterIndex];
407
- }, 0);
408
- }
409
- function fourDigitPriceWeightCheckDigit(s) {
410
- return import_utility3.NUMERIC_CREATOR.character(priceWeightSum([TWO_MINUS_WEIGHT_RESULTS, TWO_MINUS_WEIGHT_RESULTS, THREE_WEIGHT_RESULTS, FIVE_MINUS_WEIGHT_RESULTS], s) * 3 % 10);
411
- }
412
- function fiveDigitPriceWeightCheckDigit(s) {
413
- return import_utility3.NUMERIC_CREATOR.character(INVERSE_FIVE_MINUS_WEIGHT_RESULTS[9 - (priceWeightSum([FIVE_PLUS_WEIGHT_RESULTS, TWO_MINUS_WEIGHT_RESULTS, FIVE_MINUS_WEIGHT_RESULTS, FIVE_PLUS_WEIGHT_RESULTS, TWO_MINUS_WEIGHT_RESULTS], s) + 9) % 10]);
414
- }
415
- var CHECK_CHARACTER_WEIGHTS = [
416
- 107,
417
- 103,
418
- 101,
419
- 97,
420
- 89,
421
- 83,
422
- 79,
423
- 73,
424
- 71,
425
- 67,
426
- 61,
427
- 59,
428
- 53,
429
- 47,
430
- 43,
431
- 41,
432
- 37,
433
- 31,
434
- 29,
435
- 23,
436
- 19,
437
- 17,
438
- 13,
439
- 11,
440
- 7,
441
- 5,
442
- 3,
443
- 2
444
- ];
445
- var CHECK_CHARACTERS = [
446
- "2",
447
- "3",
448
- "4",
449
- "5",
450
- "6",
451
- "7",
452
- "8",
453
- "9",
454
- "A",
455
- "B",
456
- "C",
457
- "D",
458
- "E",
459
- "F",
460
- "G",
461
- "H",
462
- "J",
463
- "K",
464
- "L",
465
- "M",
466
- "N",
467
- "P",
468
- "Q",
469
- "R",
470
- "S",
471
- "T",
472
- "U",
473
- "V",
474
- "W",
475
- "X",
476
- "Y",
477
- "Z"
478
- ];
479
- function checkCharacterPair(s) {
480
- const weightIndexStart = CHECK_CHARACTER_WEIGHTS.length - s.length;
481
- if (weightIndexStart < 0) {
482
- throw new RangeError(i18nextGS1.t("Check.lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo", {
483
- length: s.length,
484
- maximumLength: CHECK_CHARACTER_WEIGHTS.length
485
- }));
486
- }
487
- const checkCharacterPairSum = AI82_CREATOR.characterIndexes(s).reduce((accumulator, characterIndex, index) => {
488
- if (characterIndex === void 0) {
489
- throw new RangeError(i18nextGS1.t("CharacterSetValidator.invalidCharacterAtPosition", {
490
- ns: import_utility3.utilityNS,
491
- c: s.charAt(index),
492
- position: index + 1
493
- }));
494
- }
495
- return accumulator + characterIndex * CHECK_CHARACTER_WEIGHTS[weightIndexStart + index];
496
- }, 0) % 1021;
497
- const checkCharacterPairSumMod32 = checkCharacterPairSum % 32;
498
- return CHECK_CHARACTERS[(checkCharacterPairSum - checkCharacterPairSumMod32) / 32] + CHECK_CHARACTERS[checkCharacterPairSumMod32];
499
- }
500
- function hasValidCheckCharacterPair(s) {
501
- const checkCharacterPairIndex = s.length - 2;
502
- return checkCharacterPair(s.substring(0, checkCharacterPairIndex)) === s.substring(checkCharacterPairIndex);
503
- }
504
-
505
- // src/idkey.ts
506
- var import_utility4 = require("@aidc-toolkit/utility");
507
- var import_ts_mixer = require("ts-mixer");
508
- var IdentificationKeyType = /* @__PURE__ */ ((IdentificationKeyType2) => {
509
- IdentificationKeyType2["GTIN"] = "GTIN";
510
- IdentificationKeyType2["GLN"] = "GLN";
511
- IdentificationKeyType2["SSCC"] = "SSCC";
512
- IdentificationKeyType2["GRAI"] = "GRAI";
513
- IdentificationKeyType2["GIAI"] = "GIAI";
514
- IdentificationKeyType2["GSRN"] = "GSRN";
515
- IdentificationKeyType2["GDTI"] = "GDTI";
516
- IdentificationKeyType2["GINC"] = "GINC";
517
- IdentificationKeyType2["GSIN"] = "GSIN";
518
- IdentificationKeyType2["GCN"] = "GCN";
519
- IdentificationKeyType2["CPID"] = "CPID";
520
- IdentificationKeyType2["GMN"] = "GMN";
521
- return IdentificationKeyType2;
522
- })(IdentificationKeyType || {});
523
- var PrefixType = /* @__PURE__ */ ((PrefixType2) => {
524
- PrefixType2[PrefixType2["GS1CompanyPrefix"] = 0] = "GS1CompanyPrefix";
525
- PrefixType2[PrefixType2["UPCCompanyPrefix"] = 1] = "UPCCompanyPrefix";
526
- PrefixType2[PrefixType2["GS18Prefix"] = 2] = "GS18Prefix";
527
- return PrefixType2;
528
- })(PrefixType || {});
529
- var ContentCharacterSet = /* @__PURE__ */ ((ContentCharacterSet2) => {
530
- ContentCharacterSet2[ContentCharacterSet2["Numeric"] = 0] = "Numeric";
531
- ContentCharacterSet2[ContentCharacterSet2["AI82"] = 1] = "AI82";
532
- ContentCharacterSet2[ContentCharacterSet2["AI39"] = 2] = "AI39";
533
- return ContentCharacterSet2;
534
- })(ContentCharacterSet || {});
535
- var AbstractIdentificationKeyValidator = class _AbstractIdentificationKeyValidator {
536
- static CHARACTER_SET_CREATORS = [
537
- import_utility4.NUMERIC_CREATOR,
538
- AI82_CREATOR,
539
- AI39_CREATOR
540
- ];
541
- /**
542
- * Identification key type.
543
- */
544
- _identificationKeyType;
545
- /**
546
- * Prefix type.
547
- */
548
- _prefixType;
549
- /**
550
- * Length.
551
- */
552
- _length;
553
- /**
554
- * Reference character set.
555
- */
556
- _referenceCharacterSet;
557
- /**
558
- * Reference creator.
559
- */
560
- _referenceCreator;
561
- /**
562
- * Get the character set creator for a character set.
563
- *
564
- * @param characterSet
565
- * Character set.
566
- *
567
- * @returns
568
- * Character set creator.
569
- */
570
- static creatorFor(characterSet) {
571
- return _AbstractIdentificationKeyValidator.CHARACTER_SET_CREATORS[characterSet];
572
- }
573
- /**
574
- * Constructor.
575
- *
576
- * @param identificationKeyType
577
- * Identification key type.
578
- *
579
- * @param prefixType
580
- * Prefix type.
581
- *
582
- * @param length
583
- * Length.
584
- *
585
- * @param referenceCharacterSet
586
- * Reference character set.
587
- */
588
- constructor(identificationKeyType, prefixType, length, referenceCharacterSet) {
589
- this._identificationKeyType = identificationKeyType;
590
- this._prefixType = prefixType;
591
- this._length = length;
592
- this._referenceCharacterSet = referenceCharacterSet;
593
- this._referenceCreator = _AbstractIdentificationKeyValidator.creatorFor(referenceCharacterSet);
594
- }
595
- /**
596
- * @inheritDoc
597
- */
598
- get identificationKeyType() {
599
- return this._identificationKeyType;
600
- }
601
- /**
602
- * @inheritDoc
603
- */
604
- get prefixType() {
605
- return this._prefixType;
606
- }
607
- /**
608
- * @inheritDoc
609
- */
610
- get length() {
611
- return this._length;
612
- }
613
- /**
614
- * @inheritDoc
615
- */
616
- get referenceCharacterSet() {
617
- return this._referenceCharacterSet;
618
- }
619
- /**
620
- * @inheritDoc
621
- */
622
- get referenceCreator() {
623
- return this._referenceCreator;
624
- }
625
- /**
626
- * Pad an identification key on the left with zero-value character for validation purposes. This is done to align an
627
- * identification key with a position offset for any error message that may be thrown by the reference validator.
628
- *
629
- * @param identificationKey
630
- * Identification key.
631
- *
632
- * @param validation
633
- * Identification key validation parameters.
634
- *
635
- * @returns
636
- * Padded identification key.
637
- */
638
- padIdentificationKey(identificationKey, validation) {
639
- return validation?.positionOffset === void 0 ? identificationKey : this.referenceCreator.character(0).repeat(validation.positionOffset).concat(identificationKey);
640
- }
641
- /**
642
- * Validate the prefix within an identification key.
643
- *
644
- * @param partialIdentificationKey
645
- * Partial identification key.
646
- *
647
- * @param positionOffset
648
- * Position offset within a larger string.
649
- */
650
- validatePrefix(partialIdentificationKey, positionOffset) {
651
- PrefixManager.validatePrefix(this.prefixType, true, false, partialIdentificationKey, true, this.referenceCharacterSet === 0 /* Numeric */, positionOffset);
652
- }
653
- };
654
- var LeaderType = /* @__PURE__ */ ((LeaderType2) => {
655
- LeaderType2[LeaderType2["None"] = 0] = "None";
656
- LeaderType2[LeaderType2["IndicatorDigit"] = 1] = "IndicatorDigit";
657
- LeaderType2[LeaderType2["ExtensionDigit"] = 2] = "ExtensionDigit";
658
- return LeaderType2;
659
- })(LeaderType || {});
660
- var AbstractNumericIdentificationKeyValidator = class extends AbstractIdentificationKeyValidator {
661
- /**
662
- * Leader type.
663
- */
664
- _leaderType;
665
- /**
666
- * Prefix position, determined by the leader type.
667
- */
668
- _prefixPosition;
669
- /**
670
- * Constructor.
671
- *
672
- * @param identificationKeyType
673
- * Identification key type.
674
- *
675
- * @param prefixType
676
- * Prefix type.
677
- *
678
- * @param length
679
- * Length.
680
- *
681
- * @param leaderType
682
- * Leader type.
683
- */
684
- constructor(identificationKeyType, prefixType, length, leaderType) {
685
- super(identificationKeyType, prefixType, length, 0 /* Numeric */);
686
- this._leaderType = leaderType;
687
- this._prefixPosition = Number(this.leaderType === 2 /* ExtensionDigit */);
688
- }
689
- /**
690
- * @inheritDoc
691
- */
692
- get leaderType() {
693
- return this._leaderType;
694
- }
695
- /**
696
- * @inheritDoc
697
- */
698
- validate(identificationKey, validation) {
699
- if (this._prefixPosition === 0) {
700
- super.validatePrefix(identificationKey, validation?.positionOffset);
701
- } else {
702
- super.validatePrefix(identificationKey.substring(this._prefixPosition), validation?.positionOffset === void 0 ? this._prefixPosition : validation.positionOffset + this._prefixPosition);
703
- }
704
- if (identificationKey.length !== this.length) {
705
- throw new RangeError(i18nextGS1.t("IdentificationKey.identificationKeyTypeLength", {
706
- identificationKeyType: this.identificationKeyType,
707
- length: this.length
708
- }));
709
- }
710
- if (!hasValidCheckDigit(this.padIdentificationKey(identificationKey, validation))) {
711
- throw new RangeError(i18nextGS1.t("IdentificationKey.invalidCheckDigit"));
712
- }
713
- }
714
- };
715
- var GTINType = /* @__PURE__ */ ((GTINType2) => {
716
- GTINType2[GTINType2["GTIN13"] = 13] = "GTIN13";
717
- GTINType2[GTINType2["GTIN12"] = 12] = "GTIN12";
718
- GTINType2[GTINType2["GTIN8"] = 8] = "GTIN8";
719
- GTINType2[GTINType2["GTIN14"] = 14] = "GTIN14";
720
- return GTINType2;
721
- })(GTINType || {});
722
- var GTINLevel = /* @__PURE__ */ ((GTINLevel2) => {
723
- GTINLevel2[GTINLevel2["Any"] = 0] = "Any";
724
- GTINLevel2[GTINLevel2["RetailConsumer"] = 1] = "RetailConsumer";
725
- GTINLevel2[GTINLevel2["OtherThanRetailConsumer"] = 2] = "OtherThanRetailConsumer";
726
- return GTINLevel2;
727
- })(GTINLevel || {});
728
- var GTINValidator = class _GTINValidator extends AbstractNumericIdentificationKeyValidator {
729
- /**
730
- * Validation parameters for optional indicator digit.
731
- */
732
- static OPTIONAL_INDICATOR_DIGIT_VALIDATION = {
733
- minimumLength: 0,
734
- maximumLength: 1,
735
- component: () => i18nextGS1.t("IdentificationKey.indicatorDigit")
736
- };
737
- /**
738
- * Validation parameters for zero-suppressed GTIN-12.
739
- */
740
- static ZERO_SUPPRESSED_GTIN12_VALIDATION = {
741
- minimumLength: 8,
742
- maximumLength: 8
743
- };
744
- /**
745
- * Constructor.
746
- *
747
- * @param gtinType
748
- * GTIN type.
749
- */
750
- constructor(gtinType) {
751
- let prefixType;
752
- switch (gtinType) {
753
- case 13 /* GTIN13 */:
754
- prefixType = 0 /* GS1CompanyPrefix */;
755
- break;
756
- case 12 /* GTIN12 */:
757
- prefixType = 1 /* UPCCompanyPrefix */;
758
- break;
759
- case 8 /* GTIN8 */:
760
- prefixType = 2 /* GS18Prefix */;
761
- break;
762
- default:
763
- throw new Error("Not supported");
764
- }
765
- super("GTIN" /* GTIN */, prefixType, gtinType, 1 /* IndicatorDigit */);
766
- }
767
- /**
768
- * @inheritDoc
769
- */
770
- get gtinType() {
771
- return this.length;
772
- }
773
- /**
774
- * @inheritDoc
775
- */
776
- validatePrefix(partialIdentificationKey, positionOffset) {
777
- PrefixManager.validatePrefix(this.prefixType, false, false, partialIdentificationKey, true, true, positionOffset);
778
- }
779
- /**
780
- * Zero suppress a GTIN-12.
781
- *
782
- * @param gtin12
783
- * GTIN-12.
784
- *
785
- * @returns
786
- * Zero-suppressed GTIN-12.
787
- */
788
- static zeroSuppress(gtin12) {
789
- GTIN12_VALIDATOR.validate(gtin12);
790
- const d = Array.from(gtin12);
791
- let zeroSuppressedGTIN12;
792
- if (d[0] === "0" && d[6] === "0" && d[7] === "0") {
793
- if (d[10] >= "5" && d[8] === "0" && d[9] === "0" && d[5] !== "0") {
794
- zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[3]}${d[4]}${d[5]}${d[10]}${d[11]}`;
795
- } else if (d[5] === "0" && d[8] === "0" && d[9] === "0" && d[4] !== "0") {
796
- zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[3]}${d[4]}${d[10]}4${d[11]}`;
797
- } else if (d[3] <= "2" && d[4] === "0" && d[5] === "0") {
798
- zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[8]}${d[9]}${d[10]}${d[3]}${d[11]}`;
799
- } else if (d[3] >= "3" && d[4] === "0" && d[5] === "0" && d[8] === "0") {
800
- zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[3]}${d[9]}${d[10]}3${d[11]}`;
801
- }
802
- }
803
- if (zeroSuppressedGTIN12 === void 0) {
804
- throw new RangeError(i18nextGS1.t("IdentificationKey.invalidZeroSuppressibleGTIN12"));
805
- }
806
- return zeroSuppressedGTIN12;
807
- }
808
- /**
809
- * Zero expand a zero-suppressed GTIN-12.
810
- *
811
- * @param zeroSuppressedGTIN12
812
- * Zero-suppressed GTIN-12.
813
- *
814
- * @returns
815
- * GTIN-12.
816
- */
817
- static zeroExpand(zeroSuppressedGTIN12) {
818
- import_utility4.NUMERIC_CREATOR.validate(zeroSuppressedGTIN12, _GTINValidator.ZERO_SUPPRESSED_GTIN12_VALIDATION);
819
- const d = Array.from(zeroSuppressedGTIN12);
820
- let gtin12;
821
- if (d[0] === "0") {
822
- if (d[6] >= "5" && d[5] !== "0") {
823
- gtin12 = `0${d[1]}${d[2]}${d[3]}${d[4]}${d[5]}0000${d[6]}${d[7]}`;
824
- } else if (d[6] === "4" && d[4] !== "0") {
825
- gtin12 = `0${d[1]}${d[2]}${d[3]}${d[4]}00000${d[5]}${d[7]}`;
826
- } else if (d[6] <= "2") {
827
- gtin12 = `0${d[1]}${d[2]}${d[6]}0000${d[3]}${d[4]}${d[5]}${d[7]}`;
828
- } else if (d[6] === "3" && d[3] >= "3") {
829
- gtin12 = `0${d[1]}${d[2]}${d[3]}00000${d[4]}${d[5]}${d[7]}`;
830
- }
831
- }
832
- if (gtin12 === void 0) {
833
- throw new RangeError(i18nextGS1.t("IdentificationKey.invalidZeroSuppressedGTIN12"));
834
- }
835
- GTIN12_VALIDATOR.validate(gtin12);
836
- return gtin12;
837
- }
838
- /**
839
- * Convert a GTIN of any length to a GTIN-14 with an optional indicator digit.
840
- *
841
- * @param indicatorDigit
842
- * Indicator digit. If blank, assumes "0" if the GTIN is not already a GTIN-14.
843
- *
844
- * @param gtin
845
- * GTIN.
846
- *
847
- * @returns
848
- * GTIN-14.
849
- */
850
- static convertToGTIN14(indicatorDigit, gtin) {
851
- GTINCreator.validateAny(gtin);
852
- import_utility4.NUMERIC_CREATOR.validate(indicatorDigit, _GTINValidator.OPTIONAL_INDICATOR_DIGIT_VALIDATION);
853
- const gtinLength = gtin.length;
854
- let gtin14 = "0".repeat(14 /* GTIN14 */ - gtinLength) + gtin;
855
- if (indicatorDigit.length !== 0 && indicatorDigit !== gtin14.charAt(0)) {
856
- const partialGTIN14 = indicatorDigit + gtin14.substring(1, 14 /* GTIN14 */ - 1);
857
- gtin14 = partialGTIN14 + checkDigit(partialGTIN14);
858
- }
859
- return gtin14;
860
- }
861
- /**
862
- * Normalize a GTIN of any length.
863
- * - A GTIN-14 that starts with six zeros or a GTIN-13 that starts with five zeros is normalized to GTIN-8.
864
- * - A GTIN-14 that starts with two zeros or a GTIN-13 that starts with one zero is normalized to GTIN-12.
865
- * - A GTIN-14 that starts with one zero is normalized to GTIN-13.
866
- * - Otherwise, the GTIN is unchanged.
867
- *
868
- * @param gtin
869
- * GTIN.
870
- *
871
- * @returns
872
- * Normalized GTIN.
873
- */
874
- static normalize(gtin) {
875
- const gtinLength = gtin.length;
876
- let normalizedGTIN;
877
- switch (gtinLength) {
878
- case 13 /* GTIN13 */:
879
- if (!gtin.startsWith("0")) {
880
- normalizedGTIN = gtin;
881
- } else if (!gtin.startsWith("00000")) {
882
- normalizedGTIN = gtin.substring(1);
883
- } else if (!gtin.startsWith("000000")) {
884
- normalizedGTIN = gtin.substring(5);
885
- } else {
886
- throw new RangeError(i18nextGS1.t("IdentificationKey.invalidZeroSuppressedGTIN12AsGTIN13"));
887
- }
888
- break;
889
- case 12 /* GTIN12 */:
890
- normalizedGTIN = gtin;
891
- break;
892
- case 8 /* GTIN8 */:
893
- if (!gtin.startsWith("0")) {
894
- normalizedGTIN = gtin;
895
- } else {
896
- normalizedGTIN = _GTINValidator.zeroExpand(gtin);
897
- }
898
- break;
899
- case 14 /* GTIN14 */:
900
- if (!gtin.startsWith("0")) {
901
- normalizedGTIN = gtin;
902
- } else if (!gtin.startsWith("00")) {
903
- normalizedGTIN = gtin.substring(1);
904
- } else if (!gtin.startsWith("000000")) {
905
- normalizedGTIN = gtin.substring(2);
906
- } else if (!gtin.startsWith("0000000")) {
907
- normalizedGTIN = gtin.substring(6);
908
- } else {
909
- throw new RangeError(i18nextGS1.t("IdentificationKey.invalidZeroSuppressedGTIN12AsGTIN14"));
910
- }
911
- break;
912
- default:
913
- throw new RangeError(i18nextGS1.t("IdentificationKey.invalidGTINLength"));
914
- }
915
- GTINCreator.validateAny(normalizedGTIN);
916
- return normalizedGTIN;
917
- }
918
- /**
919
- * Validate any GTIN, optionally against a level.
920
- *
921
- * @param gtin
922
- * GTIN.
923
- *
924
- * @param gtinLevel
925
- * Level at which GTIN is to be validated.
926
- */
927
- static validateAny(gtin, gtinLevel = 0 /* Any */) {
928
- let lengthValidatedGTIN = gtin;
929
- let gtinLevelRestriction;
930
- switch (gtin.length) {
931
- case 13 /* GTIN13 */:
932
- if (gtin.startsWith("0")) {
933
- throw new RangeError(i18nextGS1.t("IdentificationKey.invalidGTIN13AtRetail"));
934
- }
935
- PrefixManager.validatePrefix(0 /* GS1CompanyPrefix */, false, false, gtin, true, true);
936
- gtinLevelRestriction = 0 /* Any */;
937
- break;
938
- case 12 /* GTIN12 */:
939
- PrefixManager.validatePrefix(1 /* UPCCompanyPrefix */, false, false, gtin, true, true);
940
- gtinLevelRestriction = 0 /* Any */;
941
- break;
942
- case 8 /* GTIN8 */:
943
- if (!gtin.startsWith("0")) {
944
- PrefixManager.validatePrefix(2 /* GS18Prefix */, false, false, gtin, true, true);
945
- } else {
946
- lengthValidatedGTIN = _GTINValidator.zeroExpand(gtin);
947
- }
948
- gtinLevelRestriction = 1 /* RetailConsumer */;
949
- break;
950
- case 14 /* GTIN14 */:
951
- PrefixManager.validatePrefix(0 /* GS1CompanyPrefix */, true, true, gtin.substring(1), true, true);
952
- gtinLevelRestriction = 2 /* OtherThanRetailConsumer */;
953
- break;
954
- default:
955
- throw new RangeError(i18nextGS1.t("IdentificationKey.invalidGTINLength"));
956
- }
957
- if (!hasValidCheckDigit(lengthValidatedGTIN)) {
958
- throw new RangeError(i18nextGS1.t("IdentificationKey.invalidCheckDigit"));
959
- }
960
- if (gtinLevel !== 0 /* Any */ && gtinLevelRestriction !== 0 /* Any */ && gtinLevelRestriction !== gtinLevel) {
961
- throw new RangeError(i18nextGS1.t(gtinLevel === 1 /* RetailConsumer */ ? "IdentificationKey.invalidGTINAtRetail" : "IdentificationKey.invalidGTINAtOtherThanRetail"));
962
- }
963
- }
964
- /**
965
- * Validate a GTIN-14.
966
- *
967
- * @param gtin14
968
- * GTIN-14.
969
- */
970
- static validateGTIN14(gtin14) {
971
- if (gtin14.length !== 14 /* GTIN14 */) {
972
- throw new RangeError(i18nextGS1.t("IdentificationKey.invalidGTIN14Length"));
973
- }
974
- GTINCreator.validateAny(gtin14);
975
- }
976
- };
977
- var NonGTINNumericIdentificationKeyValidator = class extends AbstractNumericIdentificationKeyValidator {
978
- /**
979
- * Constructor.
980
- *
981
- * @param identificationKeyType
982
- * Identification key type.
983
- *
984
- * @param length
985
- * Length.
986
- *
987
- * @param leaderType
988
- * Leader type.
989
- */
990
- constructor(identificationKeyType, length, leaderType = 0 /* None */) {
991
- super(identificationKeyType, 0 /* GS1CompanyPrefix */, length, leaderType);
992
- }
993
- };
994
- var SerializableNumericIdentificationKeyValidator = class _SerializableNumericIdentificationKeyValidator extends NonGTINNumericIdentificationKeyValidator {
995
- /**
996
- * Serial component length.
997
- */
998
- _serialComponentLength;
999
- /**
1000
- * Serial component character set.
1001
- */
1002
- _serialComponentCharacterSet;
1003
- /**
1004
- * Serial component validation parameters.
1005
- */
1006
- _serialComponentValidation;
1007
- /**
1008
- * Serial component creator.
1009
- */
1010
- _serialComponentCreator;
1011
- /**
1012
- * Constructor.
1013
- *
1014
- * @param identificationKeyType
1015
- * Identification key type.
1016
- *
1017
- * @param length
1018
- * Length.
1019
- *
1020
- * @param serialComponentLength
1021
- * Serial component length.
1022
- *
1023
- * @param serialComponentCharacterSet
1024
- * Serial component character set.
1025
- */
1026
- constructor(identificationKeyType, length, serialComponentLength, serialComponentCharacterSet) {
1027
- super(identificationKeyType, length, 0 /* None */);
1028
- this._serialComponentLength = serialComponentLength;
1029
- this._serialComponentCharacterSet = serialComponentCharacterSet;
1030
- this._serialComponentValidation = {
1031
- minimumLength: 1,
1032
- maximumLength: serialComponentLength,
1033
- component: () => i18nextGS1.t("IdentificationKey.serialComponent")
1034
- };
1035
- this._serialComponentCreator = _SerializableNumericIdentificationKeyValidator.creatorFor(serialComponentCharacterSet);
1036
- }
1037
- /**
1038
- * Get the serial component length.
1039
- */
1040
- get serialComponentLength() {
1041
- return this._serialComponentLength;
1042
- }
1043
- /**
1044
- * Get the serial component character set.
1045
- */
1046
- get serialComponentCharacterSet() {
1047
- return this._serialComponentCharacterSet;
1048
- }
1049
- /**
1050
- * Get the serial component validation parameters.
1051
- */
1052
- get serialComponentValidation() {
1053
- return this._serialComponentValidation;
1054
- }
1055
- /**
1056
- * Get the serial component creator.
1057
- */
1058
- get serialComponentCreator() {
1059
- return this._serialComponentCreator;
1060
- }
1061
- /**
1062
- * @inheritDoc
1063
- */
1064
- validate(identificationKey, validation) {
1065
- super.validate(identificationKey.substring(0, this.length), validation);
1066
- if (identificationKey.length > this.length) {
1067
- this.serialComponentCreator.validate(identificationKey.substring(this.length), this._serialComponentValidation);
1068
- }
1069
- }
1070
- };
1071
- var NonNumericIdentificationKeyValidator = class _NonNumericIdentificationKeyValidator extends AbstractIdentificationKeyValidator {
1072
- /**
1073
- * Validator to ensure that an identification key (minus check character pair) is not all numeric.
1074
- */
1075
- static NOT_ALL_NUMERIC_VALIDATOR = new class extends import_utility4.RegExpValidator {
1076
- /**
1077
- * @inheritDoc
1078
- */
1079
- createErrorMessage(_s) {
1080
- return i18nextGS1.t("IdentificationKey.referenceCantBeAllNumeric");
1081
- }
1082
- }(/\D/);
1083
- /**
1084
- * True if the identification key requires a check character pair.
1085
- */
1086
- _requiresCheckCharacterPair;
1087
- /**
1088
- * Constructor.
1089
- *
1090
- * @param identificationKeyType
1091
- * Identification key type.
1092
- *
1093
- * @param length
1094
- * Length.
1095
- *
1096
- * @param referenceCharacterSet
1097
- * Reference character set.
1098
- *
1099
- * @param requiresCheckCharacterPair
1100
- * True if the identification key requires a check character pair.
1101
- */
1102
- constructor(identificationKeyType, length, referenceCharacterSet, requiresCheckCharacterPair = false) {
1103
- super(identificationKeyType, 0 /* GS1CompanyPrefix */, length, referenceCharacterSet);
1104
- this._requiresCheckCharacterPair = requiresCheckCharacterPair;
1105
- }
1106
- /**
1107
- * Determine if the identification key requires a check character pair.
1108
- */
1109
- get requiresCheckCharacterPair() {
1110
- return this._requiresCheckCharacterPair;
1111
- }
1112
- /**
1113
- * Validate a non-numeric identification key and throw an error if validation fails.
1114
- *
1115
- * @param identificationKey
1116
- * Identification key.
1117
- *
1118
- * @param validation
1119
- * Validation parameters.
1120
- */
1121
- validate(identificationKey, validation) {
1122
- const partialIdentificationKey = this.requiresCheckCharacterPair ? identificationKey.substring(0, identificationKey.length - 2) : identificationKey;
1123
- super.validatePrefix(partialIdentificationKey, validation?.positionOffset);
1124
- if (!this.requiresCheckCharacterPair) {
1125
- this.referenceCreator.validate(identificationKey, {
1126
- maximumLength: this.length,
1127
- positionOffset: validation?.positionOffset
1128
- });
1129
- } else if (!hasValidCheckCharacterPair(this.padIdentificationKey(identificationKey, validation))) {
1130
- throw new RangeError(i18nextGS1.t("IdentificationKey.invalidCheckCharacterPair"));
1131
- }
1132
- if (validation?.exclusion === import_utility4.Exclusion.AllNumeric) {
1133
- _NonNumericIdentificationKeyValidator.NOT_ALL_NUMERIC_VALIDATOR.validate(partialIdentificationKey);
1134
- }
1135
- }
1136
- };
1137
- var GTIN13_VALIDATOR = new GTINValidator(13 /* GTIN13 */);
1138
- var GTIN12_VALIDATOR = new GTINValidator(12 /* GTIN12 */);
1139
- var GTIN8_VALIDATOR = new GTINValidator(8 /* GTIN8 */);
1140
- var GTIN_VALIDATORS = [
1141
- GTIN13_VALIDATOR,
1142
- GTIN12_VALIDATOR,
1143
- GTIN8_VALIDATOR
1144
- ];
1145
- var GLN_VALIDATOR = new NonGTINNumericIdentificationKeyValidator("GLN" /* GLN */, 13);
1146
- var SSCC_VALIDATOR = new NonGTINNumericIdentificationKeyValidator("SSCC" /* SSCC */, 18, 2 /* ExtensionDigit */);
1147
- var GRAI_VALIDATOR = new SerializableNumericIdentificationKeyValidator("GRAI" /* GRAI */, 13, 16, 1 /* AI82 */);
1148
- var GIAI_VALIDATOR = new NonNumericIdentificationKeyValidator("GIAI" /* GIAI */, 30, 1 /* AI82 */);
1149
- var GSRN_VALIDATOR = new NonGTINNumericIdentificationKeyValidator("GSRN" /* GSRN */, 18);
1150
- var GDTI_VALIDATOR = new SerializableNumericIdentificationKeyValidator("GDTI" /* GDTI */, 13, 17, 1 /* AI82 */);
1151
- var GINC_VALIDATOR = new NonNumericIdentificationKeyValidator("GINC" /* GINC */, 30, 1 /* AI82 */);
1152
- var GSIN_VALIDATOR = new NonGTINNumericIdentificationKeyValidator("GSIN" /* GSIN */, 17);
1153
- var GCN_VALIDATOR = new SerializableNumericIdentificationKeyValidator("GCN" /* GCN */, 13, 12, 0 /* Numeric */);
1154
- var CPID_VALIDATOR = new NonNumericIdentificationKeyValidator("CPID" /* CPID */, 30, 2 /* AI39 */);
1155
- var GMN_VALIDATOR = new NonNumericIdentificationKeyValidator("GMN" /* GMN */, 25, 1 /* AI82 */, true);
1156
- var AbstractIdentificationKeyCreator = class {
1157
- /**
1158
- * Prefix manager.
1159
- */
1160
- _prefixManager;
1161
- /**
1162
- * Reference length.
1163
- */
1164
- _referenceLength;
1165
- /**
1166
- * Initialize the prefix manager. This method is in lieu of a constructor due to the mixin architecture.
1167
- *
1168
- * @param prefixManager
1169
- * Prefix manager.
1170
- *
1171
- * @param prefix
1172
- * Prefix within prefix manager to use to calculate reference length.
1173
- *
1174
- * @param checkAllowance
1175
- * Number of characters to allow for check digit or check character pair.
1176
- */
1177
- init(prefixManager, prefix, checkAllowance) {
1178
- this._prefixManager = prefixManager;
1179
- this._referenceLength = this.length - prefix.length - checkAllowance;
1180
- }
1181
- /**
1182
- * @inheritDoc
1183
- */
1184
- get prefixManager() {
1185
- return this._prefixManager;
1186
- }
1187
- /**
1188
- * @inheritDoc
1189
- */
1190
- get prefix() {
1191
- return this.prefixManager.gs1CompanyPrefix;
1192
- }
1193
- /**
1194
- * @inheritDoc
1195
- */
1196
- get referenceLength() {
1197
- return this._referenceLength;
1198
- }
1199
- };
1200
- var AbstractNumericIdentificationKeyCreator = class _AbstractNumericIdentificationKeyCreator extends AbstractIdentificationKeyCreator {
1201
- /**
1202
- * Capacity.
1203
- */
1204
- _capacity;
1205
- /**
1206
- * Tweak for sparse creation.
1207
- */
1208
- _tweak = 0n;
1209
- /**
1210
- * Initialize the prefix manager. This method is in lieu of a constructor due to the mixin architecture.
1211
- *
1212
- * @param prefixManager
1213
- * Prefix manager.
1214
- *
1215
- * @param prefix
1216
- * Prefix within prefix manager to use to calculate reference length.
1217
- */
1218
- init(prefixManager, prefix) {
1219
- super.init(prefixManager, prefix, 1);
1220
- this._capacity = Number(import_utility4.CharacterSetCreator.powerOf10(this.referenceLength));
1221
- }
1222
- /**
1223
- * @inheritDoc
1224
- */
1225
- get capacity() {
1226
- return this._capacity;
1227
- }
1228
- /**
1229
- * Get the tweak for sparse creation.
1230
- */
1231
- get tweak() {
1232
- return this._tweak;
1233
- }
1234
- /**
1235
- * Set the tweak for sparse creation.
1236
- */
1237
- set tweak(value) {
1238
- this._tweak = value;
1239
- }
1240
- /**
1241
- * Build an identification key from a reference by merging it with the prefix and adding the check digit.
1242
- *
1243
- * @param reference
1244
- * Identification key reference.
1245
- *
1246
- * @returns
1247
- * Identification key.
1248
- */
1249
- buildIdentificationKey(reference) {
1250
- const partialIdentificationKey = this.leaderType === 2 /* ExtensionDigit */ ? reference.substring(0, 1) + this.prefix + reference.substring(1) : this.prefix + reference;
1251
- return partialIdentificationKey + checkDigit(partialIdentificationKey);
1252
- }
1253
- /**
1254
- * @inheritDoc
1255
- */
1256
- create(valueOrValues, sparse = false) {
1257
- return import_utility4.NUMERIC_CREATOR.create(this.referenceLength, valueOrValues, import_utility4.Exclusion.None, sparse ? this.tweak : void 0, (reference) => this.buildIdentificationKey(reference));
1258
- }
1259
- /**
1260
- * Create all identification keys from a partial identification key. Call is recursive until remaining reference
1261
- * length is 0.
1262
- *
1263
- * @param partialIdentificationKey
1264
- * Partial identification key. Initial value is `this.prefix`.
1265
- *
1266
- * @param remainingReferenceLength
1267
- * Remaining reference length. Initial value is `this.referenceLength`.
1268
- *
1269
- * @param extensionWeight
1270
- * If this value is not zero, the identification key has an extension digit, this call is setting it, and this value
1271
- * is applied to the calculation of the check digit.
1272
- *
1273
- * @param weight
1274
- * If the extension weight is zero, this value is applied to the calculation of the check digit.
1275
- *
1276
- * @param partialCheckDigitSum
1277
- * Partial check digit sum for the partial identification key.
1278
- *
1279
- * @yields
1280
- * Identification key.
1281
- */
1282
- static *createAllPartial(partialIdentificationKey, remainingReferenceLength, extensionWeight, weight, partialCheckDigitSum) {
1283
- if (remainingReferenceLength === 0) {
1284
- yield partialIdentificationKey + import_utility4.NUMERIC_CREATOR.character(9 - (partialCheckDigitSum + 9) % 10);
1285
- } else {
1286
- const nextRemainingReferenceLength = remainingReferenceLength - 1;
1287
- let nextPartialCheckDigitSum = partialCheckDigitSum;
1288
- if (extensionWeight !== 0) {
1289
- for (const c of import_utility4.NUMERIC_CREATOR.characterSet) {
1290
- yield* _AbstractNumericIdentificationKeyCreator.createAllPartial(c + partialIdentificationKey, nextRemainingReferenceLength, 0, weight, nextPartialCheckDigitSum);
1291
- nextPartialCheckDigitSum += extensionWeight;
1292
- }
1293
- } else {
1294
- const nextWeight = 4 - weight;
1295
- for (const c of import_utility4.NUMERIC_CREATOR.characterSet) {
1296
- yield* _AbstractNumericIdentificationKeyCreator.createAllPartial(partialIdentificationKey + c, nextRemainingReferenceLength, 0, nextWeight, nextPartialCheckDigitSum);
1297
- nextPartialCheckDigitSum += weight;
1298
- }
1299
- }
1300
- }
1301
- }
1302
- /**
1303
- * @inheritDoc
1304
- */
1305
- createAll() {
1306
- const hasExtensionDigit = this.leaderType === 2 /* ExtensionDigit */;
1307
- const prefix = this.prefix;
1308
- const length = this.length;
1309
- const referenceLength = this.referenceLength;
1310
- const startWeight = 3 - 2 * ((referenceLength + 1 - Number(hasExtensionDigit)) % 2);
1311
- return {
1312
- [Symbol.iterator]() {
1313
- return _AbstractNumericIdentificationKeyCreator.createAllPartial(prefix, referenceLength, hasExtensionDigit ? 3 - 2 * length % 2 : 0, startWeight, checkDigitSum(startWeight === 3, prefix));
1314
- }
1315
- };
1316
- }
1317
- };
1318
- var GTINCreator = class _GTINCreator extends (0, import_ts_mixer.Mixin)(GTINValidator, AbstractNumericIdentificationKeyCreator) {
1319
- /**
1320
- * Validation parameters for required indicator digit.
1321
- */
1322
- static REQUIRED_INDICATOR_DIGIT_VALIDATION = {
1323
- minimumLength: 1,
1324
- maximumLength: 1,
1325
- component: () => i18nextGS1.t("IdentificationKey.indicatorDigit")
1326
- };
1327
- /**
1328
- * Constructor. Called internally by {@link PrefixManager.gtinCreator}; should not be called by other code.
1329
- *
1330
- * @param prefixManager
1331
- * Prefix manager.
1332
- *
1333
- * @param gtinType
1334
- * GTIN type.
1335
- */
1336
- constructor(prefixManager, gtinType) {
1337
- super(gtinType);
1338
- this.init(prefixManager, prefixManager.prefix);
1339
- }
1340
- /**
1341
- * @inheritDoc
1342
- */
1343
- get prefix() {
1344
- return this.prefixManager.prefix;
1345
- }
1346
- /**
1347
- * Create GTIN-14(s) with an indicator digit and reference(s) based on numeric value(s). The value(s) is/are
1348
- * converted to reference(s) of the appropriate length using {@linkcode NUMERIC_CREATOR}.
1349
- *
1350
- * @param indicatorDigit
1351
- * Indicator digit.
1352
- *
1353
- * @param valueOrValues
1354
- * Numeric value(s).
1355
- *
1356
- * @param sparse
1357
- * If true, the value(s) is/are mapped to a sparse sequence resistant to discovery. Default is false.
1358
- *
1359
- * @returns
1360
- * GTIN-14(s).
1361
- */
1362
- createGTIN14(indicatorDigit, valueOrValues, sparse = false) {
1363
- import_utility4.NUMERIC_CREATOR.validate(indicatorDigit, _GTINCreator.REQUIRED_INDICATOR_DIGIT_VALIDATION);
1364
- return import_utility4.NUMERIC_CREATOR.create(13 /* GTIN13 */ - this.prefixManager.gs1CompanyPrefix.length - 1, valueOrValues, import_utility4.Exclusion.None, sparse ? this.tweak : void 0, (reference) => {
1365
- const partialIdentificationKey = indicatorDigit + this.prefixManager.gs1CompanyPrefix + reference;
1366
- return partialIdentificationKey + checkDigit(partialIdentificationKey);
1367
- });
1368
- }
1369
- };
1370
- var NonGTINNumericIdentificationKeyCreator = class extends (0, import_ts_mixer.Mixin)(NonGTINNumericIdentificationKeyValidator, AbstractNumericIdentificationKeyCreator) {
1371
- /**
1372
- * Constructor. Called internally by {@link PrefixManager} non-GTIN numeric identification key creator getters;
1373
- * should not be called by other code.
1374
- *
1375
- * @param prefixManager
1376
- * Prefix manager.
1377
- *
1378
- * @param identificationKeyType
1379
- * Identification key type.
1380
- *
1381
- * @param length
1382
- * Length.
1383
- *
1384
- * @param leaderType
1385
- * Leader type.
1386
- */
1387
- constructor(prefixManager, identificationKeyType, length, leaderType = 0 /* None */) {
1388
- super(identificationKeyType, length, leaderType);
1389
- this.init(prefixManager, prefixManager.gs1CompanyPrefix);
1390
- }
1391
- };
1392
- var SerializableNumericIdentificationKeyCreator = class extends (0, import_ts_mixer.Mixin)(SerializableNumericIdentificationKeyValidator, AbstractNumericIdentificationKeyCreator) {
1393
- /**
1394
- * Constructor. Called internally by {@link PrefixManager} serialized numeric identification key creator getters;
1395
- * should not be called by other code.
1396
- *
1397
- * @param prefixManager
1398
- * Prefix manager.
1399
- *
1400
- * @param identificationKeyType
1401
- * Identification key type.
1402
- *
1403
- * @param length
1404
- * Length.
1405
- *
1406
- * @param serialComponentLength
1407
- * Serial component length.
1408
- *
1409
- * @param serialComponentCharacterSet
1410
- * Serial component character set.
1411
- */
1412
- constructor(prefixManager, identificationKeyType, length, serialComponentLength, serialComponentCharacterSet) {
1413
- super(identificationKeyType, length, serialComponentLength, serialComponentCharacterSet);
1414
- this.init(prefixManager, prefixManager.gs1CompanyPrefix);
1415
- }
1416
- /**
1417
- * Concatenate a validated base identification key with serial component(s).
1418
- *
1419
- * @param baseIdentificationKey
1420
- * Base identification key.
1421
- *
1422
- * @param serialComponentOrComponents
1423
- * Serial component(s).
1424
- *
1425
- * @returns
1426
- * Serialized identification key(s).
1427
- */
1428
- concatenateValidated(baseIdentificationKey, serialComponentOrComponents) {
1429
- let result;
1430
- const serialComponentCreator = this.serialComponentCreator;
1431
- const serialComponentValidation = this.serialComponentValidation;
1432
- function validateAndConcatenate(serialComponent) {
1433
- serialComponentCreator.validate(serialComponent, serialComponentValidation);
1434
- return baseIdentificationKey + serialComponent;
1435
- }
1436
- if (typeof serialComponentOrComponents !== "object") {
1437
- result = validateAndConcatenate(serialComponentOrComponents);
1438
- } else {
1439
- result = (0, import_utility4.transformIterable)(serialComponentOrComponents, validateAndConcatenate);
1440
- }
1441
- return result;
1442
- }
1443
- /**
1444
- * Create serialized identification key(s) with a reference based on a numeric value concatenated with serial
1445
- * component(s). The value is converted to a reference of the appropriate length using {@linkcode NUMERIC_CREATOR}.
1446
- *
1447
- * @param value
1448
- * Numeric value of the reference.
1449
- *
1450
- * @param serialComponentOrComponents
1451
- * Serial component(s).
1452
- *
1453
- * @param sparse
1454
- * If true, the value is mapped to a sparse sequence resistant to discovery. Default is false.
1455
- *
1456
- * @returns
1457
- * Serialized identification keys.
1458
- */
1459
- createSerialized(value, serialComponentOrComponents, sparse) {
1460
- return this.concatenateValidated(this.create(value, sparse), serialComponentOrComponents);
1461
- }
1462
- /**
1463
- * Concatenate a base identification key with serial component(s).
1464
- *
1465
- * @param baseIdentificationKey
1466
- * Base identification key.
1467
- *
1468
- * @param serialComponentOrComponents
1469
- * Serial component(s).
1470
- *
1471
- * @returns
1472
- * Serialized identification key(s).
1473
- */
1474
- concatenate(baseIdentificationKey, serialComponentOrComponents) {
1475
- this.validate(baseIdentificationKey);
1476
- return this.concatenateValidated(baseIdentificationKey, serialComponentOrComponents);
1477
- }
1478
- };
1479
- var NonNumericIdentificationKeyCreator = class extends (0, import_ts_mixer.Mixin)(NonNumericIdentificationKeyValidator, AbstractIdentificationKeyCreator) {
1480
- /**
1481
- * Reference validation parameters.
1482
- */
1483
- _referenceValidation;
1484
- /**
1485
- * Constructor. Called internally by {@link PrefixManager} non-numeric identification key creator getters; should
1486
- * not be called by other code.
1487
- *
1488
- * @param prefixManager
1489
- * Prefix manager.
1490
- *
1491
- * @param identificationKeyType
1492
- * Identification key type.
1493
- *
1494
- * @param length
1495
- * Length.
1496
- *
1497
- * @param referenceCharacterSet
1498
- * Reference character set.
1499
- *
1500
- * @param requiresCheckCharacterPair
1501
- * True if the identification key requires a check character pair.
1502
- */
1503
- constructor(prefixManager, identificationKeyType, length, referenceCharacterSet, requiresCheckCharacterPair = false) {
1504
- super(identificationKeyType, length, referenceCharacterSet, requiresCheckCharacterPair);
1505
- this.init(prefixManager, prefixManager.gs1CompanyPrefix, 2 * Number(requiresCheckCharacterPair));
1506
- this._referenceValidation = {
1507
- minimumLength: 1,
1508
- // Maximum reference length has to account for prefix and check character pair.
1509
- maximumLength: this.referenceLength,
1510
- component: () => i18nextGS1.t("IdentificationKey.reference")
1511
- };
1512
- }
1513
- /**
1514
- * Get the reference validation parameters.
1515
- */
1516
- get referenceValidation() {
1517
- return this._referenceValidation;
1518
- }
1519
- /**
1520
- * Create identification key(s) with reference(s).
1521
- *
1522
- * @param referenceOrReferences
1523
- * Reference(s).
1524
- *
1525
- * @returns
1526
- * Identification key(s).
1527
- */
1528
- create(referenceOrReferences) {
1529
- let result;
1530
- const referenceCreator = this.referenceCreator;
1531
- const referenceValidation = this.referenceValidation;
1532
- const prefix = this.prefix;
1533
- const requiresCheckCharacterPair = this.requiresCheckCharacterPair;
1534
- function validateAndCreate(reference) {
1535
- referenceCreator.validate(reference, referenceValidation);
1536
- const partialIdentificationKey = prefix + reference;
1537
- return requiresCheckCharacterPair ? partialIdentificationKey + checkCharacterPair(partialIdentificationKey) : partialIdentificationKey;
1538
- }
1539
- if (typeof referenceOrReferences !== "object") {
1540
- result = validateAndCreate(referenceOrReferences);
1541
- } else {
1542
- result = (0, import_utility4.transformIterable)(referenceOrReferences, validateAndCreate);
1543
- }
1544
- return result;
1545
- }
1546
- };
1547
- var PrefixManager = class _PrefixManager {
1548
- /**
1549
- * Cached prefix managers, keyed by GS1 Company Prefix.
1550
- */
1551
- static PREFIX_MANAGERS_MAP = /* @__PURE__ */ new Map();
1552
- /**
1553
- * GS1 Company Prefix minimum length.
1554
- */
1555
- static GS1_COMPANY_PREFIX_MINIMUM_LENGTH = 4;
1556
- /**
1557
- * GS1 Company Prefix maximum length.
1558
- */
1559
- static GS1_COMPANY_PREFIX_MAXIMUM_LENGTH = 12;
1560
- /**
1561
- * U.P.C. Company Prefix minimum length.
1562
- */
1563
- static UPC_COMPANY_PREFIX_MINIMUM_LENGTH = 6;
1564
- /**
1565
- * U.P.C. Company Prefix maximum length.
1566
- */
1567
- static UPC_COMPANY_PREFIX_MAXIMUM_LENGTH = 11;
1568
- /**
1569
- * GS1-8 Prefix minimum length.
1570
- */
1571
- static GS1_8_PREFIX_MINIMUM_LENGTH = 2;
1572
- /**
1573
- * GS1-8 Prefix maximum length.
1574
- */
1575
- static GS1_8_PREFIX_MAXIMUM_LENGTH = 7;
1576
- /**
1577
- * Validation parameters for GS1 Company Prefix.
1578
- */
1579
- static GS1_COMPANY_PREFIX_VALIDATION = {
1580
- minimumLength: _PrefixManager.GS1_COMPANY_PREFIX_MINIMUM_LENGTH,
1581
- maximumLength: _PrefixManager.GS1_COMPANY_PREFIX_MAXIMUM_LENGTH,
1582
- component: () => i18nextGS1.t("Prefix.gs1CompanyPrefix")
1583
- };
1584
- /**
1585
- * Validation parameters for U.P.C. Company Prefix expressed as GS1 Company Prefix.
1586
- */
1587
- static UPC_COMPANY_PREFIX_AS_GS1_COMPANY_PREFIX_VALIDATION = {
1588
- minimumLength: _PrefixManager.UPC_COMPANY_PREFIX_MINIMUM_LENGTH + 1,
1589
- maximumLength: _PrefixManager.UPC_COMPANY_PREFIX_MAXIMUM_LENGTH + 1,
1590
- component: () => i18nextGS1.t("Prefix.gs1CompanyPrefix")
1591
- };
1592
- /**
1593
- * Validation parameters for GS1-8 Prefix expressed as GS1 Company Prefix.
1594
- */
1595
- static GS1_8_PREFIX_AS_GS1_COMPANY_PREFIX_VALIDATION = {
1596
- minimumLength: _PrefixManager.GS1_8_PREFIX_MINIMUM_LENGTH + 5,
1597
- maximumLength: _PrefixManager.GS1_8_PREFIX_MAXIMUM_LENGTH + 5,
1598
- component: () => i18nextGS1.t("Prefix.gs1CompanyPrefix")
1599
- };
1600
- /**
1601
- * Validation parameters for U.P.C. Company Prefix.
1602
- */
1603
- static UPC_COMPANY_PREFIX_VALIDATION = {
1604
- minimumLength: _PrefixManager.UPC_COMPANY_PREFIX_MINIMUM_LENGTH,
1605
- maximumLength: _PrefixManager.UPC_COMPANY_PREFIX_MAXIMUM_LENGTH,
1606
- component: () => i18nextGS1.t("Prefix.upcCompanyPrefix")
1607
- };
1608
- /**
1609
- * Validation parameters for GS1-8 Prefix.
1610
- */
1611
- static GS1_8_PREFIX_VALIDATION = {
1612
- minimumLength: _PrefixManager.GS1_8_PREFIX_MINIMUM_LENGTH,
1613
- maximumLength: _PrefixManager.GS1_8_PREFIX_MAXIMUM_LENGTH,
1614
- component: () => i18nextGS1.t("Prefix.gs18Prefix")
1615
- };
1616
- /**
1617
- * Creator tweak factors. Different numeric identification key types have different tweak factors so that sparse
1618
- * creation generates different sequences for each.
1619
- */
1620
- static CREATOR_TWEAK_FACTORS_MAP = /* @__PURE__ */ new Map([
1621
- ["GTIN" /* GTIN */, 1987n],
1622
- ["GLN" /* GLN */, 4241n],
1623
- ["SSCC" /* SSCC */, 8087n],
1624
- ["GRAI" /* GRAI */, 3221n],
1625
- ["GSRN" /* GSRN */, 2341n],
1626
- ["GDTI" /* GDTI */, 7333n],
1627
- ["GSIN" /* GSIN */, 5623n],
1628
- ["GCN" /* GCN */, 6869n]
1629
- ]);
1630
- /**
1631
- * Normalized prefix type.
1632
- */
1633
- _prefixType;
1634
- /**
1635
- * Normalized prefix.
1636
- */
1637
- _prefix;
1638
- /**
1639
- * Prefix as GS1 Company Prefix.
1640
- */
1641
- _gs1CompanyPrefix;
1642
- /**
1643
- * U.P.C. Company Prefix if prefix type is {@link PrefixType.UPCCompanyPrefix}.
1644
- */
1645
- _upcCompanyPrefix;
1646
- /**
1647
- * GS1-8 Prefix if prefix type is {@link PrefixType.GS18Prefix}.
1648
- */
1649
- _gs18Prefix;
1650
- /**
1651
- * Default tweak factor.
1652
- */
1653
- _defaultTweakFactor;
1654
- /**
1655
- * Tweak factor.
1656
- */
1657
- _tweakFactor = 0n;
1658
- /**
1659
- * Cached identification key creators.
1660
- */
1661
- _identificationKeyCreatorsMap = /* @__PURE__ */ new Map();
1662
- /**
1663
- * Constructor.
1664
- *
1665
- * @param gs1CompanyPrefix
1666
- * GS1 Company Prefix.
1667
- */
1668
- constructor(gs1CompanyPrefix) {
1669
- this._gs1CompanyPrefix = gs1CompanyPrefix;
1670
- if (!gs1CompanyPrefix.startsWith("0")) {
1671
- this._prefixType = 0 /* GS1CompanyPrefix */;
1672
- this._prefix = this._gs1CompanyPrefix;
1673
- } else if (!gs1CompanyPrefix.startsWith("00000")) {
1674
- this._prefixType = 1 /* UPCCompanyPrefix */;
1675
- this._upcCompanyPrefix = gs1CompanyPrefix.substring(1);
1676
- this._prefix = this._upcCompanyPrefix;
1677
- } else {
1678
- this._prefixType = 2 /* GS18Prefix */;
1679
- this._gs18Prefix = gs1CompanyPrefix.substring(5);
1680
- this._prefix = this._gs18Prefix;
1681
- }
1682
- this._defaultTweakFactor = BigInt(`1${this.gs1CompanyPrefix}`);
1683
- this.resetTweakFactor();
1684
- }
1685
- /**
1686
- * Get the prefix type.
1687
- */
1688
- get prefixType() {
1689
- return this._prefixType;
1690
- }
1691
- /**
1692
- * Get the prefix.
1693
- */
1694
- get prefix() {
1695
- return this._prefix;
1696
- }
1697
- /**
1698
- * Get the GS1 Company Prefix.
1699
- */
1700
- get gs1CompanyPrefix() {
1701
- return this._gs1CompanyPrefix;
1702
- }
1703
- /**
1704
- * Get the U.P.C. Company Prefix if prefix type is {@link PrefixType.UPCCompanyPrefix} or undefined if not.
1705
- */
1706
- get upcCompanyPrefix() {
1707
- return this._upcCompanyPrefix;
1708
- }
1709
- /**
1710
- * Get the GS1-8 Prefix if prefix type is {@link PrefixType.GS18Prefix} or undefined if not.
1711
- */
1712
- get gs18Prefix() {
1713
- return this._gs18Prefix;
1714
- }
1715
- /**
1716
- * Set the tweak for an identification key creator if it's a numeric identification key creator.
1717
- *
1718
- * @param creator
1719
- * Identification key creator.
1720
- */
1721
- setCreatorTweak(creator) {
1722
- const creatorTweakFactor = _PrefixManager.CREATOR_TWEAK_FACTORS_MAP.get(creator.identificationKeyType);
1723
- if (creatorTweakFactor !== void 0) {
1724
- creator.tweak = this.tweakFactor * creatorTweakFactor;
1725
- }
1726
- }
1727
- /**
1728
- * Get the tweak factor.
1729
- */
1730
- get tweakFactor() {
1731
- return this._tweakFactor;
1732
- }
1733
- /**
1734
- * Set the tweak factor.
1735
- *
1736
- * @param value
1737
- * Tweak factor.
1738
- */
1739
- set tweakFactor(value) {
1740
- const tweakFactor = BigInt(value);
1741
- if (this._tweakFactor !== tweakFactor) {
1742
- this._tweakFactor = tweakFactor;
1743
- for (const creator of this._identificationKeyCreatorsMap.values()) {
1744
- this.setCreatorTweak(creator);
1745
- }
1746
- }
1747
- }
1748
- /**
1749
- * Reset the tweak factor to its default (numeric value of the GS1 Company Prefix preceded by '1').
1750
- */
1751
- resetTweakFactor() {
1752
- this.tweakFactor = this._defaultTweakFactor;
1753
- }
1754
- /**
1755
- * Get a prefix manager.
1756
- *
1757
- * @param prefixType
1758
- * Prefix type.
1759
- *
1760
- * @param prefix
1761
- * Prefix.
1762
- *
1763
- * @returns
1764
- * Prefix manager with normalized prefix type and prefix.
1765
- */
1766
- static get(prefixType, prefix) {
1767
- _PrefixManager.validatePrefix(prefixType, true, true, prefix);
1768
- let gs1CompanyPrefix;
1769
- switch (prefixType) {
1770
- case 0 /* GS1CompanyPrefix */:
1771
- gs1CompanyPrefix = prefix;
1772
- break;
1773
- case 1 /* UPCCompanyPrefix */:
1774
- gs1CompanyPrefix = "0" + prefix;
1775
- break;
1776
- case 2 /* GS18Prefix */:
1777
- gs1CompanyPrefix = "00000" + prefix;
1778
- break;
1779
- // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- Method may be called by unsafe means.
1780
- default:
1781
- throw new RangeError(i18nextGS1.t("Prefix.invalidPrefixType"));
1782
- }
1783
- let prefixManager = _PrefixManager.PREFIX_MANAGERS_MAP.get(gs1CompanyPrefix);
1784
- if (prefixManager === void 0) {
1785
- prefixManager = new _PrefixManager(gs1CompanyPrefix);
1786
- _PrefixManager.PREFIX_MANAGERS_MAP.set(gs1CompanyPrefix, prefixManager);
1787
- }
1788
- return prefixManager;
1789
- }
1790
- /**
1791
- * Validate a prefix.
1792
- *
1793
- * @param prefixType
1794
- * Prefix type.
1795
- *
1796
- * @param allowUPCCompanyPrefix
1797
- * If true, a U.P.C. Company Prefix expressed as a GS1 Company Prefix is permitted.
1798
- *
1799
- * @param allowGS18Prefix
1800
- * If true, a GS1-8 Prefix expressed as a GS1 Company Prefix is permitted.
1801
- *
1802
- * @param prefix
1803
- * Prefix.
1804
- *
1805
- * @param isFromIdentificationKey
1806
- * If true, the prefix is from an identification key and should be trimmed before its character set is validated.
1807
- *
1808
- * @param isNumericIdentificationKey
1809
- * If true, the prefix is from a numeric identification key and its character set will be validated by the caller.
1810
- *
1811
- * @param positionOffset
1812
- * Position offset within a larger string.
1813
- */
1814
- static validatePrefix(prefixType, allowUPCCompanyPrefix, allowGS18Prefix, prefix, isFromIdentificationKey = false, isNumericIdentificationKey = false, positionOffset) {
1815
- let baseValidation;
1816
- switch (prefixType) {
1817
- case 0 /* GS1CompanyPrefix */:
1818
- if (!prefix.startsWith("0")) {
1819
- baseValidation = _PrefixManager.GS1_COMPANY_PREFIX_VALIDATION;
1820
- } else if (!prefix.startsWith("00000")) {
1821
- if (!allowUPCCompanyPrefix) {
1822
- throw new RangeError(i18nextGS1.t("Prefix.gs1CompanyPrefixCantStartWith0"));
1823
- }
1824
- baseValidation = _PrefixManager.UPC_COMPANY_PREFIX_AS_GS1_COMPANY_PREFIX_VALIDATION;
1825
- } else if (!prefix.startsWith("000000")) {
1826
- if (!allowGS18Prefix) {
1827
- throw new RangeError(i18nextGS1.t("Prefix.gs1CompanyPrefixCantStartWith00000"));
1828
- }
1829
- baseValidation = _PrefixManager.GS1_8_PREFIX_AS_GS1_COMPANY_PREFIX_VALIDATION;
1830
- } else {
1831
- throw new RangeError(i18nextGS1.t("Prefix.gs1CompanyPrefixCantStartWith000000"));
1832
- }
1833
- break;
1834
- case 1 /* UPCCompanyPrefix */:
1835
- if (prefix.startsWith("0000")) {
1836
- throw new RangeError(i18nextGS1.t("Prefix.upcCompanyPrefixCantStartWith0000"));
1837
- }
1838
- baseValidation = _PrefixManager.UPC_COMPANY_PREFIX_VALIDATION;
1839
- break;
1840
- case 2 /* GS18Prefix */:
1841
- if (prefix.startsWith("0")) {
1842
- throw new RangeError(i18nextGS1.t("Prefix.gs18PrefixCantStartWith0"));
1843
- }
1844
- baseValidation = _PrefixManager.GS1_8_PREFIX_VALIDATION;
1845
- break;
1846
- }
1847
- const mergedValidation = {
1848
- ...baseValidation,
1849
- positionOffset
1850
- };
1851
- if (!isFromIdentificationKey) {
1852
- import_utility4.NUMERIC_CREATOR.validate(prefix, mergedValidation);
1853
- } else if (!isNumericIdentificationKey) {
1854
- import_utility4.NUMERIC_CREATOR.validate(prefix.substring(0, Math.min(mergedValidation.minimumLength, prefix.length - 1)), mergedValidation);
1855
- }
1856
- }
1857
- /**
1858
- * Get an identification key creator.
1859
- *
1860
- * @param identificationKeyType
1861
- * Identification key type.
1862
- *
1863
- * @param constructorCallback
1864
- * Constructor callback.
1865
- *
1866
- * @returns
1867
- * Identification key creator.
1868
- */
1869
- getIdentificationKeyCreator(identificationKeyType, constructorCallback) {
1870
- let creator = this._identificationKeyCreatorsMap.get(identificationKeyType);
1871
- if (creator === void 0) {
1872
- if (this.prefixType === 2 /* GS18Prefix */ && identificationKeyType !== "GTIN" /* GTIN */) {
1873
- throw new RangeError(i18nextGS1.t("Prefix.identificationKeyTypeNotSupportedByGS18Prefix", {
1874
- identificationKeyType
1875
- }));
1876
- }
1877
- creator = constructorCallback();
1878
- this.setCreatorTweak(creator);
1879
- this._identificationKeyCreatorsMap.set(identificationKeyType, creator);
1880
- }
1881
- return creator;
1882
- }
1883
- /**
1884
- * Get non-GTIN numeric identification key creator.
1885
- *
1886
- * @param validator
1887
- * Validator on which identification key creator is based.
1888
- *
1889
- * @returns
1890
- * Identification key creator.
1891
- */
1892
- getNonGTINNumericIdentificationKeyCreator(validator) {
1893
- return this.getIdentificationKeyCreator(validator.identificationKeyType, () => new NonGTINNumericIdentificationKeyCreator(this, validator.identificationKeyType, validator.length, validator.leaderType));
1894
- }
1895
- /**
1896
- * Get serialized numeric identification key creator.
1897
- *
1898
- * @param validator
1899
- * Validator on which identification key creator is based.
1900
- *
1901
- * @returns
1902
- * Identification key creator.
1903
- */
1904
- getSerializableNumericIdentificationKeyCreator(validator) {
1905
- return this.getIdentificationKeyCreator(validator.identificationKeyType, () => new SerializableNumericIdentificationKeyCreator(this, validator.identificationKeyType, validator.length, validator.serialComponentLength, validator.serialComponentCharacterSet));
1906
- }
1907
- /**
1908
- * Get non-numeric identification key creator.
1909
- *
1910
- * @param validator
1911
- * Validator on which identification key creator is based.
1912
- *
1913
- * @returns
1914
- * Identification key creator.
1915
- */
1916
- getNonNumericIdentificationKeyCreator(validator) {
1917
- return this.getIdentificationKeyCreator(validator.identificationKeyType, () => new NonNumericIdentificationKeyCreator(this, validator.identificationKeyType, validator.length, validator.referenceCharacterSet, validator.requiresCheckCharacterPair));
1918
- }
1919
- /**
1920
- * Get GTIN creator.
1921
- */
1922
- get gtinCreator() {
1923
- return this.getIdentificationKeyCreator("GTIN" /* GTIN */, () => {
1924
- let gtinType;
1925
- switch (this.prefixType) {
1926
- case 0 /* GS1CompanyPrefix */:
1927
- gtinType = 13 /* GTIN13 */;
1928
- break;
1929
- case 1 /* UPCCompanyPrefix */:
1930
- gtinType = 12 /* GTIN12 */;
1931
- break;
1932
- case 2 /* GS18Prefix */:
1933
- gtinType = 8 /* GTIN8 */;
1934
- break;
1935
- }
1936
- return new GTINCreator(this, gtinType);
1937
- });
1938
- }
1939
- /**
1940
- * Get GLN creator.
1941
- */
1942
- get glnCreator() {
1943
- return this.getNonGTINNumericIdentificationKeyCreator(GLN_VALIDATOR);
1944
- }
1945
- /**
1946
- * Get SSCC creator.
1947
- */
1948
- get ssccCreator() {
1949
- return this.getNonGTINNumericIdentificationKeyCreator(SSCC_VALIDATOR);
1950
- }
1951
- /**
1952
- * Get GRAI creator.
1953
- */
1954
- get graiCreator() {
1955
- return this.getSerializableNumericIdentificationKeyCreator(GRAI_VALIDATOR);
1956
- }
1957
- /**
1958
- * Get GIAI creator.
1959
- */
1960
- get giaiCreator() {
1961
- return this.getNonNumericIdentificationKeyCreator(GIAI_VALIDATOR);
1962
- }
1963
- /**
1964
- * Get GSRN creator.
1965
- */
1966
- get gsrnCreator() {
1967
- return this.getNonGTINNumericIdentificationKeyCreator(GSRN_VALIDATOR);
1968
- }
1969
- /**
1970
- * Get GDTI creator.
1971
- */
1972
- get gdtiCreator() {
1973
- return this.getSerializableNumericIdentificationKeyCreator(GDTI_VALIDATOR);
1974
- }
1975
- /**
1976
- * Get GINC creator.
1977
- */
1978
- get gincCreator() {
1979
- return this.getNonNumericIdentificationKeyCreator(GINC_VALIDATOR);
1980
- }
1981
- /**
1982
- * Get GSIN creator.
1983
- */
1984
- get gsinCreator() {
1985
- return this.getNonGTINNumericIdentificationKeyCreator(GSIN_VALIDATOR);
1986
- }
1987
- /**
1988
- * Get GCN creator.
1989
- */
1990
- get gcnCreator() {
1991
- return this.getSerializableNumericIdentificationKeyCreator(GCN_VALIDATOR);
1992
- }
1993
- /**
1994
- * Get CPID creator.
1995
- */
1996
- get cpidCreator() {
1997
- return this.getNonNumericIdentificationKeyCreator(CPID_VALIDATOR);
1998
- }
1999
- /**
2000
- * Get GMN creator.
2001
- */
2002
- get gmnCreator() {
2003
- return this.getNonNumericIdentificationKeyCreator(GMN_VALIDATOR);
2004
- }
2005
- };
2006
- // Annotate the CommonJS export names for ESM import in node:
2007
- 0 && (module.exports = {
2008
- AI39_CREATOR,
2009
- AI82_CREATOR,
2010
- CPID_VALIDATOR,
2011
- ContentCharacterSet,
2012
- GCN_VALIDATOR,
2013
- GDTI_VALIDATOR,
2014
- GIAI_VALIDATOR,
2015
- GINC_VALIDATOR,
2016
- GLN_VALIDATOR,
2017
- GMN_VALIDATOR,
2018
- GRAI_VALIDATOR,
2019
- GSIN_VALIDATOR,
2020
- GSRN_VALIDATOR,
2021
- GTIN12_VALIDATOR,
2022
- GTIN13_VALIDATOR,
2023
- GTIN8_VALIDATOR,
2024
- GTINCreator,
2025
- GTINLevel,
2026
- GTINType,
2027
- GTINValidator,
2028
- GTIN_VALIDATORS,
2029
- IdentificationKeyType,
2030
- LeaderType,
2031
- NonGTINNumericIdentificationKeyCreator,
2032
- NonGTINNumericIdentificationKeyValidator,
2033
- NonNumericIdentificationKeyCreator,
2034
- NonNumericIdentificationKeyValidator,
2035
- PrefixManager,
2036
- PrefixType,
2037
- SSCC_VALIDATOR,
2038
- SerializableNumericIdentificationKeyCreator,
2039
- SerializableNumericIdentificationKeyValidator,
2040
- checkCharacterPair,
2041
- checkDigit,
2042
- checkDigitSum,
2043
- fiveDigitPriceWeightCheckDigit,
2044
- fourDigitPriceWeightCheckDigit,
2045
- gs1NS,
2046
- gs1Resources,
2047
- hasValidCheckCharacterPair,
2048
- hasValidCheckDigit,
2049
- i18nGS1Init,
2050
- i18nextGS1
2051
- });
2052
- /*!
2053
- * Copyright © 2024-2025 Dolphin Data Development Ltd. and AIDC Toolkit
2054
- * contributors
2055
- *
2056
- * Licensed under the Apache License, Version 2.0 (the "License");
2057
- * you may not use this file except in compliance with the License.
2058
- * You may obtain a copy of the License at
2059
- *
2060
- * https://www.apache.org/licenses/LICENSE-2.0
2061
- *
2062
- * Unless required by applicable law or agreed to in writing, software
2063
- * distributed under the License is distributed on an "AS IS" BASIS,
2064
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2065
- * See the License for the specific language governing permissions and
2066
- * limitations under the License.
2067
- */