@aidc-toolkit/gs1 0.9.14-beta → 0.9.15-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.
@@ -0,0 +1,1262 @@
1
+ import { CharacterSetCreator, type CharacterSetValidation, Exclusion, type StringValidation, type StringValidator, type TransformerInput, type TransformerOutput } from "@aidc-toolkit/utility";
2
+ /**
3
+ * Identification key type.
4
+ */
5
+ export declare enum IdentificationKeyType {
6
+ /**
7
+ * Global Trade Item Number.
8
+ */
9
+ GTIN = "GTIN",
10
+ /**
11
+ * Global Location Number.
12
+ */
13
+ GLN = "GLN",
14
+ /**
15
+ * Serial Shipping Container Code.
16
+ */
17
+ SSCC = "SSCC",
18
+ /**
19
+ * Global Returnable Asset Identifier.
20
+ */
21
+ GRAI = "GRAI",
22
+ /**
23
+ * Global Individual Asset Identifier.
24
+ */
25
+ GIAI = "GIAI",
26
+ /**
27
+ * Global Service Relation Number.
28
+ */
29
+ GSRN = "GSRN",
30
+ /**
31
+ * Global Document Type Identifier.
32
+ */
33
+ GDTI = "GDTI",
34
+ /**
35
+ * Global Identification Number for Consignment.
36
+ */
37
+ GINC = "GINC",
38
+ /**
39
+ * Global Shipment Identification Number.
40
+ */
41
+ GSIN = "GSIN",
42
+ /**
43
+ * Global Coupon Number.
44
+ */
45
+ GCN = "GCN",
46
+ /**
47
+ * Component/Part Identifier.
48
+ */
49
+ CPID = "CPID",
50
+ /**
51
+ * Global Model Number.
52
+ */
53
+ GMN = "GMN"
54
+ }
55
+ /**
56
+ * Prefix type.
57
+ */
58
+ export declare enum PrefixType {
59
+ /**
60
+ * GS1 Company Prefix.
61
+ */
62
+ GS1CompanyPrefix = 0,
63
+ /**
64
+ * U.P.C. Company Prefix.
65
+ */
66
+ UPCCompanyPrefix = 1,
67
+ /**
68
+ * GS1-8 Prefix.
69
+ */
70
+ GS18Prefix = 2
71
+ }
72
+ /**
73
+ * Character set supported by the reference portion of an identification key or the serial component of a numeric
74
+ * identification key.
75
+ */
76
+ export declare enum ContentCharacterSet {
77
+ /**
78
+ * Numeric.
79
+ */
80
+ Numeric = 0,
81
+ /**
82
+ * GS1 AI encodable character set 82.
83
+ */
84
+ AI82 = 1,
85
+ /**
86
+ * GS1 AI encodable character set 39.
87
+ */
88
+ AI39 = 2
89
+ }
90
+ /**
91
+ * Identification key validation parameters.
92
+ */
93
+ export interface IdentificationKeyValidation extends StringValidation {
94
+ /**
95
+ * Position offset within a larger string. Strings are sometimes composed of multiple substrings; this parameter
96
+ * ensures that the error notes the proper position in the string.
97
+ */
98
+ positionOffset?: number | undefined;
99
+ }
100
+ /**
101
+ * Identification key validator. Validates an identification key against its definition in section 3 of the {@link
102
+ * https://www.gs1.org/genspecs | GS1 General Specifications}.
103
+ */
104
+ export interface IdentificationKeyValidator<TIdentificationKeyValidation extends IdentificationKeyValidation = IdentificationKeyValidation> extends StringValidator<TIdentificationKeyValidation> {
105
+ /**
106
+ * Get the identification key type. Per the GS1 General Specifications, the identification key type determines
107
+ * the remaining properties.
108
+ */
109
+ get identificationKeyType(): IdentificationKeyType;
110
+ /**
111
+ * Get the prefix type supported by the identification key type. For all identification key types except the GTIN,
112
+ * this is {@linkcode PrefixType.GS1CompanyPrefix}. For the GTIN, the prefix type determines the length.
113
+ */
114
+ get prefixType(): PrefixType;
115
+ /**
116
+ * Get the length. For numeric identification key types, the length is fixed; for alphanumeric identification key
117
+ * types, the length is the maximum.
118
+ */
119
+ get length(): number;
120
+ /**
121
+ * Get the reference character set.
122
+ */
123
+ get referenceCharacterSet(): ContentCharacterSet;
124
+ /**
125
+ * Get the reference validator.
126
+ */
127
+ get referenceCreator(): CharacterSetCreator;
128
+ /**
129
+ * Validate an identification key and throw an error if validation fails.
130
+ *
131
+ * @param identificationKey
132
+ * Identification key.
133
+ *
134
+ * @param validation
135
+ * Identification key validation parameters.
136
+ */
137
+ validate: (identificationKey: string, validation?: TIdentificationKeyValidation) => void;
138
+ }
139
+ /**
140
+ * Abstract identification key validator. Implements common functionality for an identification key validator.
141
+ */
142
+ declare abstract class AbstractIdentificationKeyValidator<TIdentificationKeyValidation extends IdentificationKeyValidation = IdentificationKeyValidation> implements IdentificationKeyValidator<TIdentificationKeyValidation> {
143
+ private static readonly CHARACTER_SET_CREATORS;
144
+ /**
145
+ * Identification key type.
146
+ */
147
+ private readonly _identificationKeyType;
148
+ /**
149
+ * Prefix type.
150
+ */
151
+ private readonly _prefixType;
152
+ /**
153
+ * Length.
154
+ */
155
+ private readonly _length;
156
+ /**
157
+ * Reference character set.
158
+ */
159
+ private readonly _referenceCharacterSet;
160
+ /**
161
+ * Reference creator.
162
+ */
163
+ private readonly _referenceCreator;
164
+ /**
165
+ * Get the character set creator for a character set.
166
+ *
167
+ * @param characterSet
168
+ * Character set.
169
+ *
170
+ * @returns
171
+ * Character set creator.
172
+ */
173
+ protected static creatorFor(characterSet: ContentCharacterSet): CharacterSetCreator;
174
+ /**
175
+ * Constructor.
176
+ *
177
+ * @param identificationKeyType
178
+ * Identification key type.
179
+ *
180
+ * @param prefixType
181
+ * Prefix type.
182
+ *
183
+ * @param length
184
+ * Length.
185
+ *
186
+ * @param referenceCharacterSet
187
+ * Reference character set.
188
+ */
189
+ protected constructor(identificationKeyType: IdentificationKeyType, prefixType: PrefixType, length: number, referenceCharacterSet: ContentCharacterSet);
190
+ /**
191
+ * @inheritDoc
192
+ */
193
+ get identificationKeyType(): IdentificationKeyType;
194
+ /**
195
+ * @inheritDoc
196
+ */
197
+ get prefixType(): PrefixType;
198
+ /**
199
+ * @inheritDoc
200
+ */
201
+ get length(): number;
202
+ /**
203
+ * @inheritDoc
204
+ */
205
+ get referenceCharacterSet(): ContentCharacterSet;
206
+ /**
207
+ * @inheritDoc
208
+ */
209
+ get referenceCreator(): CharacterSetCreator;
210
+ /**
211
+ * Pad an identification key on the left with zero-value character for validation purposes. This is done to align an
212
+ * identification key with a position offset for any error message that may be thrown by the reference validator.
213
+ *
214
+ * @param identificationKey
215
+ * Identification key.
216
+ *
217
+ * @param validation
218
+ * Identification key validation parameters.
219
+ *
220
+ * @returns
221
+ * Padded identification key.
222
+ */
223
+ protected padIdentificationKey(identificationKey: string, validation: IdentificationKeyValidation | undefined): string;
224
+ /**
225
+ * Validate the prefix within an identification key.
226
+ *
227
+ * @param partialIdentificationKey
228
+ * Partial identification key.
229
+ *
230
+ * @param positionOffset
231
+ * Position offset within a larger string.
232
+ */
233
+ protected validatePrefix(partialIdentificationKey: string, positionOffset?: number): void;
234
+ abstract validate(identificationKey: string, validation?: TIdentificationKeyValidation): void;
235
+ }
236
+ /**
237
+ * Leader type.
238
+ */
239
+ export declare enum LeaderType {
240
+ /**
241
+ * No leader.
242
+ */
243
+ None = 0,
244
+ /**
245
+ * Indicator digit (GTIN only).
246
+ */
247
+ IndicatorDigit = 1,
248
+ /**
249
+ * Extension digit (SSCC only).
250
+ */
251
+ ExtensionDigit = 2
252
+ }
253
+ /**
254
+ * Numeric identification key validator. Validates a numeric identification key.
255
+ */
256
+ export interface NumericIdentificationKeyValidator extends IdentificationKeyValidator {
257
+ /**
258
+ * Get the leader type.
259
+ */
260
+ get leaderType(): LeaderType;
261
+ }
262
+ /**
263
+ * Abstract numeric identification key validator. Implements common functionality for a numeric identification key
264
+ * validator.
265
+ */
266
+ declare abstract class AbstractNumericIdentificationKeyValidator extends AbstractIdentificationKeyValidator implements NumericIdentificationKeyValidator {
267
+ /**
268
+ * Leader type.
269
+ */
270
+ private readonly _leaderType;
271
+ /**
272
+ * Prefix position, determined by the leader type.
273
+ */
274
+ private readonly _prefixPosition;
275
+ /**
276
+ * Constructor.
277
+ *
278
+ * @param identificationKeyType
279
+ * Identification key type.
280
+ *
281
+ * @param prefixType
282
+ * Prefix type.
283
+ *
284
+ * @param length
285
+ * Length.
286
+ *
287
+ * @param leaderType
288
+ * Leader type.
289
+ */
290
+ protected constructor(identificationKeyType: IdentificationKeyType, prefixType: PrefixType, length: number, leaderType: LeaderType);
291
+ /**
292
+ * @inheritDoc
293
+ */
294
+ get leaderType(): LeaderType;
295
+ /**
296
+ * @inheritDoc
297
+ */
298
+ validate(identificationKey: string, validation?: IdentificationKeyValidation): void;
299
+ }
300
+ /**
301
+ * GTIN type. The numeric values of this enumeration are equal to the lengths of the GTIN types.
302
+ */
303
+ export declare enum GTINType {
304
+ /**
305
+ * GTIN-13.
306
+ */
307
+ GTIN13 = 13,
308
+ /**
309
+ * GTIN-12.
310
+ */
311
+ GTIN12 = 12,
312
+ /**
313
+ * GTIN-8.
314
+ */
315
+ GTIN8 = 8,
316
+ /**
317
+ * GTIN-14.
318
+ */
319
+ GTIN14 = 14
320
+ }
321
+ /**
322
+ * Level at which GTIN is to be validated.
323
+ */
324
+ export declare enum GTINLevel {
325
+ /**
326
+ * Any level (level is ignored).
327
+ */
328
+ Any = 0,
329
+ /**
330
+ * Retail consumer trade item level, supporting GTIN-13, GTIN-12 (optionally zero-suppressed), and GTIN-8.
331
+ */
332
+ RetailConsumer = 1,
333
+ /**
334
+ * Other than retail consumer trade item level, supporting GTIN-13, GTIN-12 (not zero-suppressed), and GTIN-14.
335
+ */
336
+ OtherThanRetailConsumer = 2
337
+ }
338
+ /**
339
+ * GTIN validator.
340
+ */
341
+ export declare class GTINValidator extends AbstractNumericIdentificationKeyValidator {
342
+ /**
343
+ * Validation parameters for optional indicator digit.
344
+ */
345
+ private static readonly OPTIONAL_INDICATOR_DIGIT_VALIDATION;
346
+ /**
347
+ * Validation parameters for zero-suppressed GTIN-12.
348
+ */
349
+ private static readonly ZERO_SUPPRESSED_GTIN12_VALIDATION;
350
+ /**
351
+ * Constructor.
352
+ *
353
+ * @param gtinType
354
+ * GTIN type.
355
+ */
356
+ constructor(gtinType: GTINType);
357
+ /**
358
+ * @inheritDoc
359
+ */
360
+ get gtinType(): GTINType;
361
+ /**
362
+ * @inheritDoc
363
+ */
364
+ protected validatePrefix(partialIdentificationKey: string, positionOffset?: number): void;
365
+ /**
366
+ * Zero suppress a GTIN-12.
367
+ *
368
+ * @param gtin12
369
+ * GTIN-12.
370
+ *
371
+ * @returns
372
+ * Zero-suppressed GTIN-12.
373
+ */
374
+ static zeroSuppress(gtin12: string): string;
375
+ /**
376
+ * Zero expand a zero-suppressed GTIN-12.
377
+ *
378
+ * @param zeroSuppressedGTIN12
379
+ * Zero-suppressed GTIN-12.
380
+ *
381
+ * @returns
382
+ * GTIN-12.
383
+ */
384
+ static zeroExpand(zeroSuppressedGTIN12: string): string;
385
+ /**
386
+ * Convert a GTIN of any length to a GTIN-14 with an optional indicator digit.
387
+ *
388
+ * @param indicatorDigit
389
+ * Indicator digit. If blank, assumes "0" if the GTIN is not already a GTIN-14.
390
+ *
391
+ * @param gtin
392
+ * GTIN.
393
+ *
394
+ * @returns
395
+ * GTIN-14.
396
+ */
397
+ static convertToGTIN14(indicatorDigit: string, gtin: string): string;
398
+ /**
399
+ * Normalize a GTIN of any length.
400
+ * - A GTIN-14 that starts with six zeros or a GTIN-13 that starts with five zeros is normalized to GTIN-8.
401
+ * - A GTIN-14 that starts with two zeros or a GTIN-13 that starts with one zero is normalized to GTIN-12.
402
+ * - A GTIN-14 that starts with one zero is normalized to GTIN-13.
403
+ * - Otherwise, the GTIN is unchanged.
404
+ *
405
+ * @param gtin
406
+ * GTIN.
407
+ *
408
+ * @returns
409
+ * Normalized GTIN.
410
+ */
411
+ static normalize(gtin: string): string;
412
+ /**
413
+ * Validate any GTIN, optionally against a level.
414
+ *
415
+ * @param gtin
416
+ * GTIN.
417
+ *
418
+ * @param gtinLevel
419
+ * Level at which GTIN is to be validated.
420
+ */
421
+ static validateAny(gtin: string, gtinLevel?: GTINLevel): void;
422
+ /**
423
+ * Validate a GTIN-14.
424
+ *
425
+ * @param gtin14
426
+ * GTIN-14.
427
+ */
428
+ static validateGTIN14(gtin14: string): void;
429
+ }
430
+ /**
431
+ * Non-GTIN numeric identification key validator.
432
+ */
433
+ export declare class NonGTINNumericIdentificationKeyValidator extends AbstractNumericIdentificationKeyValidator {
434
+ /**
435
+ * Constructor.
436
+ *
437
+ * @param identificationKeyType
438
+ * Identification key type.
439
+ *
440
+ * @param length
441
+ * Length.
442
+ *
443
+ * @param leaderType
444
+ * Leader type.
445
+ */
446
+ constructor(identificationKeyType: IdentificationKeyType, length: number, leaderType?: LeaderType);
447
+ }
448
+ /**
449
+ * Serializable numeric identification key validator. Validates both serialized and non-serialized forms of
450
+ * numeric identification keys that support serialization.
451
+ */
452
+ export declare class SerializableNumericIdentificationKeyValidator extends NonGTINNumericIdentificationKeyValidator {
453
+ /**
454
+ * Serial component length.
455
+ */
456
+ private readonly _serialComponentLength;
457
+ /**
458
+ * Serial component character set.
459
+ */
460
+ private readonly _serialComponentCharacterSet;
461
+ /**
462
+ * Serial component validation parameters.
463
+ */
464
+ private readonly _serialComponentValidation;
465
+ /**
466
+ * Serial component creator.
467
+ */
468
+ private readonly _serialComponentCreator;
469
+ /**
470
+ * Constructor.
471
+ *
472
+ * @param identificationKeyType
473
+ * Identification key type.
474
+ *
475
+ * @param length
476
+ * Length.
477
+ *
478
+ * @param serialComponentLength
479
+ * Serial component length.
480
+ *
481
+ * @param serialComponentCharacterSet
482
+ * Serial component character set.
483
+ */
484
+ constructor(identificationKeyType: IdentificationKeyType, length: number, serialComponentLength: number, serialComponentCharacterSet: ContentCharacterSet);
485
+ /**
486
+ * Get the serial component length.
487
+ */
488
+ get serialComponentLength(): number;
489
+ /**
490
+ * Get the serial component character set.
491
+ */
492
+ get serialComponentCharacterSet(): ContentCharacterSet;
493
+ /**
494
+ * Get the serial component validation parameters.
495
+ */
496
+ protected get serialComponentValidation(): CharacterSetValidation;
497
+ /**
498
+ * Get the serial component creator.
499
+ */
500
+ get serialComponentCreator(): CharacterSetCreator;
501
+ /**
502
+ * @inheritDoc
503
+ */
504
+ validate(identificationKey: string, validation?: IdentificationKeyValidation): void;
505
+ }
506
+ /**
507
+ * Non-numeric identification key validation parameters.
508
+ */
509
+ export interface NonNumericIdentificationKeyValidation extends IdentificationKeyValidation {
510
+ /**
511
+ * Exclusion support for reference. Prevents non-numeric identification key from being mistaken for numeric
512
+ * identification key.
513
+ */
514
+ exclusion?: Exclusion.None | Exclusion.AllNumeric | undefined;
515
+ }
516
+ /**
517
+ * Non-numeric identification key validator.
518
+ */
519
+ export declare class NonNumericIdentificationKeyValidator extends AbstractIdentificationKeyValidator<NonNumericIdentificationKeyValidation> {
520
+ /**
521
+ * Validator to ensure that an identification key (minus check character pair) is not all numeric.
522
+ */
523
+ private static readonly NOT_ALL_NUMERIC_VALIDATOR;
524
+ /**
525
+ * True if the identification key requires a check character pair.
526
+ */
527
+ private readonly _requiresCheckCharacterPair;
528
+ /**
529
+ * Constructor.
530
+ *
531
+ * @param identificationKeyType
532
+ * Identification key type.
533
+ *
534
+ * @param length
535
+ * Length.
536
+ *
537
+ * @param referenceCharacterSet
538
+ * Reference character set.
539
+ *
540
+ * @param requiresCheckCharacterPair
541
+ * True if the identification key requires a check character pair.
542
+ */
543
+ constructor(identificationKeyType: IdentificationKeyType, length: number, referenceCharacterSet: ContentCharacterSet, requiresCheckCharacterPair?: boolean);
544
+ /**
545
+ * Determine if the identification key requires a check character pair.
546
+ */
547
+ get requiresCheckCharacterPair(): boolean;
548
+ /**
549
+ * Validate a non-numeric identification key and throw an error if validation fails.
550
+ *
551
+ * @param identificationKey
552
+ * Identification key.
553
+ *
554
+ * @param validation
555
+ * Validation parameters.
556
+ */
557
+ validate(identificationKey: string, validation?: NonNumericIdentificationKeyValidation): void;
558
+ }
559
+ /**
560
+ * GTIN-13 validator.
561
+ */
562
+ export declare const GTIN13_VALIDATOR: GTINValidator;
563
+ /**
564
+ * GTIN-12 validator.
565
+ */
566
+ export declare const GTIN12_VALIDATOR: GTINValidator;
567
+ /**
568
+ * GTIN-8 validator.
569
+ */
570
+ export declare const GTIN8_VALIDATOR: GTINValidator;
571
+ /**
572
+ * GTIN validators indexed by prefix type.
573
+ */
574
+ export declare const GTIN_VALIDATORS: GTINValidator[];
575
+ /**
576
+ * GLN validator.
577
+ */
578
+ export declare const GLN_VALIDATOR: NonGTINNumericIdentificationKeyValidator;
579
+ /**
580
+ * SSCC validator.
581
+ */
582
+ export declare const SSCC_VALIDATOR: NonGTINNumericIdentificationKeyValidator;
583
+ /**
584
+ * GRAI validator.
585
+ */
586
+ export declare const GRAI_VALIDATOR: SerializableNumericIdentificationKeyValidator;
587
+ /**
588
+ * GIAI validator.
589
+ */
590
+ export declare const GIAI_VALIDATOR: NonNumericIdentificationKeyValidator;
591
+ /**
592
+ * GSRN validator.
593
+ */
594
+ export declare const GSRN_VALIDATOR: NonGTINNumericIdentificationKeyValidator;
595
+ /**
596
+ * GDTI validator.
597
+ */
598
+ export declare const GDTI_VALIDATOR: SerializableNumericIdentificationKeyValidator;
599
+ /**
600
+ * GINC validator.
601
+ */
602
+ export declare const GINC_VALIDATOR: NonNumericIdentificationKeyValidator;
603
+ /**
604
+ * GSIN validator.
605
+ */
606
+ export declare const GSIN_VALIDATOR: NonGTINNumericIdentificationKeyValidator;
607
+ /**
608
+ * GCN validator.
609
+ */
610
+ export declare const GCN_VALIDATOR: SerializableNumericIdentificationKeyValidator;
611
+ /**
612
+ * CPID validator.
613
+ */
614
+ export declare const CPID_VALIDATOR: NonNumericIdentificationKeyValidator;
615
+ /**
616
+ * GMN validator.
617
+ */
618
+ export declare const GMN_VALIDATOR: NonNumericIdentificationKeyValidator;
619
+ /**
620
+ * Identification key creator. Creates an identification key based on its definition in section 3 of the {@link
621
+ * https://www.gs1.org/genspecs | GS1 General Specifications}.
622
+ *
623
+ * Keys are created based on a prefix defined in a prefix manager to which the identification key creator is bound.
624
+ */
625
+ export interface IdentificationKeyCreator extends IdentificationKeyValidator {
626
+ /**
627
+ * Get the prefix manager to which this identification key creator is bound.
628
+ */
629
+ get prefixManager(): PrefixManager;
630
+ /**
631
+ * Get the prefix, equivalent to calling {@linkcode PrefixManager.prefix | prefixManager.prefix} for a GTIN or
632
+ * {@linkcode PrefixManager.gs1CompanyPrefix | prefixManager.gs1CompanyPrefix} for all other identification key
633
+ * types.
634
+ */
635
+ get prefix(): string;
636
+ /**
637
+ * Get the reference length.
638
+ */
639
+ get referenceLength(): number;
640
+ }
641
+ /**
642
+ * Abstract identification key creator. Implements common functionality for an identification key creator, bound to a
643
+ * {@link PrefixManager}.
644
+ */
645
+ declare abstract class AbstractIdentificationKeyCreator implements IdentificationKeyCreator {
646
+ /**
647
+ * Prefix manager.
648
+ */
649
+ private _prefixManager;
650
+ /**
651
+ * Reference length.
652
+ */
653
+ private _referenceLength;
654
+ /**
655
+ * Initialize the prefix manager. This method is in lieu of a constructor due to the mixin architecture.
656
+ *
657
+ * @param prefixManager
658
+ * Prefix manager.
659
+ *
660
+ * @param prefix
661
+ * Prefix within prefix manager to use to calculate reference length.
662
+ *
663
+ * @param checkAllowance
664
+ * Number of characters to allow for check digit or check character pair.
665
+ */
666
+ protected init(prefixManager: PrefixManager, prefix: string, checkAllowance: number): void;
667
+ abstract get identificationKeyType(): IdentificationKeyType;
668
+ abstract get prefixType(): PrefixType;
669
+ abstract get length(): number;
670
+ abstract get referenceCharacterSet(): ContentCharacterSet;
671
+ abstract get referenceCreator(): CharacterSetCreator;
672
+ /**
673
+ * @inheritDoc
674
+ */
675
+ get prefixManager(): PrefixManager;
676
+ /**
677
+ * @inheritDoc
678
+ */
679
+ get prefix(): string;
680
+ /**
681
+ * @inheritDoc
682
+ */
683
+ get referenceLength(): number;
684
+ abstract validate(identificationKey: string, validation?: IdentificationKeyValidation): void;
685
+ }
686
+ /**
687
+ * Numeric identification key creator. Creates one or many numeric identification keys.
688
+ */
689
+ export interface NumericIdentificationKeyCreator extends NumericIdentificationKeyValidator, IdentificationKeyCreator {
690
+ /**
691
+ * Get the capacity (`10**referenceLength`).
692
+ */
693
+ get capacity(): number;
694
+ /**
695
+ * Create identification key(s) with reference(s) based on numeric value(s). The value(s) is/are converted to
696
+ * references of the appropriate length using {@linkcode NUMERIC_CREATOR}.
697
+ *
698
+ * @param valueOrValues
699
+ * Numeric value(s).
700
+ *
701
+ * @param sparse
702
+ * If true, the value(s) are mapped to a sparse sequence resistant to discovery. Default is false.
703
+ *
704
+ * @returns
705
+ * Identification key(s).
706
+ */
707
+ create: <TTransformerInput extends TransformerInput<number | bigint>>(valueOrValues: TTransformerInput, sparse?: boolean) => TransformerOutput<TTransformerInput, string>;
708
+ /**
709
+ * Create all identification keys for the prefix from `0` to `capacity - 1`.
710
+ *
711
+ * The implementation creates the strings only as needed using an internal generator function. Although the result
712
+ * is equivalent to calling `creator.create(new Sequence(0, creator.capacity))`, this method is significantly
713
+ * faster.
714
+ *
715
+ * @returns
716
+ * All identification keys for the prefix.
717
+ */
718
+ createAll: () => Iterable<string>;
719
+ }
720
+ /**
721
+ * Abstract numeric identification key creator. Implements common functionality for a numeric identification key creator.
722
+ */
723
+ declare abstract class AbstractNumericIdentificationKeyCreator extends AbstractIdentificationKeyCreator implements NumericIdentificationKeyCreator {
724
+ /**
725
+ * Capacity.
726
+ */
727
+ private _capacity;
728
+ /**
729
+ * Tweak for sparse creation.
730
+ */
731
+ private _tweak;
732
+ /**
733
+ * Initialize the prefix manager. This method is in lieu of a constructor due to the mixin architecture.
734
+ *
735
+ * @param prefixManager
736
+ * Prefix manager.
737
+ *
738
+ * @param prefix
739
+ * Prefix within prefix manager to use to calculate reference length.
740
+ */
741
+ protected init(prefixManager: PrefixManager, prefix: string): void;
742
+ abstract get leaderType(): LeaderType;
743
+ /**
744
+ * @inheritDoc
745
+ */
746
+ get capacity(): number;
747
+ /**
748
+ * Get the tweak for sparse creation.
749
+ */
750
+ get tweak(): bigint;
751
+ /**
752
+ * Set the tweak for sparse creation.
753
+ */
754
+ set tweak(value: bigint);
755
+ /**
756
+ * Build an identification key from a reference by merging it with the prefix and adding the check digit.
757
+ *
758
+ * @param reference
759
+ * Identification key reference.
760
+ *
761
+ * @returns
762
+ * Identification key.
763
+ */
764
+ private buildIdentificationKey;
765
+ /**
766
+ * @inheritDoc
767
+ */
768
+ create<TTransformerInput extends TransformerInput<number | bigint>>(valueOrValues: TTransformerInput, sparse?: boolean): TransformerOutput<TTransformerInput, string>;
769
+ /**
770
+ * Create all identification keys from a partial identification key. Call is recursive until remaining reference
771
+ * length is 0.
772
+ *
773
+ * @param partialIdentificationKey
774
+ * Partial identification key. Initial value is `this.prefix`.
775
+ *
776
+ * @param remainingReferenceLength
777
+ * Remaining reference length. Initial value is `this.referenceLength`.
778
+ *
779
+ * @param extensionWeight
780
+ * If this value is not zero, the identification key has an extension digit, this call is setting it, and this value
781
+ * is applied to the calculation of the check digit.
782
+ *
783
+ * @param weight
784
+ * If the extension weight is zero, this value is applied to the calculation of the check digit.
785
+ *
786
+ * @param partialCheckDigitSum
787
+ * Partial check digit sum for the partial identification key.
788
+ *
789
+ * @yields
790
+ * Identification key.
791
+ */
792
+ private static createAllPartial;
793
+ /**
794
+ * @inheritDoc
795
+ */
796
+ createAll(): Iterable<string>;
797
+ }
798
+ declare const GTINCreator_base: import("ts-mixer/dist/types/types.js").Class<any[], GTINValidator & AbstractNumericIdentificationKeyCreator, typeof GTINValidator & typeof AbstractNumericIdentificationKeyCreator>;
799
+ /**
800
+ * GTIN creator. Applicable to GTIN-13, GTIN-12, and GTIN-8 types; no applicable to GTIN-14 type.
801
+ */
802
+ export declare class GTINCreator extends GTINCreator_base {
803
+ /**
804
+ * Validation parameters for required indicator digit.
805
+ */
806
+ private static readonly REQUIRED_INDICATOR_DIGIT_VALIDATION;
807
+ /**
808
+ * Constructor. Called internally by {@link PrefixManager.gtinCreator}; should not be called by other code.
809
+ *
810
+ * @param prefixManager
811
+ * Prefix manager.
812
+ *
813
+ * @param gtinType
814
+ * GTIN type.
815
+ */
816
+ constructor(prefixManager: PrefixManager, gtinType: GTINType);
817
+ /**
818
+ * @inheritDoc
819
+ */
820
+ get prefix(): string;
821
+ /**
822
+ * Create GTIN-14(s) with an indicator digit and reference(s) based on numeric value(s). The value(s) is/are
823
+ * converted to reference(s) of the appropriate length using {@linkcode NUMERIC_CREATOR}.
824
+ *
825
+ * @param indicatorDigit
826
+ * Indicator digit.
827
+ *
828
+ * @param valueOrValues
829
+ * Numeric value(s).
830
+ *
831
+ * @param sparse
832
+ * If true, the value(s) is/are mapped to a sparse sequence resistant to discovery. Default is false.
833
+ *
834
+ * @returns
835
+ * GTIN-14(s).
836
+ */
837
+ createGTIN14<TTransformerInput extends TransformerInput<number | bigint>>(indicatorDigit: string, valueOrValues: TTransformerInput, sparse?: boolean): TransformerOutput<TTransformerInput, string>;
838
+ }
839
+ declare const NonGTINNumericIdentificationKeyCreator_base: import("ts-mixer/dist/types/types.js").Class<any[], NonGTINNumericIdentificationKeyValidator & AbstractNumericIdentificationKeyCreator, typeof NonGTINNumericIdentificationKeyValidator & typeof AbstractNumericIdentificationKeyCreator>;
840
+ /**
841
+ * Non-GTIN numeric identification key creator.
842
+ */
843
+ export declare class NonGTINNumericIdentificationKeyCreator extends NonGTINNumericIdentificationKeyCreator_base {
844
+ /**
845
+ * Constructor. Called internally by {@link PrefixManager} non-GTIN numeric identification key creator getters;
846
+ * should not be called by other code.
847
+ *
848
+ * @param prefixManager
849
+ * Prefix manager.
850
+ *
851
+ * @param identificationKeyType
852
+ * Identification key type.
853
+ *
854
+ * @param length
855
+ * Length.
856
+ *
857
+ * @param leaderType
858
+ * Leader type.
859
+ */
860
+ constructor(prefixManager: PrefixManager, identificationKeyType: IdentificationKeyType, length: number, leaderType?: LeaderType);
861
+ }
862
+ declare const SerializableNumericIdentificationKeyCreator_base: import("ts-mixer/dist/types/types.js").Class<any[], SerializableNumericIdentificationKeyValidator & AbstractNumericIdentificationKeyCreator, typeof SerializableNumericIdentificationKeyValidator & typeof AbstractNumericIdentificationKeyCreator>;
863
+ /**
864
+ * Serializable numeric identification key creator.
865
+ */
866
+ export declare class SerializableNumericIdentificationKeyCreator extends SerializableNumericIdentificationKeyCreator_base {
867
+ /**
868
+ * Constructor. Called internally by {@link PrefixManager} serialized numeric identification key creator getters;
869
+ * should not be called by other code.
870
+ *
871
+ * @param prefixManager
872
+ * Prefix manager.
873
+ *
874
+ * @param identificationKeyType
875
+ * Identification key type.
876
+ *
877
+ * @param length
878
+ * Length.
879
+ *
880
+ * @param serialComponentLength
881
+ * Serial component length.
882
+ *
883
+ * @param serialComponentCharacterSet
884
+ * Serial component character set.
885
+ */
886
+ constructor(prefixManager: PrefixManager, identificationKeyType: IdentificationKeyType, length: number, serialComponentLength: number, serialComponentCharacterSet: ContentCharacterSet);
887
+ /**
888
+ * Concatenate a validated base identification key with serial component(s).
889
+ *
890
+ * @param baseIdentificationKey
891
+ * Base identification key.
892
+ *
893
+ * @param serialComponentOrComponents
894
+ * Serial component(s).
895
+ *
896
+ * @returns
897
+ * Serialized identification key(s).
898
+ */
899
+ private concatenateValidated;
900
+ /**
901
+ * Create serialized identification key(s) with a reference based on a numeric value concatenated with serial
902
+ * component(s). The value is converted to a reference of the appropriate length using {@linkcode NUMERIC_CREATOR}.
903
+ *
904
+ * @param value
905
+ * Numeric value of the reference.
906
+ *
907
+ * @param serialComponentOrComponents
908
+ * Serial component(s).
909
+ *
910
+ * @param sparse
911
+ * If true, the value is mapped to a sparse sequence resistant to discovery. Default is false.
912
+ *
913
+ * @returns
914
+ * Serialized identification keys.
915
+ */
916
+ createSerialized<TTransformerInput extends TransformerInput<string>>(value: number, serialComponentOrComponents: TTransformerInput, sparse?: boolean): TransformerOutput<TTransformerInput, string>;
917
+ /**
918
+ * Concatenate a base identification key with serial component(s).
919
+ *
920
+ * @param baseIdentificationKey
921
+ * Base identification key.
922
+ *
923
+ * @param serialComponentOrComponents
924
+ * Serial component(s).
925
+ *
926
+ * @returns
927
+ * Serialized identification key(s).
928
+ */
929
+ concatenate<TTransformerInput extends TransformerInput<string>>(baseIdentificationKey: string, serialComponentOrComponents: TTransformerInput): TransformerOutput<TTransformerInput, string>;
930
+ }
931
+ declare const NonNumericIdentificationKeyCreator_base: import("ts-mixer/dist/types/types.js").Class<any[], NonNumericIdentificationKeyValidator & AbstractIdentificationKeyCreator, typeof NonNumericIdentificationKeyValidator & typeof AbstractIdentificationKeyCreator>;
932
+ /**
933
+ * Non-numeric identification key creator.
934
+ */
935
+ export declare class NonNumericIdentificationKeyCreator extends NonNumericIdentificationKeyCreator_base {
936
+ /**
937
+ * Reference validation parameters.
938
+ */
939
+ private readonly _referenceValidation;
940
+ /**
941
+ * Constructor. Called internally by {@link PrefixManager} non-numeric identification key creator getters; should
942
+ * not be called by other code.
943
+ *
944
+ * @param prefixManager
945
+ * Prefix manager.
946
+ *
947
+ * @param identificationKeyType
948
+ * Identification key type.
949
+ *
950
+ * @param length
951
+ * Length.
952
+ *
953
+ * @param referenceCharacterSet
954
+ * Reference character set.
955
+ *
956
+ * @param requiresCheckCharacterPair
957
+ * True if the identification key requires a check character pair.
958
+ */
959
+ constructor(prefixManager: PrefixManager, identificationKeyType: IdentificationKeyType, length: number, referenceCharacterSet: ContentCharacterSet, requiresCheckCharacterPair?: boolean);
960
+ /**
961
+ * Get the reference validation parameters.
962
+ */
963
+ protected get referenceValidation(): CharacterSetValidation;
964
+ /**
965
+ * Create identification key(s) with reference(s).
966
+ *
967
+ * @param referenceOrReferences
968
+ * Reference(s).
969
+ *
970
+ * @returns
971
+ * Identification key(s).
972
+ */
973
+ create<TTransformerInput extends TransformerInput<string>>(referenceOrReferences: TTransformerInput): TransformerOutput<TTransformerInput, string>;
974
+ }
975
+ /**
976
+ * Prefix manager. This is the core class for identification key creation.
977
+ *
978
+ * A prefix manager may be created for any {@link PrefixType | prefix type}. As most applications work with a limited
979
+ * number of prefixes for creating identification keys, prefix managers are cached in memory and may be reused.
980
+ *
981
+ * Prefix managers are keyed by GS1 Company Prefix, so the prefix type that is requested may not match the prefix type
982
+ * of the returned prefix manager. For example, the prefix manager for GS1 Company Prefix 0614141 is identical to the
983
+ * one for U.P.C. Company Prefix 614141, with the prefix type equal to {@link PrefixType.UPCCompanyPrefix} and the
984
+ * prefix equal to "614141".
985
+ *
986
+ * To support the creation of sparse identification keys, a prefix manager maintains a {@link tweakFactor | tweak
987
+ * factor} which is used, along with a type-specific multiplier, as the tweak when creating numeric identification keys.
988
+ * The default tweak factor is the numeric value of the GS1 Company Prefix representation of the prefix preceded by '1'
989
+ * to ensure uniqueness (i.e., so that prefixes 0 N1 N2 N3... and N1 N2 N3... produce different tweak factors). This is
990
+ * usually sufficient for obfuscation, but as the sparse creation algorithm is reversible and as the GS1 Company Prefix
991
+ * is discoverable via {@link https://www.gs1.org/services/verified-by-gs1 | Verified by GS1}, a user-defined tweak
992
+ * factor should be used if a higher degree of obfuscation is required. When using a tweak factor other than the
993
+ * default, care should be taken to restore it when resuming the application. A tweak factor of 0 creates a straight
994
+ * sequence.
995
+ */
996
+ export declare class PrefixManager {
997
+ /**
998
+ * Cached prefix managers, keyed by GS1 Company Prefix.
999
+ */
1000
+ private static readonly PREFIX_MANAGERS_MAP;
1001
+ /**
1002
+ * GS1 Company Prefix minimum length.
1003
+ */
1004
+ static readonly GS1_COMPANY_PREFIX_MINIMUM_LENGTH = 4;
1005
+ /**
1006
+ * GS1 Company Prefix maximum length.
1007
+ */
1008
+ static readonly GS1_COMPANY_PREFIX_MAXIMUM_LENGTH = 12;
1009
+ /**
1010
+ * U.P.C. Company Prefix minimum length.
1011
+ */
1012
+ static readonly UPC_COMPANY_PREFIX_MINIMUM_LENGTH = 6;
1013
+ /**
1014
+ * U.P.C. Company Prefix maximum length.
1015
+ */
1016
+ static readonly UPC_COMPANY_PREFIX_MAXIMUM_LENGTH = 11;
1017
+ /**
1018
+ * GS1-8 Prefix minimum length.
1019
+ */
1020
+ static readonly GS1_8_PREFIX_MINIMUM_LENGTH = 2;
1021
+ /**
1022
+ * GS1-8 Prefix maximum length.
1023
+ */
1024
+ static readonly GS1_8_PREFIX_MAXIMUM_LENGTH = 7;
1025
+ /**
1026
+ * Validation parameters for GS1 Company Prefix.
1027
+ */
1028
+ private static readonly GS1_COMPANY_PREFIX_VALIDATION;
1029
+ /**
1030
+ * Validation parameters for U.P.C. Company Prefix expressed as GS1 Company Prefix.
1031
+ */
1032
+ private static readonly UPC_COMPANY_PREFIX_AS_GS1_COMPANY_PREFIX_VALIDATION;
1033
+ /**
1034
+ * Validation parameters for GS1-8 Prefix expressed as GS1 Company Prefix.
1035
+ */
1036
+ private static readonly GS1_8_PREFIX_AS_GS1_COMPANY_PREFIX_VALIDATION;
1037
+ /**
1038
+ * Validation parameters for U.P.C. Company Prefix.
1039
+ */
1040
+ private static readonly UPC_COMPANY_PREFIX_VALIDATION;
1041
+ /**
1042
+ * Validation parameters for GS1-8 Prefix.
1043
+ */
1044
+ private static readonly GS1_8_PREFIX_VALIDATION;
1045
+ /**
1046
+ * Creator tweak factors. Different numeric identification key types have different tweak factors so that sparse
1047
+ * creation generates different sequences for each.
1048
+ */
1049
+ private static readonly CREATOR_TWEAK_FACTORS_MAP;
1050
+ /**
1051
+ * Normalized prefix type.
1052
+ */
1053
+ private readonly _prefixType;
1054
+ /**
1055
+ * Normalized prefix.
1056
+ */
1057
+ private readonly _prefix;
1058
+ /**
1059
+ * Prefix as GS1 Company Prefix.
1060
+ */
1061
+ private readonly _gs1CompanyPrefix;
1062
+ /**
1063
+ * U.P.C. Company Prefix if prefix type is {@link PrefixType.UPCCompanyPrefix}.
1064
+ */
1065
+ private readonly _upcCompanyPrefix;
1066
+ /**
1067
+ * GS1-8 Prefix if prefix type is {@link PrefixType.GS18Prefix}.
1068
+ */
1069
+ private readonly _gs18Prefix;
1070
+ /**
1071
+ * Default tweak factor.
1072
+ */
1073
+ private readonly _defaultTweakFactor;
1074
+ /**
1075
+ * Tweak factor.
1076
+ */
1077
+ private _tweakFactor;
1078
+ /**
1079
+ * Cached identification key creators.
1080
+ */
1081
+ private readonly _identificationKeyCreatorsMap;
1082
+ /**
1083
+ * Constructor.
1084
+ *
1085
+ * @param gs1CompanyPrefix
1086
+ * GS1 Company Prefix.
1087
+ */
1088
+ private constructor();
1089
+ /**
1090
+ * Get the prefix type.
1091
+ */
1092
+ get prefixType(): PrefixType;
1093
+ /**
1094
+ * Get the prefix.
1095
+ */
1096
+ get prefix(): string;
1097
+ /**
1098
+ * Get the GS1 Company Prefix.
1099
+ */
1100
+ get gs1CompanyPrefix(): string;
1101
+ /**
1102
+ * Get the U.P.C. Company Prefix if prefix type is {@link PrefixType.UPCCompanyPrefix} or undefined if not.
1103
+ */
1104
+ get upcCompanyPrefix(): string | undefined;
1105
+ /**
1106
+ * Get the GS1-8 Prefix if prefix type is {@link PrefixType.GS18Prefix} or undefined if not.
1107
+ */
1108
+ get gs18Prefix(): string | undefined;
1109
+ /**
1110
+ * Set the tweak for an identification key creator if it's a numeric identification key creator.
1111
+ *
1112
+ * @param creator
1113
+ * Identification key creator.
1114
+ */
1115
+ private setCreatorTweak;
1116
+ /**
1117
+ * Get the tweak factor.
1118
+ */
1119
+ get tweakFactor(): bigint;
1120
+ /**
1121
+ * Set the tweak factor.
1122
+ *
1123
+ * @param value
1124
+ * Tweak factor.
1125
+ */
1126
+ set tweakFactor(value: number | bigint);
1127
+ /**
1128
+ * Reset the tweak factor to its default (numeric value of the GS1 Company Prefix preceded by '1').
1129
+ */
1130
+ resetTweakFactor(): void;
1131
+ /**
1132
+ * Get a prefix manager.
1133
+ *
1134
+ * @param prefixType
1135
+ * Prefix type.
1136
+ *
1137
+ * @param prefix
1138
+ * Prefix.
1139
+ *
1140
+ * @returns
1141
+ * Prefix manager with normalized prefix type and prefix.
1142
+ */
1143
+ static get(prefixType: PrefixType, prefix: string): PrefixManager;
1144
+ /**
1145
+ * Validate a prefix.
1146
+ *
1147
+ * @param prefixType
1148
+ * Prefix type.
1149
+ *
1150
+ * @param allowUPCCompanyPrefix
1151
+ * If true, a U.P.C. Company Prefix expressed as a GS1 Company Prefix is permitted.
1152
+ *
1153
+ * @param allowGS18Prefix
1154
+ * If true, a GS1-8 Prefix expressed as a GS1 Company Prefix is permitted.
1155
+ *
1156
+ * @param prefix
1157
+ * Prefix.
1158
+ *
1159
+ * @param isFromIdentificationKey
1160
+ * If true, the prefix is from an identification key and should be trimmed before its character set is validated.
1161
+ *
1162
+ * @param isNumericIdentificationKey
1163
+ * If true, the prefix is from a numeric identification key and its character set will be validated by the caller.
1164
+ *
1165
+ * @param positionOffset
1166
+ * Position offset within a larger string.
1167
+ */
1168
+ static validatePrefix(prefixType: PrefixType, allowUPCCompanyPrefix: boolean, allowGS18Prefix: boolean, prefix: string, isFromIdentificationKey?: boolean, isNumericIdentificationKey?: boolean, positionOffset?: number): void;
1169
+ /**
1170
+ * Get an identification key creator.
1171
+ *
1172
+ * @param identificationKeyType
1173
+ * Identification key type.
1174
+ *
1175
+ * @param constructorCallback
1176
+ * Constructor callback.
1177
+ *
1178
+ * @returns
1179
+ * Identification key creator.
1180
+ */
1181
+ private getIdentificationKeyCreator;
1182
+ /**
1183
+ * Get non-GTIN numeric identification key creator.
1184
+ *
1185
+ * @param validator
1186
+ * Validator on which identification key creator is based.
1187
+ *
1188
+ * @returns
1189
+ * Identification key creator.
1190
+ */
1191
+ private getNonGTINNumericIdentificationKeyCreator;
1192
+ /**
1193
+ * Get serialized numeric identification key creator.
1194
+ *
1195
+ * @param validator
1196
+ * Validator on which identification key creator is based.
1197
+ *
1198
+ * @returns
1199
+ * Identification key creator.
1200
+ */
1201
+ private getSerializableNumericIdentificationKeyCreator;
1202
+ /**
1203
+ * Get non-numeric identification key creator.
1204
+ *
1205
+ * @param validator
1206
+ * Validator on which identification key creator is based.
1207
+ *
1208
+ * @returns
1209
+ * Identification key creator.
1210
+ */
1211
+ private getNonNumericIdentificationKeyCreator;
1212
+ /**
1213
+ * Get GTIN creator.
1214
+ */
1215
+ get gtinCreator(): GTINCreator;
1216
+ /**
1217
+ * Get GLN creator.
1218
+ */
1219
+ get glnCreator(): NonGTINNumericIdentificationKeyCreator;
1220
+ /**
1221
+ * Get SSCC creator.
1222
+ */
1223
+ get ssccCreator(): NonGTINNumericIdentificationKeyCreator;
1224
+ /**
1225
+ * Get GRAI creator.
1226
+ */
1227
+ get graiCreator(): SerializableNumericIdentificationKeyCreator;
1228
+ /**
1229
+ * Get GIAI creator.
1230
+ */
1231
+ get giaiCreator(): NonNumericIdentificationKeyCreator;
1232
+ /**
1233
+ * Get GSRN creator.
1234
+ */
1235
+ get gsrnCreator(): NonGTINNumericIdentificationKeyCreator;
1236
+ /**
1237
+ * Get GDTI creator.
1238
+ */
1239
+ get gdtiCreator(): SerializableNumericIdentificationKeyCreator;
1240
+ /**
1241
+ * Get GINC creator.
1242
+ */
1243
+ get gincCreator(): NonNumericIdentificationKeyCreator;
1244
+ /**
1245
+ * Get GSIN creator.
1246
+ */
1247
+ get gsinCreator(): NonGTINNumericIdentificationKeyCreator;
1248
+ /**
1249
+ * Get GCN creator.
1250
+ */
1251
+ get gcnCreator(): SerializableNumericIdentificationKeyCreator;
1252
+ /**
1253
+ * Get CPID creator.
1254
+ */
1255
+ get cpidCreator(): NonNumericIdentificationKeyCreator;
1256
+ /**
1257
+ * Get GMN creator.
1258
+ */
1259
+ get gmnCreator(): NonNumericIdentificationKeyCreator;
1260
+ }
1261
+ export {};
1262
+ //# sourceMappingURL=idkey.d.ts.map