@aidc-toolkit/gs1 0.9.5 → 0.9.7-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.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- import { CharacterSetCreator, StringValidation, StringValidator, CharacterSetValidator, CharacterSetValidation, Exclusion } from '@aidc-toolkit/utility';
1
+ import { CharacterSetCreator, StringValidation, StringValidator, CharacterSetValidation, Exclusion, TransformerInput, TransformerOutput } from '@aidc-toolkit/utility';
2
2
  import * as ts_mixer_dist_types_types_js from 'ts-mixer/dist/types/types.js';
3
3
 
4
+ declare const gs1NS = "aidct_gs1";
5
+
4
6
  /**
5
7
  * GS1 AI encodable character set 82 creator as defined in section 7.11 of the {@link https://www.gs1.org/genspecs | GS1
6
8
  * General Specifications}. Supports {@linkcode Exclusion.AllNumeric}.
@@ -165,7 +167,7 @@ declare enum PrefixType {
165
167
  * Character set supported by the reference portion of an identification key or the serial component of a numeric
166
168
  * identification key.
167
169
  */
168
- declare enum CharacterSet {
170
+ declare enum ContentCharacterSet {
169
171
  /**
170
172
  * Numeric.
171
173
  */
@@ -212,11 +214,11 @@ interface IdentificationKeyValidator<V extends IdentificationKeyValidation = Ide
212
214
  /**
213
215
  * Get the reference character set.
214
216
  */
215
- get referenceCharacterSet(): CharacterSet;
217
+ get referenceCharacterSet(): ContentCharacterSet;
216
218
  /**
217
219
  * Get the reference validator.
218
220
  */
219
- get referenceValidator(): CharacterSetValidator;
221
+ get referenceCreator(): CharacterSetCreator;
220
222
  /**
221
223
  * Validate an identification key and throw an error if validation fails.
222
224
  *
@@ -250,19 +252,19 @@ declare abstract class AbstractIdentificationKeyValidator<V extends Identificati
250
252
  */
251
253
  private readonly _referenceCharacterSet;
252
254
  /**
253
- * Reference validator.
255
+ * Reference creator.
254
256
  */
255
- private readonly _referenceValidator;
257
+ private readonly _referenceCreator;
256
258
  /**
257
- * Get the character set validator for a character set.
259
+ * Get the character set creator for a character set.
258
260
  *
259
261
  * @param characterSet
260
262
  * Character set.
261
263
  *
262
264
  * @returns
263
- * Character set validator.
265
+ * Character set creator.
264
266
  */
265
- protected static validatorFor(characterSet: CharacterSet): CharacterSetValidator;
267
+ protected static creatorFor(characterSet: ContentCharacterSet): CharacterSetCreator;
266
268
  /**
267
269
  * Constructor.
268
270
  *
@@ -278,7 +280,7 @@ declare abstract class AbstractIdentificationKeyValidator<V extends Identificati
278
280
  * @param referenceCharacterSet
279
281
  * Reference character set.
280
282
  */
281
- protected constructor(identificationKeyType: IdentificationKeyType, prefixType: PrefixType, length: number, referenceCharacterSet: CharacterSet);
283
+ protected constructor(identificationKeyType: IdentificationKeyType, prefixType: PrefixType, length: number, referenceCharacterSet: ContentCharacterSet);
282
284
  /**
283
285
  * @inheritDoc
284
286
  */
@@ -294,11 +296,11 @@ declare abstract class AbstractIdentificationKeyValidator<V extends Identificati
294
296
  /**
295
297
  * @inheritDoc
296
298
  */
297
- get referenceCharacterSet(): CharacterSet;
299
+ get referenceCharacterSet(): ContentCharacterSet;
298
300
  /**
299
301
  * @inheritDoc
300
302
  */
301
- get referenceValidator(): CharacterSetValidator;
303
+ get referenceCreator(): CharacterSetCreator;
302
304
  /**
303
305
  * Pad an identification key on the left with zero-value character for validation purposes. This is done to align an
304
306
  * identification key with a position offset for any error message that may be thrown by the reference validator.
@@ -514,9 +516,9 @@ declare class SerializableNumericIdentificationKeyValidator extends NonGTINNumer
514
516
  */
515
517
  private readonly _serialComponentValidation;
516
518
  /**
517
- * Serial component validator.
519
+ * Serial component creator.
518
520
  */
519
- private readonly _serialComponentValidator;
521
+ private readonly _serialComponentCreator;
520
522
  /**
521
523
  * Constructor.
522
524
  *
@@ -532,7 +534,7 @@ declare class SerializableNumericIdentificationKeyValidator extends NonGTINNumer
532
534
  * @param serialComponentCharacterSet
533
535
  * Serial component character set.
534
536
  */
535
- constructor(identificationKeyType: IdentificationKeyType, length: number, serialComponentLength: number, serialComponentCharacterSet: CharacterSet);
537
+ constructor(identificationKeyType: IdentificationKeyType, length: number, serialComponentLength: number, serialComponentCharacterSet: ContentCharacterSet);
536
538
  /**
537
539
  * Get the serial component length.
538
540
  */
@@ -540,15 +542,15 @@ declare class SerializableNumericIdentificationKeyValidator extends NonGTINNumer
540
542
  /**
541
543
  * Get the serial component character set.
542
544
  */
543
- get serialComponentCharacterSet(): CharacterSet;
545
+ get serialComponentCharacterSet(): ContentCharacterSet;
544
546
  /**
545
547
  * Get the serial component validation parameters.
546
548
  */
547
549
  protected get serialComponentValidation(): CharacterSetValidation;
548
550
  /**
549
- * Get the serial component validator.
551
+ * Get the serial component creator.
550
552
  */
551
- get serialComponentValidator(): CharacterSetValidator;
553
+ get serialComponentCreator(): CharacterSetCreator;
552
554
  /**
553
555
  * @inheritDoc
554
556
  */
@@ -591,7 +593,7 @@ declare class NonNumericIdentificationKeyValidator extends AbstractIdentificatio
591
593
  * @param requiresCheckCharacterPair
592
594
  * True if the identification key requires a check character pair.
593
595
  */
594
- constructor(identificationKeyType: IdentificationKeyType, length: number, referenceCharacterSet: CharacterSet, requiresCheckCharacterPair?: boolean);
596
+ constructor(identificationKeyType: IdentificationKeyType, length: number, referenceCharacterSet: ContentCharacterSet, requiresCheckCharacterPair?: boolean);
595
597
  /**
596
598
  * Determine if the identification key requires a check character pair.
597
599
  */
@@ -674,10 +676,6 @@ declare const GMN_VALIDATOR: NonNumericIdentificationKeyValidator;
674
676
  * Keys are created based on a prefix defined in a prefix manager to which the identification key creator is bound.
675
677
  */
676
678
  interface IdentificationKeyCreator extends IdentificationKeyValidator {
677
- /**
678
- * Get the reference creator.
679
- */
680
- get referenceCreator(): CharacterSetCreator;
681
679
  /**
682
680
  * Get the prefix manager to which this identification key creator is bound.
683
681
  */
@@ -722,12 +720,8 @@ declare abstract class AbstractIdentificationKeyCreator implements Identificatio
722
720
  abstract get identificationKeyType(): IdentificationKeyType;
723
721
  abstract get prefixType(): PrefixType;
724
722
  abstract get length(): number;
725
- abstract get referenceCharacterSet(): CharacterSet;
726
- abstract get referenceValidator(): CharacterSetValidator;
727
- /**
728
- * @inheritDoc
729
- */
730
- get referenceCreator(): CharacterSetCreator;
723
+ abstract get referenceCharacterSet(): ContentCharacterSet;
724
+ abstract get referenceCreator(): CharacterSetCreator;
731
725
  /**
732
726
  * @inheritDoc
733
727
  */
@@ -750,36 +744,20 @@ interface NumericIdentificationKeyCreator extends NumericIdentificationKeyValida
750
744
  * Get the capacity (`10**referenceLength`).
751
745
  */
752
746
  get capacity(): number;
753
- create: {
754
- /**
755
- * Create an identification key with a reference based on a numeric value. The value is converted to a reference of
756
- * the appropriate length using {@linkcode NUMERIC_CREATOR}.
757
- *
758
- * @param value
759
- * Numeric value.
760
- *
761
- * @param sparse
762
- * If true, the value is mapped to a sparse sequence resistant to discovery. Default is false.
763
- *
764
- * @returns
765
- * Identification key.
766
- */
767
- (value: number | bigint, sparse?: boolean): string;
768
- /**
769
- * Create identification keys with references based on numeric values. The values are converted to references of
770
- * the appropriate length using {@linkcode NUMERIC_CREATOR}.
771
- *
772
- * @param values
773
- * Numeric values.
774
- *
775
- * @param sparse
776
- * If true, the values are mapped to a sparse sequence resistant to discovery. Default is false.
777
- *
778
- * @returns
779
- * Identification keys.
780
- */
781
- (values: Iterable<number | bigint>, sparse?: boolean): IterableIterator<string>;
782
- };
747
+ /**
748
+ * Create identification key(s) with reference(s) based on numeric value(s). The value(s) is/are converted to
749
+ * references of the appropriate length using {@linkcode NUMERIC_CREATOR}.
750
+ *
751
+ * @param valueOrValues
752
+ * Numeric value(s).
753
+ *
754
+ * @param sparse
755
+ * If true, the value(s) are mapped to a sparse sequence resistant to discovery. Default is false.
756
+ *
757
+ * @returns
758
+ * Identification key(s).
759
+ */
760
+ create: <T extends TransformerInput<number | bigint>>(valueOrValues: T, sparse?: boolean) => TransformerOutput<T, string>;
783
761
  /**
784
762
  * Create all identification keys for the prefix from `0` to `capacity - 1`.
785
763
  *
@@ -839,11 +817,7 @@ declare abstract class AbstractNumericIdentificationKeyCreator extends AbstractI
839
817
  /**
840
818
  * @inheritDoc
841
819
  */
842
- create(value: number | bigint, sparse?: boolean): string;
843
- /**
844
- * @inheritDoc
845
- */
846
- create(values: Iterable<number | bigint>, sparse?: boolean): IterableIterator<string>;
820
+ create<T extends TransformerInput<number | bigint>>(valueOrValues: T, sparse?: boolean): TransformerOutput<T, string>;
847
821
  /**
848
822
  * Create all identification keys from a partial identification key. Call is recursive until remaining reference
849
823
  * length is 0.
@@ -901,41 +875,22 @@ declare class GTINCreator extends GTINCreator_base {
901
875
  */
902
876
  get prefix(): string;
903
877
  /**
904
- * Create a GTIN-14 with an indicator digit and a reference based on a numeric value. The value is converted to a
905
- * reference of the appropriate length using {@linkcode NUMERIC_CREATOR}.
906
- *
907
- * @param indicatorDigit
908
- * Indicator digit.
909
- *
910
- * @param value
911
- * Numeric value of the reference.
912
- *
913
- * @param sparse
914
- * If true, the value is mapped to a sparse sequence resistant to discovery. Default is false.
915
- *
916
- * @returns
917
- * GTIN-14.
918
- */
919
- createGTIN14(indicatorDigit: string, value: number | bigint, sparse?: boolean): string;
920
- /**
921
- * Create multiple GTIN-14s with an indicator digit and references based on numeric values. The values are converted
922
- * to references of the appropriate length using {@linkcode NUMERIC_CREATOR}.
923
- *
924
- * The implementation uses {@link CharacterSetCreator.create}, so the values are created only as needed.
878
+ * Create GTIN-14(s) with an indicator digit and reference(s) based on numeric value(s). The value(s) is/are
879
+ * converted to reference(s) of the appropriate length using {@linkcode NUMERIC_CREATOR}.
925
880
  *
926
881
  * @param indicatorDigit
927
882
  * Indicator digit.
928
883
  *
929
- * @param values
930
- * Values.
884
+ * @param valueOrValues
885
+ * Numeric value(s).
931
886
  *
932
887
  * @param sparse
933
- * If true, the values are mapped to a sparse sequence resistant to discovery. Default is false.
888
+ * If true, the value(s) is/are mapped to a sparse sequence resistant to discovery. Default is false.
934
889
  *
935
890
  * @returns
936
- * Iterable iterator over created GTIN-14s.
891
+ * GTIN-14(s).
937
892
  */
938
- createGTIN14(indicatorDigit: string, values: Iterable<number | bigint>, sparse?: boolean): IterableIterator<string>;
893
+ createGTIN14<T extends TransformerInput<number | bigint>>(indicatorDigit: string, valueOrValues: T, sparse?: boolean): TransformerOutput<T, string>;
939
894
  /**
940
895
  * Zero suppress a GTIN-12.
941
896
  *
@@ -1021,50 +976,29 @@ declare class SerializableNumericIdentificationKeyCreator extends SerializableNu
1021
976
  * @param serialComponentCharacterSet
1022
977
  * Serial component character set.
1023
978
  */
1024
- constructor(prefixManager: PrefixManager, identificationKeyType: IdentificationKeyType, length: number, serialComponentLength: number, serialComponentCharacterSet: CharacterSet);
979
+ constructor(prefixManager: PrefixManager, identificationKeyType: IdentificationKeyType, length: number, serialComponentLength: number, serialComponentCharacterSet: ContentCharacterSet);
1025
980
  /**
1026
- * Get the serial component creator.
1027
- */
1028
- get serialComponentCreator(): CharacterSetCreator;
1029
- /**
1030
- * Concatenate a validated base identification key with a serial component.
981
+ * Concatenate a validated base identification key with serial component(s).
1031
982
  *
1032
983
  * @param baseIdentificationKey
1033
984
  * Base identification key.
1034
985
  *
1035
- * @param serialComponent
1036
- * Serial component.
986
+ * @param serialComponentOrComponents
987
+ * Serial component(s).
1037
988
  *
1038
989
  * @returns
1039
- * Serialized identification key.
990
+ * Serialized identification key(s).
1040
991
  */
1041
992
  private concatenateValidated;
1042
993
  /**
1043
- * Create a serialized identification key with a reference based on a numeric value and a serial component. The
1044
- * value is converted to a reference of the appropriate length using {@linkcode NUMERIC_CREATOR}.
994
+ * Create serialized identification key(s) with a reference based on a numeric value concatenated with serial
995
+ * component(s). The value is converted to a reference of the appropriate length using {@linkcode NUMERIC_CREATOR}.
1045
996
  *
1046
997
  * @param value
1047
- * Numeric value of the references.
1048
- *
1049
- * @param serialComponent
1050
- * Serial component.
1051
- *
1052
- * @param sparse
1053
- * If true, the value is mapped to a sparse sequence resistant to discovery. Default is false.
1054
- *
1055
- * @returns
1056
- * Serialized identification key.
1057
- */
1058
- createSerialized(value: number, serialComponent: string, sparse?: boolean): string;
1059
- /**
1060
- * Create multiple serialized identification keys with a reference based on a numeric value and multiple serial
1061
- * components. The value is converted to a reference of the appropriate length using {@linkcode NUMERIC_CREATOR}.
1062
- *
1063
- * @param value
1064
- * Numeric value.
998
+ * Numeric value of the reference.
1065
999
  *
1066
- * @param serialComponents
1067
- * Serial components.
1000
+ * @param serialComponentOrComponents
1001
+ * Serial component(s).
1068
1002
  *
1069
1003
  * @param sparse
1070
1004
  * If true, the value is mapped to a sparse sequence resistant to discovery. Default is false.
@@ -1072,33 +1006,20 @@ declare class SerializableNumericIdentificationKeyCreator extends SerializableNu
1072
1006
  * @returns
1073
1007
  * Serialized identification keys.
1074
1008
  */
1075
- createSerialized(value: number, serialComponents: Iterable<string>, sparse?: boolean): IterableIterator<string>;
1076
- /**
1077
- * Concatenate a base identification key with a serial component.
1078
- *
1079
- * @param baseIdentificationKey
1080
- * Base identification key.
1081
- *
1082
- * @param serialComponent
1083
- * Serial component.
1084
- *
1085
- * @returns
1086
- * Serialized identification key.
1087
- */
1088
- concatenate(baseIdentificationKey: string, serialComponent: string): string;
1009
+ createSerialized<T extends TransformerInput<string>>(value: number, serialComponentOrComponents: T, sparse?: boolean): TransformerOutput<T, string>;
1089
1010
  /**
1090
- * Concatenate a base identification key with multiple serial components.
1011
+ * Concatenate a base identification key with serial component(s).
1091
1012
  *
1092
1013
  * @param baseIdentificationKey
1093
1014
  * Base identification key.
1094
1015
  *
1095
- * @param serialComponents
1096
- * Serial components.
1016
+ * @param serialComponentOrComponents
1017
+ * Serial component(s).
1097
1018
  *
1098
1019
  * @returns
1099
- * Serialized identification keys.
1020
+ * Serialized identification key(s).
1100
1021
  */
1101
- concatenate(baseIdentificationKey: string, serialComponents: Iterable<string>): IterableIterator<string>;
1022
+ concatenate<T extends TransformerInput<string>>(baseIdentificationKey: string, serialComponentOrComponents: T): TransformerOutput<T, string>;
1102
1023
  }
1103
1024
  declare const NonNumericIdentificationKeyCreator_base: ts_mixer_dist_types_types_js.Class<any[], NonNumericIdentificationKeyValidator & AbstractIdentificationKeyCreator, typeof NonNumericIdentificationKeyValidator & typeof AbstractIdentificationKeyCreator>;
1104
1025
  /**
@@ -1128,27 +1049,21 @@ declare class NonNumericIdentificationKeyCreator extends NonNumericIdentificatio
1128
1049
  * @param requiresCheckCharacterPair
1129
1050
  * True if the identification key requires a check character pair.
1130
1051
  */
1131
- constructor(prefixManager: PrefixManager, identificationKeyType: IdentificationKeyType, length: number, referenceCharacterSet: CharacterSet, requiresCheckCharacterPair?: boolean);
1052
+ constructor(prefixManager: PrefixManager, identificationKeyType: IdentificationKeyType, length: number, referenceCharacterSet: ContentCharacterSet, requiresCheckCharacterPair?: boolean);
1132
1053
  /**
1133
- * Create an identification key with a reference.
1134
- *
1135
- * @param reference
1136
- * Reference.
1137
- *
1138
- * @returns
1139
- * Identification key.
1054
+ * Get the reference validation parameters.
1140
1055
  */
1141
- create(reference: string): string;
1056
+ protected get referenceValidation(): CharacterSetValidation;
1142
1057
  /**
1143
- * Create multiple identification keys with references.
1058
+ * Create identification key(s) with reference(s).
1144
1059
  *
1145
- * @param references
1146
- * References.
1060
+ * @param referenceOrReferences
1061
+ * Reference(s).
1147
1062
  *
1148
1063
  * @returns
1149
- * Identification keys.
1064
+ * Identification key(s).
1150
1065
  */
1151
- create(references: Iterable<string>): IterableIterator<string>;
1066
+ create<T extends TransformerInput<string>>(referenceOrReferences: T): TransformerOutput<T, string>;
1152
1067
  }
1153
1068
  /**
1154
1069
  * Prefix manager. This is the core class for identification key creation.
@@ -1433,4 +1348,4 @@ declare class PrefixManager {
1433
1348
  get gmnCreator(): NonNumericIdentificationKeyCreator;
1434
1349
  }
1435
1350
 
1436
- export { AI39_CREATOR, AI82_CREATOR, CPID_VALIDATOR, CharacterSet, GCN_VALIDATOR, GDTI_VALIDATOR, GIAI_VALIDATOR, GINC_VALIDATOR, GLN_VALIDATOR, GMN_VALIDATOR, GRAI_VALIDATOR, GSIN_VALIDATOR, GSRN_VALIDATOR, GTIN12_VALIDATOR, GTIN13_VALIDATOR, GTIN8_VALIDATOR, GTINCreator, GTINLevel, GTINType, GTINValidator, GTIN_VALIDATORS, type IdentificationKeyCreator, IdentificationKeyType, type IdentificationKeyValidation, type IdentificationKeyValidator, LeaderType, NonGTINNumericIdentificationKeyCreator, NonGTINNumericIdentificationKeyValidator, NonNumericIdentificationKeyCreator, type NonNumericIdentificationKeyValidation, NonNumericIdentificationKeyValidator, type NumericIdentificationKeyCreator, type NumericIdentificationKeyValidator, PrefixManager, PrefixType, SSCC_VALIDATOR, SerializableNumericIdentificationKeyCreator, SerializableNumericIdentificationKeyValidator, checkCharacterPair, checkDigit, checkDigitSum, fiveDigitPriceWeightCheckDigit, fourDigitPriceWeightCheckDigit, hasValidCheckCharacterPair, hasValidCheckDigit };
1351
+ export { AI39_CREATOR, AI82_CREATOR, CPID_VALIDATOR, ContentCharacterSet, GCN_VALIDATOR, GDTI_VALIDATOR, GIAI_VALIDATOR, GINC_VALIDATOR, GLN_VALIDATOR, GMN_VALIDATOR, GRAI_VALIDATOR, GSIN_VALIDATOR, GSRN_VALIDATOR, GTIN12_VALIDATOR, GTIN13_VALIDATOR, GTIN8_VALIDATOR, GTINCreator, GTINLevel, GTINType, GTINValidator, GTIN_VALIDATORS, type IdentificationKeyCreator, IdentificationKeyType, type IdentificationKeyValidation, type IdentificationKeyValidator, LeaderType, NonGTINNumericIdentificationKeyCreator, NonGTINNumericIdentificationKeyValidator, NonNumericIdentificationKeyCreator, type NonNumericIdentificationKeyValidation, NonNumericIdentificationKeyValidator, type NumericIdentificationKeyCreator, type NumericIdentificationKeyValidator, PrefixManager, PrefixType, SSCC_VALIDATOR, SerializableNumericIdentificationKeyCreator, SerializableNumericIdentificationKeyValidator, checkCharacterPair, checkDigit, checkDigitSum, fiveDigitPriceWeightCheckDigit, fourDigitPriceWeightCheckDigit, gs1NS, hasValidCheckCharacterPair, hasValidCheckDigit };