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