@aidc-toolkit/gs1 0.9.3 → 0.9.5

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