@aidc-toolkit/gs1 1.0.24-beta → 1.0.25-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +562 -373
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +776 -415
- package/dist/index.d.ts +776 -415
- package/dist/index.js +549 -363
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/abstract-identifier-creator.ts +97 -0
- package/src/abstract-identifier-validator.ts +140 -0
- package/src/abstract-numeric-identifier-creator.ts +168 -0
- package/src/abstract-numeric-identifier-validator.ts +69 -0
- package/src/character-set.ts +10 -10
- package/src/check.ts +7 -7
- package/src/content-character-set.ts +29 -0
- package/src/creators.ts +113 -0
- package/src/descriptors.ts +332 -0
- package/src/gtin-creator.ts +7 -6
- package/src/gtin-descriptor.ts +18 -0
- package/src/gtin-type.ts +50 -0
- package/src/gtin-validator.ts +36 -60
- package/src/identifier-creator.ts +11 -75
- package/src/identifier-descriptor.ts +30 -0
- package/src/identifier-type.ts +6 -1
- package/src/identifier-validator.ts +12 -188
- package/src/index.ts +29 -5
- package/src/locale/en/locale-resources.ts +0 -1
- package/src/locale/fr/locale-resources.ts +0 -1
- package/src/non-gtin-numeric-identifier-creator.ts +5 -11
- package/src/non-gtin-numeric-identifier-descriptor.ts +24 -0
- package/src/non-gtin-numeric-identifier-type.ts +7 -0
- package/src/non-gtin-numeric-identifier-validator.ts +8 -42
- package/src/non-numeric-identifier-creator.ts +5 -15
- package/src/non-numeric-identifier-descriptor.ts +29 -0
- package/src/non-numeric-identifier-type.ts +7 -0
- package/src/non-numeric-identifier-validator.ts +15 -53
- package/src/numeric-identifier-creator.ts +20 -163
- package/src/numeric-identifier-descriptor.ts +23 -0
- package/src/numeric-identifier-type.ts +44 -0
- package/src/numeric-identifier-validator.ts +13 -116
- package/src/prefix-manager.ts +84 -142
- package/src/prefix-provider.ts +2 -2
- package/src/prefix-type.ts +6 -1
- package/src/prefix-validator.ts +141 -79
- package/src/serializable-numeric-identifier-creator.ts +4 -14
- package/src/serializable-numeric-identifier-descriptor.ts +29 -0
- package/src/serializable-numeric-identifier-type.ts +9 -0
- package/src/serializable-numeric-identifier-validator.ts +17 -45
- package/src/validators.ts +203 -0
- package/test/creator.test.ts +2 -4
- package/test/gtin-creator.ts +5 -1
- package/test/gtin-validator.test.ts +5 -8
- package/test/identifier-creator.ts +1 -0
- package/test/identifier-validator.ts +2 -2
- package/test/non-gtin-numeric-identifier-creator.ts +8 -92
- package/test/non-gtin-numeric-identifier-validator.ts +1 -1
- package/test/non-numeric-identifier-creator.ts +93 -0
- package/test/numeric-identifier-creator.ts +9 -3
- package/test/numeric-identifier-validator.ts +3 -7
- package/test/serializable-numeric-identifier-creator.ts +10 -2
- package/test/validator.test.ts +59 -35
package/dist/index.js
CHANGED
|
@@ -431,7 +431,7 @@ var postProcessor = {
|
|
|
431
431
|
return value;
|
|
432
432
|
}
|
|
433
433
|
};
|
|
434
|
-
var PATH_KEY = Symbol("i18next/PATH_KEY");
|
|
434
|
+
var PATH_KEY = /* @__PURE__ */ Symbol("i18next/PATH_KEY");
|
|
435
435
|
function createProxy() {
|
|
436
436
|
const state = [];
|
|
437
437
|
const handler = /* @__PURE__ */ Object.create(null);
|
|
@@ -2232,7 +2232,6 @@ var locale_resources_default = {
|
|
|
2232
2232
|
gs1CompanyPrefix: "GS1 Company Prefix",
|
|
2233
2233
|
upcCompanyPrefix: "U.P.C. Company Prefix",
|
|
2234
2234
|
gs18Prefix: "GS1-8 Prefix",
|
|
2235
|
-
invalidPrefixType: "Invalid prefix type",
|
|
2236
2235
|
gs1CompanyPrefixCantStartWith0: `GS1 Company Prefix can't start with "0"`,
|
|
2237
2236
|
gs1CompanyPrefixCantStartWith00000: `GS1 Company Prefix can't start with "00000"`,
|
|
2238
2237
|
gs1CompanyPrefixCantStartWith000000: `GS1 Company Prefix can't start with "000000"`,
|
|
@@ -2275,7 +2274,6 @@ var locale_resources_default2 = {
|
|
|
2275
2274
|
gs1CompanyPrefix: "Pr\xE9fixe de l'entreprise GS1",
|
|
2276
2275
|
upcCompanyPrefix: "Pr\xE9fixe de l'entreprise U.P.C.",
|
|
2277
2276
|
gs18Prefix: "Pr\xE9fixe GS1-8",
|
|
2278
|
-
invalidPrefixType: "Type de pr\xE9fixe invalide",
|
|
2279
2277
|
gs1CompanyPrefixCantStartWith0: `Le pr\xE9fixe de l'entreprise GS1 ne peut pas commencer par "0"`,
|
|
2280
2278
|
gs1CompanyPrefixCantStartWith00000: `Le pr\xE9fixe de l'entreprise GS1 ne peut pas commencer par "00000"`,
|
|
2281
2279
|
gs1CompanyPrefixCantStartWith000000: `Le pr\xE9fixe de l'entreprise GS1 ne peut pas commencer par "000000"`,
|
|
@@ -2751,49 +2749,6 @@ var GS1_8_PREFIX_VALIDATION = {
|
|
|
2751
2749
|
maximumLength: GS1_8_PREFIX_MAXIMUM_LENGTH,
|
|
2752
2750
|
component: () => i18nextGS1.t("Prefix.gs18Prefix")
|
|
2753
2751
|
};
|
|
2754
|
-
function validate(prefixType, allowUPCCompanyPrefix, allowGS18Prefix, prefix, isFromIdentifier = false, isNumericIdentifier = false, positionOffset) {
|
|
2755
|
-
let baseValidation;
|
|
2756
|
-
switch (prefixType) {
|
|
2757
|
-
case PrefixTypes.GS1CompanyPrefix:
|
|
2758
|
-
if (!prefix.startsWith("0")) {
|
|
2759
|
-
baseValidation = GS1_COMPANY_PREFIX_VALIDATION;
|
|
2760
|
-
} else if (!prefix.startsWith("00000")) {
|
|
2761
|
-
if (!allowUPCCompanyPrefix) {
|
|
2762
|
-
throw new RangeError(i18nextGS1.t("Prefix.gs1CompanyPrefixCantStartWith0"));
|
|
2763
|
-
}
|
|
2764
|
-
baseValidation = UPC_COMPANY_PREFIX_AS_GS1_COMPANY_PREFIX_VALIDATION;
|
|
2765
|
-
} else if (!prefix.startsWith("000000")) {
|
|
2766
|
-
if (!allowGS18Prefix) {
|
|
2767
|
-
throw new RangeError(i18nextGS1.t("Prefix.gs1CompanyPrefixCantStartWith00000"));
|
|
2768
|
-
}
|
|
2769
|
-
baseValidation = GS1_8_PREFIX_AS_GS1_COMPANY_PREFIX_VALIDATION;
|
|
2770
|
-
} else {
|
|
2771
|
-
throw new RangeError(i18nextGS1.t("Prefix.gs1CompanyPrefixCantStartWith000000"));
|
|
2772
|
-
}
|
|
2773
|
-
break;
|
|
2774
|
-
case PrefixTypes.UPCCompanyPrefix:
|
|
2775
|
-
if (prefix.startsWith("0000")) {
|
|
2776
|
-
throw new RangeError(i18nextGS1.t("Prefix.upcCompanyPrefixCantStartWith0000"));
|
|
2777
|
-
}
|
|
2778
|
-
baseValidation = UPC_COMPANY_PREFIX_VALIDATION;
|
|
2779
|
-
break;
|
|
2780
|
-
case PrefixTypes.GS18Prefix:
|
|
2781
|
-
if (prefix.startsWith("0")) {
|
|
2782
|
-
throw new RangeError(i18nextGS1.t("Prefix.gs18PrefixCantStartWith0"));
|
|
2783
|
-
}
|
|
2784
|
-
baseValidation = GS1_8_PREFIX_VALIDATION;
|
|
2785
|
-
break;
|
|
2786
|
-
}
|
|
2787
|
-
const mergedValidation = {
|
|
2788
|
-
...baseValidation,
|
|
2789
|
-
positionOffset
|
|
2790
|
-
};
|
|
2791
|
-
if (!isFromIdentifier) {
|
|
2792
|
-
NUMERIC_CREATOR2.validate(prefix, mergedValidation);
|
|
2793
|
-
} else if (!isNumericIdentifier) {
|
|
2794
|
-
NUMERIC_CREATOR2.validate(prefix.substring(0, Math.min(mergedValidation.minimumLength, prefix.length - 1)), mergedValidation);
|
|
2795
|
-
}
|
|
2796
|
-
}
|
|
2797
2752
|
var PrefixValidator = {
|
|
2798
2753
|
GS1_COMPANY_PREFIX_MINIMUM_LENGTH,
|
|
2799
2754
|
GS1_COMPANY_PREFIX_MAXIMUM_LENGTH,
|
|
@@ -2801,7 +2756,139 @@ var PrefixValidator = {
|
|
|
2801
2756
|
UPC_COMPANY_PREFIX_MAXIMUM_LENGTH,
|
|
2802
2757
|
GS1_8_PREFIX_MINIMUM_LENGTH,
|
|
2803
2758
|
GS1_8_PREFIX_MAXIMUM_LENGTH,
|
|
2804
|
-
|
|
2759
|
+
/**
|
|
2760
|
+
* Validate a prefix.
|
|
2761
|
+
*
|
|
2762
|
+
* @param prefixType
|
|
2763
|
+
* Prefix type.
|
|
2764
|
+
*
|
|
2765
|
+
* @param allowUPCCompanyPrefix
|
|
2766
|
+
* If true, a U.P.C. Company Prefix expressed as a GS1 Company Prefix is permitted.
|
|
2767
|
+
*
|
|
2768
|
+
* @param allowGS18Prefix
|
|
2769
|
+
* If true, a GS1-8 Prefix expressed as a GS1 Company Prefix is permitted.
|
|
2770
|
+
*
|
|
2771
|
+
* @param prefix
|
|
2772
|
+
* Prefix.
|
|
2773
|
+
*
|
|
2774
|
+
* @param isFromIdentifier
|
|
2775
|
+
* If true, the prefix is from an identifier and should be trimmed before its character set is validated.
|
|
2776
|
+
*
|
|
2777
|
+
* @param isNumericIdentifier
|
|
2778
|
+
* If true, the prefix is from a numeric identifier and its character set will be validated by the caller.
|
|
2779
|
+
*
|
|
2780
|
+
* @param positionOffset
|
|
2781
|
+
* Position offset within a larger string.
|
|
2782
|
+
*/
|
|
2783
|
+
validate(prefixType, allowUPCCompanyPrefix, allowGS18Prefix, prefix, isFromIdentifier = false, isNumericIdentifier = false, positionOffset) {
|
|
2784
|
+
let baseValidation;
|
|
2785
|
+
switch (prefixType) {
|
|
2786
|
+
case PrefixTypes.GS1CompanyPrefix:
|
|
2787
|
+
if (!prefix.startsWith("0")) {
|
|
2788
|
+
baseValidation = GS1_COMPANY_PREFIX_VALIDATION;
|
|
2789
|
+
} else if (!prefix.startsWith("00000")) {
|
|
2790
|
+
if (!allowUPCCompanyPrefix) {
|
|
2791
|
+
throw new RangeError(i18nextGS1.t("Prefix.gs1CompanyPrefixCantStartWith0"));
|
|
2792
|
+
}
|
|
2793
|
+
baseValidation = UPC_COMPANY_PREFIX_AS_GS1_COMPANY_PREFIX_VALIDATION;
|
|
2794
|
+
} else if (!prefix.startsWith("000000")) {
|
|
2795
|
+
if (!allowGS18Prefix) {
|
|
2796
|
+
throw new RangeError(i18nextGS1.t("Prefix.gs1CompanyPrefixCantStartWith00000"));
|
|
2797
|
+
}
|
|
2798
|
+
baseValidation = GS1_8_PREFIX_AS_GS1_COMPANY_PREFIX_VALIDATION;
|
|
2799
|
+
} else {
|
|
2800
|
+
throw new RangeError(i18nextGS1.t("Prefix.gs1CompanyPrefixCantStartWith000000"));
|
|
2801
|
+
}
|
|
2802
|
+
break;
|
|
2803
|
+
case PrefixTypes.UPCCompanyPrefix:
|
|
2804
|
+
if (prefix.startsWith("0000")) {
|
|
2805
|
+
throw new RangeError(i18nextGS1.t("Prefix.upcCompanyPrefixCantStartWith0000"));
|
|
2806
|
+
}
|
|
2807
|
+
baseValidation = UPC_COMPANY_PREFIX_VALIDATION;
|
|
2808
|
+
break;
|
|
2809
|
+
case PrefixTypes.GS18Prefix:
|
|
2810
|
+
if (prefix.startsWith("0")) {
|
|
2811
|
+
throw new RangeError(i18nextGS1.t("Prefix.gs18PrefixCantStartWith0"));
|
|
2812
|
+
}
|
|
2813
|
+
baseValidation = GS1_8_PREFIX_VALIDATION;
|
|
2814
|
+
break;
|
|
2815
|
+
}
|
|
2816
|
+
const mergedValidation = {
|
|
2817
|
+
...baseValidation,
|
|
2818
|
+
positionOffset
|
|
2819
|
+
};
|
|
2820
|
+
if (!isFromIdentifier) {
|
|
2821
|
+
NUMERIC_CREATOR2.validate(prefix, mergedValidation);
|
|
2822
|
+
} else if (!isNumericIdentifier) {
|
|
2823
|
+
NUMERIC_CREATOR2.validate(prefix.substring(0, Math.min(mergedValidation.minimumLength, prefix.length - 1)), mergedValidation);
|
|
2824
|
+
}
|
|
2825
|
+
},
|
|
2826
|
+
/**
|
|
2827
|
+
* Normalize a prefix.
|
|
2828
|
+
*
|
|
2829
|
+
* @param prefixType
|
|
2830
|
+
* Prefix type.
|
|
2831
|
+
*
|
|
2832
|
+
* @param prefix
|
|
2833
|
+
* Prefix.
|
|
2834
|
+
*
|
|
2835
|
+
* @returns
|
|
2836
|
+
* Prefix provider with normalized prefix type and prefix.
|
|
2837
|
+
*/
|
|
2838
|
+
normalize(prefixType, prefix) {
|
|
2839
|
+
this.validate(prefixType, true, true, prefix);
|
|
2840
|
+
let gs1CompanyPrefix;
|
|
2841
|
+
switch (prefixType) {
|
|
2842
|
+
case PrefixTypes.GS1CompanyPrefix:
|
|
2843
|
+
gs1CompanyPrefix = prefix;
|
|
2844
|
+
break;
|
|
2845
|
+
case PrefixTypes.UPCCompanyPrefix:
|
|
2846
|
+
gs1CompanyPrefix = "0" + prefix;
|
|
2847
|
+
break;
|
|
2848
|
+
case PrefixTypes.GS18Prefix:
|
|
2849
|
+
gs1CompanyPrefix = "00000" + prefix;
|
|
2850
|
+
break;
|
|
2851
|
+
}
|
|
2852
|
+
let normalizedPrefixType;
|
|
2853
|
+
let normalizedPrefix;
|
|
2854
|
+
let upcCompanyPrefix = void 0;
|
|
2855
|
+
let gs18Prefix = void 0;
|
|
2856
|
+
if (!gs1CompanyPrefix.startsWith("0")) {
|
|
2857
|
+
normalizedPrefixType = PrefixTypes.GS1CompanyPrefix;
|
|
2858
|
+
normalizedPrefix = gs1CompanyPrefix;
|
|
2859
|
+
} else if (!gs1CompanyPrefix.startsWith("00000")) {
|
|
2860
|
+
normalizedPrefixType = PrefixTypes.UPCCompanyPrefix;
|
|
2861
|
+
upcCompanyPrefix = gs1CompanyPrefix.substring(1);
|
|
2862
|
+
normalizedPrefix = upcCompanyPrefix;
|
|
2863
|
+
} else {
|
|
2864
|
+
normalizedPrefixType = PrefixTypes.GS18Prefix;
|
|
2865
|
+
gs18Prefix = gs1CompanyPrefix.substring(5);
|
|
2866
|
+
normalizedPrefix = gs18Prefix;
|
|
2867
|
+
}
|
|
2868
|
+
return {
|
|
2869
|
+
prefixType: normalizedPrefixType,
|
|
2870
|
+
prefix: normalizedPrefix,
|
|
2871
|
+
gs1CompanyPrefix,
|
|
2872
|
+
upcCompanyPrefix,
|
|
2873
|
+
gs18Prefix
|
|
2874
|
+
};
|
|
2875
|
+
}
|
|
2876
|
+
};
|
|
2877
|
+
|
|
2878
|
+
// src/content-character-set.ts
|
|
2879
|
+
var ContentCharacterSets = {
|
|
2880
|
+
/**
|
|
2881
|
+
* Numeric.
|
|
2882
|
+
*/
|
|
2883
|
+
Numeric: "Numeric",
|
|
2884
|
+
/**
|
|
2885
|
+
* GS1 AI encodable character set 82.
|
|
2886
|
+
*/
|
|
2887
|
+
AI82: "AI82",
|
|
2888
|
+
/**
|
|
2889
|
+
* GS1 AI encodable character set 39.
|
|
2890
|
+
*/
|
|
2891
|
+
AI39: "AI39"
|
|
2805
2892
|
};
|
|
2806
2893
|
|
|
2807
2894
|
// src/identifier-type.ts
|
|
@@ -2856,24 +2943,200 @@ var IdentifierTypes = {
|
|
|
2856
2943
|
GMN: "GMN"
|
|
2857
2944
|
};
|
|
2858
2945
|
|
|
2859
|
-
// src/identifier-
|
|
2860
|
-
|
|
2861
|
-
NUMERIC_CREATOR as NUMERIC_CREATOR3
|
|
2862
|
-
} from "@aidc-toolkit/utility";
|
|
2863
|
-
var ContentCharacterSets = {
|
|
2946
|
+
// src/numeric-identifier-type.ts
|
|
2947
|
+
var LeaderTypes = {
|
|
2864
2948
|
/**
|
|
2865
|
-
*
|
|
2949
|
+
* No leader.
|
|
2866
2950
|
*/
|
|
2867
|
-
|
|
2951
|
+
None: "None",
|
|
2868
2952
|
/**
|
|
2869
|
-
*
|
|
2953
|
+
* Indicator digit (GTIN only).
|
|
2870
2954
|
*/
|
|
2871
|
-
|
|
2955
|
+
IndicatorDigit: "Indicator digit",
|
|
2872
2956
|
/**
|
|
2873
|
-
*
|
|
2957
|
+
* Extension digit (SSCC only).
|
|
2874
2958
|
*/
|
|
2875
|
-
|
|
2959
|
+
ExtensionDigit: "Extension digit"
|
|
2960
|
+
};
|
|
2961
|
+
|
|
2962
|
+
// src/gtin-type.ts
|
|
2963
|
+
var GTINTypes = {
|
|
2964
|
+
/**
|
|
2965
|
+
* GTIN-13.
|
|
2966
|
+
*/
|
|
2967
|
+
GTIN13: 13,
|
|
2968
|
+
/**
|
|
2969
|
+
* GTIN-12.
|
|
2970
|
+
*/
|
|
2971
|
+
GTIN12: 12,
|
|
2972
|
+
/**
|
|
2973
|
+
* GTIN-8.
|
|
2974
|
+
*/
|
|
2975
|
+
GTIN8: 8,
|
|
2976
|
+
/**
|
|
2977
|
+
* GTIN-14.
|
|
2978
|
+
*/
|
|
2979
|
+
GTIN14: 14
|
|
2980
|
+
};
|
|
2981
|
+
var GTIN_BASE_TYPES = {
|
|
2982
|
+
[PrefixTypes.GS1CompanyPrefix]: GTINTypes.GTIN13,
|
|
2983
|
+
[PrefixTypes.UPCCompanyPrefix]: GTINTypes.GTIN12,
|
|
2984
|
+
[PrefixTypes.GS18Prefix]: GTINTypes.GTIN8
|
|
2985
|
+
};
|
|
2986
|
+
|
|
2987
|
+
// src/descriptors.ts
|
|
2988
|
+
var GTIN13_DESCRIPTOR = {
|
|
2989
|
+
identifierType: IdentifierTypes.GTIN,
|
|
2990
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
2991
|
+
length: GTINTypes.GTIN13,
|
|
2992
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
2993
|
+
leaderType: LeaderTypes.IndicatorDigit
|
|
2876
2994
|
};
|
|
2995
|
+
var GTIN12_DESCRIPTOR = {
|
|
2996
|
+
identifierType: IdentifierTypes.GTIN,
|
|
2997
|
+
prefixType: PrefixTypes.UPCCompanyPrefix,
|
|
2998
|
+
length: GTINTypes.GTIN12,
|
|
2999
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
3000
|
+
leaderType: LeaderTypes.IndicatorDigit
|
|
3001
|
+
};
|
|
3002
|
+
var GTIN8_DESCRIPTOR = {
|
|
3003
|
+
identifierType: IdentifierTypes.GTIN,
|
|
3004
|
+
prefixType: PrefixTypes.GS18Prefix,
|
|
3005
|
+
length: GTINTypes.GTIN8,
|
|
3006
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
3007
|
+
leaderType: LeaderTypes.IndicatorDigit
|
|
3008
|
+
};
|
|
3009
|
+
var GTIN_DESCRIPTORS = {
|
|
3010
|
+
[GTINTypes.GTIN13]: GTIN13_DESCRIPTOR,
|
|
3011
|
+
[GTINTypes.GTIN12]: GTIN12_DESCRIPTOR,
|
|
3012
|
+
[GTINTypes.GTIN8]: GTIN8_DESCRIPTOR
|
|
3013
|
+
};
|
|
3014
|
+
var GLN_DESCRIPTOR = {
|
|
3015
|
+
identifierType: IdentifierTypes.GLN,
|
|
3016
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3017
|
+
length: 13,
|
|
3018
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
3019
|
+
leaderType: LeaderTypes.None
|
|
3020
|
+
};
|
|
3021
|
+
var SSCC_DESCRIPTOR = {
|
|
3022
|
+
identifierType: IdentifierTypes.SSCC,
|
|
3023
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3024
|
+
length: 18,
|
|
3025
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
3026
|
+
leaderType: LeaderTypes.ExtensionDigit
|
|
3027
|
+
};
|
|
3028
|
+
var GRAI_DESCRIPTOR = {
|
|
3029
|
+
identifierType: IdentifierTypes.GRAI,
|
|
3030
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3031
|
+
length: 13,
|
|
3032
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
3033
|
+
leaderType: LeaderTypes.None,
|
|
3034
|
+
serialComponentLength: 16,
|
|
3035
|
+
serialComponentCharacterSet: ContentCharacterSets.AI82
|
|
3036
|
+
};
|
|
3037
|
+
var GIAI_DESCRIPTOR = {
|
|
3038
|
+
identifierType: IdentifierTypes.GIAI,
|
|
3039
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3040
|
+
length: 30,
|
|
3041
|
+
referenceCharacterSet: ContentCharacterSets.AI82,
|
|
3042
|
+
requiresCheckCharacterPair: false
|
|
3043
|
+
};
|
|
3044
|
+
var GSRN_DESCRIPTOR = {
|
|
3045
|
+
identifierType: IdentifierTypes.GSRN,
|
|
3046
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3047
|
+
length: 18,
|
|
3048
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
3049
|
+
leaderType: LeaderTypes.None
|
|
3050
|
+
};
|
|
3051
|
+
var GDTI_DESCRIPTOR = {
|
|
3052
|
+
identifierType: IdentifierTypes.GDTI,
|
|
3053
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3054
|
+
length: 13,
|
|
3055
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
3056
|
+
leaderType: LeaderTypes.None,
|
|
3057
|
+
serialComponentLength: 17,
|
|
3058
|
+
serialComponentCharacterSet: ContentCharacterSets.AI82
|
|
3059
|
+
};
|
|
3060
|
+
var GINC_DESCRIPTOR = {
|
|
3061
|
+
identifierType: IdentifierTypes.GINC,
|
|
3062
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3063
|
+
length: 30,
|
|
3064
|
+
referenceCharacterSet: ContentCharacterSets.AI82,
|
|
3065
|
+
requiresCheckCharacterPair: false
|
|
3066
|
+
};
|
|
3067
|
+
var GSIN_DESCRIPTOR = {
|
|
3068
|
+
identifierType: IdentifierTypes.GSIN,
|
|
3069
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3070
|
+
length: 17,
|
|
3071
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
3072
|
+
leaderType: LeaderTypes.None
|
|
3073
|
+
};
|
|
3074
|
+
var GCN_DESCRIPTOR = {
|
|
3075
|
+
identifierType: IdentifierTypes.GCN,
|
|
3076
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3077
|
+
length: 13,
|
|
3078
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
3079
|
+
leaderType: LeaderTypes.None,
|
|
3080
|
+
serialComponentLength: 12,
|
|
3081
|
+
serialComponentCharacterSet: ContentCharacterSets.Numeric
|
|
3082
|
+
};
|
|
3083
|
+
var CPID_DESCRIPTOR = {
|
|
3084
|
+
identifierType: IdentifierTypes.CPID,
|
|
3085
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3086
|
+
length: 30,
|
|
3087
|
+
referenceCharacterSet: ContentCharacterSets.AI39,
|
|
3088
|
+
requiresCheckCharacterPair: false
|
|
3089
|
+
};
|
|
3090
|
+
var GMN_DESCRIPTOR = {
|
|
3091
|
+
identifierType: IdentifierTypes.GMN,
|
|
3092
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3093
|
+
length: 25,
|
|
3094
|
+
referenceCharacterSet: ContentCharacterSets.AI82,
|
|
3095
|
+
requiresCheckCharacterPair: true
|
|
3096
|
+
};
|
|
3097
|
+
var IdentifierDescriptors = {
|
|
3098
|
+
[IdentifierTypes.GTIN]: GTIN_DESCRIPTORS,
|
|
3099
|
+
[IdentifierTypes.GLN]: GLN_DESCRIPTOR,
|
|
3100
|
+
[IdentifierTypes.SSCC]: SSCC_DESCRIPTOR,
|
|
3101
|
+
[IdentifierTypes.GRAI]: GRAI_DESCRIPTOR,
|
|
3102
|
+
[IdentifierTypes.GIAI]: GIAI_DESCRIPTOR,
|
|
3103
|
+
[IdentifierTypes.GSRN]: GSRN_DESCRIPTOR,
|
|
3104
|
+
[IdentifierTypes.GDTI]: GDTI_DESCRIPTOR,
|
|
3105
|
+
[IdentifierTypes.GINC]: GINC_DESCRIPTOR,
|
|
3106
|
+
[IdentifierTypes.GSIN]: GSIN_DESCRIPTOR,
|
|
3107
|
+
[IdentifierTypes.GCN]: GCN_DESCRIPTOR,
|
|
3108
|
+
[IdentifierTypes.CPID]: CPID_DESCRIPTOR,
|
|
3109
|
+
[IdentifierTypes.GMN]: GMN_DESCRIPTOR
|
|
3110
|
+
};
|
|
3111
|
+
function isGTINDescriptors(identifierDescriptorsOrDescriptor) {
|
|
3112
|
+
return !("identifierType" in identifierDescriptorsOrDescriptor);
|
|
3113
|
+
}
|
|
3114
|
+
function identifierTypesIncludes(identifierTypes, identifierType) {
|
|
3115
|
+
return identifierTypes.includes(identifierType);
|
|
3116
|
+
}
|
|
3117
|
+
var NUMERIC_IDENTIFIER_TYPES = [IdentifierTypes.GTIN, IdentifierTypes.GLN, IdentifierTypes.SSCC, IdentifierTypes.GRAI, IdentifierTypes.GSRN, IdentifierTypes.GDTI, IdentifierTypes.GSIN, IdentifierTypes.GCN];
|
|
3118
|
+
function isNumericIdentifierDescriptor(identifierDescriptor) {
|
|
3119
|
+
return identifierTypesIncludes(NUMERIC_IDENTIFIER_TYPES, identifierDescriptor.identifierType);
|
|
3120
|
+
}
|
|
3121
|
+
function isGTINDescriptor(identifierDescriptor) {
|
|
3122
|
+
return identifierDescriptor.identifierType === IdentifierTypes.GTIN;
|
|
3123
|
+
}
|
|
3124
|
+
function isNonGTINNumericIdentifierDescriptor(identifierDescriptor) {
|
|
3125
|
+
return isNumericIdentifierDescriptor(identifierDescriptor) && !isGTINDescriptor(identifierDescriptor);
|
|
3126
|
+
}
|
|
3127
|
+
var SERIALIZABLE_NUMERIC_IDENTIFIER_TYPES = [IdentifierTypes.GRAI, IdentifierTypes.GDTI, IdentifierTypes.GCN];
|
|
3128
|
+
function isSerializableNumericIdentifierDescriptor(identifierDescriptor) {
|
|
3129
|
+
return identifierTypesIncludes(SERIALIZABLE_NUMERIC_IDENTIFIER_TYPES, identifierDescriptor.identifierType);
|
|
3130
|
+
}
|
|
3131
|
+
function isNonNumericIdentifierDescriptor(identifierDescriptor) {
|
|
3132
|
+
return !isNumericIdentifierDescriptor(identifierDescriptor);
|
|
3133
|
+
}
|
|
3134
|
+
|
|
3135
|
+
// src/gtin-validator.ts
|
|
3136
|
+
import { NUMERIC_CREATOR as NUMERIC_CREATOR4 } from "@aidc-toolkit/utility";
|
|
3137
|
+
|
|
3138
|
+
// src/abstract-identifier-validator.ts
|
|
3139
|
+
import { NUMERIC_CREATOR as NUMERIC_CREATOR3 } from "@aidc-toolkit/utility";
|
|
2877
3140
|
var AbstractIdentifierValidator = class _AbstractIdentifierValidator {
|
|
2878
3141
|
static CHARACTER_SET_CREATORS = {
|
|
2879
3142
|
[ContentCharacterSets.Numeric]: NUMERIC_CREATOR3,
|
|
@@ -2884,10 +3147,6 @@ var AbstractIdentifierValidator = class _AbstractIdentifierValidator {
|
|
|
2884
3147
|
* Identifier type.
|
|
2885
3148
|
*/
|
|
2886
3149
|
_identifierType;
|
|
2887
|
-
/**
|
|
2888
|
-
* Prefix type.
|
|
2889
|
-
*/
|
|
2890
|
-
_prefixType;
|
|
2891
3150
|
/**
|
|
2892
3151
|
* Length.
|
|
2893
3152
|
*/
|
|
@@ -2915,24 +3174,14 @@ var AbstractIdentifierValidator = class _AbstractIdentifierValidator {
|
|
|
2915
3174
|
/**
|
|
2916
3175
|
* Constructor.
|
|
2917
3176
|
*
|
|
2918
|
-
* @param
|
|
2919
|
-
* Identifier
|
|
2920
|
-
*
|
|
2921
|
-
* @param prefixType
|
|
2922
|
-
* Prefix type.
|
|
2923
|
-
*
|
|
2924
|
-
* @param length
|
|
2925
|
-
* Length.
|
|
2926
|
-
*
|
|
2927
|
-
* @param referenceCharacterSet
|
|
2928
|
-
* Reference character set.
|
|
3177
|
+
* @param identifierDescriptor
|
|
3178
|
+
* Identifier descriptor.
|
|
2929
3179
|
*/
|
|
2930
|
-
constructor(
|
|
2931
|
-
this._identifierType = identifierType;
|
|
2932
|
-
this.
|
|
2933
|
-
this.
|
|
2934
|
-
this.
|
|
2935
|
-
this._referenceCreator = _AbstractIdentifierValidator.creatorFor(referenceCharacterSet);
|
|
3180
|
+
constructor(identifierDescriptor) {
|
|
3181
|
+
this._identifierType = identifierDescriptor.identifierType;
|
|
3182
|
+
this._length = identifierDescriptor.length;
|
|
3183
|
+
this._referenceCharacterSet = identifierDescriptor.referenceCharacterSet;
|
|
3184
|
+
this._referenceCreator = _AbstractIdentifierValidator.creatorFor(identifierDescriptor.referenceCharacterSet);
|
|
2936
3185
|
}
|
|
2937
3186
|
/**
|
|
2938
3187
|
* @inheritDoc
|
|
@@ -2944,7 +3193,7 @@ var AbstractIdentifierValidator = class _AbstractIdentifierValidator {
|
|
|
2944
3193
|
* @inheritDoc
|
|
2945
3194
|
*/
|
|
2946
3195
|
get prefixType() {
|
|
2947
|
-
return
|
|
3196
|
+
return PrefixTypes.GS1CompanyPrefix;
|
|
2948
3197
|
}
|
|
2949
3198
|
/**
|
|
2950
3199
|
* @inheritDoc
|
|
@@ -2971,14 +3220,14 @@ var AbstractIdentifierValidator = class _AbstractIdentifierValidator {
|
|
|
2971
3220
|
* @param identifier
|
|
2972
3221
|
* Identifier.
|
|
2973
3222
|
*
|
|
2974
|
-
* @param
|
|
2975
|
-
*
|
|
3223
|
+
* @param positionOffset
|
|
3224
|
+
* Position offset within a larger string.
|
|
2976
3225
|
*
|
|
2977
3226
|
* @returns
|
|
2978
3227
|
* Padded identifier.
|
|
2979
3228
|
*/
|
|
2980
|
-
padIdentifier(identifier,
|
|
2981
|
-
return
|
|
3229
|
+
padIdentifier(identifier, positionOffset) {
|
|
3230
|
+
return positionOffset === void 0 ? identifier : this.referenceCreator.character(0).repeat(positionOffset).concat(identifier);
|
|
2982
3231
|
}
|
|
2983
3232
|
/**
|
|
2984
3233
|
* Validate the prefix within an identifier.
|
|
@@ -2994,21 +3243,7 @@ var AbstractIdentifierValidator = class _AbstractIdentifierValidator {
|
|
|
2994
3243
|
}
|
|
2995
3244
|
};
|
|
2996
3245
|
|
|
2997
|
-
// src/numeric-identifier-validator.ts
|
|
2998
|
-
var LeaderTypes = {
|
|
2999
|
-
/**
|
|
3000
|
-
* No leader.
|
|
3001
|
-
*/
|
|
3002
|
-
None: "None",
|
|
3003
|
-
/**
|
|
3004
|
-
* Indicator digit (GTIN only).
|
|
3005
|
-
*/
|
|
3006
|
-
IndicatorDigit: "Indicator digit",
|
|
3007
|
-
/**
|
|
3008
|
-
* Extension digit (SSCC only).
|
|
3009
|
-
*/
|
|
3010
|
-
ExtensionDigit: "Extension digit"
|
|
3011
|
-
};
|
|
3246
|
+
// src/abstract-numeric-identifier-validator.ts
|
|
3012
3247
|
var AbstractNumericIdentifierValidator = class extends AbstractIdentifierValidator {
|
|
3013
3248
|
/**
|
|
3014
3249
|
* Leader type.
|
|
@@ -3021,21 +3256,12 @@ var AbstractNumericIdentifierValidator = class extends AbstractIdentifierValidat
|
|
|
3021
3256
|
/**
|
|
3022
3257
|
* Constructor.
|
|
3023
3258
|
*
|
|
3024
|
-
* @param
|
|
3025
|
-
* Identifier
|
|
3026
|
-
*
|
|
3027
|
-
* @param prefixType
|
|
3028
|
-
* Prefix type.
|
|
3029
|
-
*
|
|
3030
|
-
* @param length
|
|
3031
|
-
* Length.
|
|
3032
|
-
*
|
|
3033
|
-
* @param leaderType
|
|
3034
|
-
* Leader type.
|
|
3259
|
+
* @param identifierDescriptor
|
|
3260
|
+
* Identifier descriptor.
|
|
3035
3261
|
*/
|
|
3036
|
-
constructor(
|
|
3037
|
-
super(
|
|
3038
|
-
this._leaderType = leaderType;
|
|
3262
|
+
constructor(identifierDescriptor) {
|
|
3263
|
+
super(identifierDescriptor);
|
|
3264
|
+
this._leaderType = identifierDescriptor.leaderType;
|
|
3039
3265
|
this._prefixPosition = Number(this.leaderType === LeaderTypes.ExtensionDigit);
|
|
3040
3266
|
}
|
|
3041
3267
|
/**
|
|
@@ -3059,32 +3285,13 @@ var AbstractNumericIdentifierValidator = class extends AbstractIdentifierValidat
|
|
|
3059
3285
|
length: this.length
|
|
3060
3286
|
}));
|
|
3061
3287
|
}
|
|
3062
|
-
if (!hasValidCheckDigit(this.padIdentifier(identifier, validation))) {
|
|
3288
|
+
if (!hasValidCheckDigit(this.padIdentifier(identifier, validation?.positionOffset))) {
|
|
3063
3289
|
throw new RangeError(i18nextGS1.t("Identifier.invalidCheckDigit"));
|
|
3064
3290
|
}
|
|
3065
3291
|
}
|
|
3066
3292
|
};
|
|
3067
3293
|
|
|
3068
3294
|
// src/gtin-validator.ts
|
|
3069
|
-
import { NUMERIC_CREATOR as NUMERIC_CREATOR4 } from "@aidc-toolkit/utility";
|
|
3070
|
-
var GTINTypes = {
|
|
3071
|
-
/**
|
|
3072
|
-
* GTIN-13.
|
|
3073
|
-
*/
|
|
3074
|
-
GTIN13: 13,
|
|
3075
|
-
/**
|
|
3076
|
-
* GTIN-12.
|
|
3077
|
-
*/
|
|
3078
|
-
GTIN12: 12,
|
|
3079
|
-
/**
|
|
3080
|
-
* GTIN-8.
|
|
3081
|
-
*/
|
|
3082
|
-
GTIN8: 8,
|
|
3083
|
-
/**
|
|
3084
|
-
* GTIN-14.
|
|
3085
|
-
*/
|
|
3086
|
-
GTIN14: 14
|
|
3087
|
-
};
|
|
3088
3295
|
var GTINLevels = {
|
|
3089
3296
|
/**
|
|
3090
3297
|
* Any level (level is ignored).
|
|
@@ -3115,28 +3322,26 @@ var GTINValidator = class _GTINValidator extends AbstractNumericIdentifierValida
|
|
|
3115
3322
|
minimumLength: 8,
|
|
3116
3323
|
maximumLength: 8
|
|
3117
3324
|
};
|
|
3325
|
+
/**
|
|
3326
|
+
* Prefix type.
|
|
3327
|
+
*/
|
|
3328
|
+
_prefixType;
|
|
3118
3329
|
/**
|
|
3119
3330
|
* Constructor.
|
|
3120
3331
|
*
|
|
3121
|
-
* @param
|
|
3122
|
-
* GTIN type.
|
|
3332
|
+
* @param gtinBaseType
|
|
3333
|
+
* GTIN base type (all except GTIN-14).
|
|
3123
3334
|
*/
|
|
3124
|
-
constructor(
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
prefixType = PrefixTypes.GS18Prefix;
|
|
3135
|
-
break;
|
|
3136
|
-
default:
|
|
3137
|
-
throw new Error("Not supported");
|
|
3138
|
-
}
|
|
3139
|
-
super(IdentifierTypes.GTIN, prefixType, gtinType, LeaderTypes.IndicatorDigit);
|
|
3335
|
+
constructor(gtinBaseType) {
|
|
3336
|
+
const identifierDescriptor = IdentifierDescriptors.GTIN[gtinBaseType];
|
|
3337
|
+
super(identifierDescriptor);
|
|
3338
|
+
this._prefixType = identifierDescriptor.prefixType;
|
|
3339
|
+
}
|
|
3340
|
+
/**
|
|
3341
|
+
* @inheritDoc
|
|
3342
|
+
*/
|
|
3343
|
+
get prefixType() {
|
|
3344
|
+
return this._prefixType;
|
|
3140
3345
|
}
|
|
3141
3346
|
/**
|
|
3142
3347
|
* @inheritDoc
|
|
@@ -3453,9 +3658,9 @@ var GTIN13_VALIDATOR = new GTINValidator(GTINTypes.GTIN13);
|
|
|
3453
3658
|
var GTIN12_VALIDATOR = new GTINValidator(GTINTypes.GTIN12);
|
|
3454
3659
|
var GTIN8_VALIDATOR = new GTINValidator(GTINTypes.GTIN8);
|
|
3455
3660
|
var GTIN_VALIDATORS = {
|
|
3456
|
-
[
|
|
3457
|
-
[
|
|
3458
|
-
[
|
|
3661
|
+
[GTINTypes.GTIN13]: GTIN13_VALIDATOR,
|
|
3662
|
+
[GTINTypes.GTIN12]: GTIN12_VALIDATOR,
|
|
3663
|
+
[GTINTypes.GTIN8]: GTIN8_VALIDATOR
|
|
3459
3664
|
};
|
|
3460
3665
|
|
|
3461
3666
|
// src/non-gtin-numeric-identifier-validator.ts
|
|
@@ -3465,24 +3670,14 @@ var NonGTINNumericIdentifierValidator = class extends AbstractNumericIdentifierV
|
|
|
3465
3670
|
*
|
|
3466
3671
|
* @param identifierType
|
|
3467
3672
|
* Identifier type.
|
|
3468
|
-
*
|
|
3469
|
-
* @param length
|
|
3470
|
-
* Length.
|
|
3471
|
-
*
|
|
3472
|
-
* @param leaderType
|
|
3473
|
-
* Leader type.
|
|
3474
3673
|
*/
|
|
3475
|
-
constructor(identifierType
|
|
3476
|
-
super(identifierType
|
|
3674
|
+
constructor(identifierType) {
|
|
3675
|
+
super(IdentifierDescriptors[identifierType]);
|
|
3477
3676
|
}
|
|
3478
3677
|
};
|
|
3479
|
-
var GLN_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.GLN, 13);
|
|
3480
|
-
var SSCC_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.SSCC, 18, LeaderTypes.ExtensionDigit);
|
|
3481
|
-
var GSRN_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.GSRN, 18);
|
|
3482
|
-
var GSIN_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.GSIN, 17);
|
|
3483
3678
|
|
|
3484
3679
|
// src/serializable-numeric-identifier-validator.ts
|
|
3485
|
-
var SerializableNumericIdentifierValidator = class _SerializableNumericIdentifierValidator extends
|
|
3680
|
+
var SerializableNumericIdentifierValidator = class _SerializableNumericIdentifierValidator extends AbstractNumericIdentifierValidator {
|
|
3486
3681
|
/**
|
|
3487
3682
|
* Serial component length.
|
|
3488
3683
|
*/
|
|
@@ -3504,26 +3699,18 @@ var SerializableNumericIdentifierValidator = class _SerializableNumericIdentifie
|
|
|
3504
3699
|
*
|
|
3505
3700
|
* @param identifierType
|
|
3506
3701
|
* Identifier type.
|
|
3507
|
-
*
|
|
3508
|
-
* @param length
|
|
3509
|
-
* Length.
|
|
3510
|
-
*
|
|
3511
|
-
* @param serialComponentLength
|
|
3512
|
-
* Serial component length.
|
|
3513
|
-
*
|
|
3514
|
-
* @param serialComponentCharacterSet
|
|
3515
|
-
* Serial component character set.
|
|
3516
3702
|
*/
|
|
3517
|
-
constructor(identifierType
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
this.
|
|
3703
|
+
constructor(identifierType) {
|
|
3704
|
+
const identifierDescriptor = IdentifierDescriptors[identifierType];
|
|
3705
|
+
super(identifierDescriptor);
|
|
3706
|
+
this._serialComponentLength = identifierDescriptor.serialComponentLength;
|
|
3707
|
+
this._serialComponentCharacterSet = identifierDescriptor.serialComponentCharacterSet;
|
|
3521
3708
|
this._serialComponentValidation = {
|
|
3522
3709
|
minimumLength: 1,
|
|
3523
|
-
maximumLength: serialComponentLength,
|
|
3710
|
+
maximumLength: identifierDescriptor.serialComponentLength,
|
|
3524
3711
|
component: () => i18nextGS1.t("Identifier.serialComponent")
|
|
3525
3712
|
};
|
|
3526
|
-
this._serialComponentCreator = _SerializableNumericIdentifierValidator.creatorFor(serialComponentCharacterSet);
|
|
3713
|
+
this._serialComponentCreator = _SerializableNumericIdentifierValidator.creatorFor(identifierDescriptor.serialComponentCharacterSet);
|
|
3527
3714
|
}
|
|
3528
3715
|
/**
|
|
3529
3716
|
* Get the serial component length.
|
|
@@ -3559,9 +3746,6 @@ var SerializableNumericIdentifierValidator = class _SerializableNumericIdentifie
|
|
|
3559
3746
|
}
|
|
3560
3747
|
}
|
|
3561
3748
|
};
|
|
3562
|
-
var GRAI_VALIDATOR = new SerializableNumericIdentifierValidator(IdentifierTypes.GRAI, 13, 16, ContentCharacterSets.AI82);
|
|
3563
|
-
var GDTI_VALIDATOR = new SerializableNumericIdentifierValidator(IdentifierTypes.GDTI, 13, 17, ContentCharacterSets.AI82);
|
|
3564
|
-
var GCN_VALIDATOR = new SerializableNumericIdentifierValidator(IdentifierTypes.GCN, 13, 12, ContentCharacterSets.Numeric);
|
|
3565
3749
|
|
|
3566
3750
|
// src/non-numeric-identifier-validator.ts
|
|
3567
3751
|
import { Exclusions as Exclusions2, RegExpValidator } from "@aidc-toolkit/utility";
|
|
@@ -3586,19 +3770,11 @@ var NonNumericIdentifierValidator = class _NonNumericIdentifierValidator extends
|
|
|
3586
3770
|
*
|
|
3587
3771
|
* @param identifierType
|
|
3588
3772
|
* Identifier type.
|
|
3589
|
-
*
|
|
3590
|
-
* @param length
|
|
3591
|
-
* Length.
|
|
3592
|
-
*
|
|
3593
|
-
* @param referenceCharacterSet
|
|
3594
|
-
* Reference character set.
|
|
3595
|
-
*
|
|
3596
|
-
* @param requiresCheckCharacterPair
|
|
3597
|
-
* True if the identifier requires a check character pair.
|
|
3598
3773
|
*/
|
|
3599
|
-
constructor(identifierType
|
|
3600
|
-
|
|
3601
|
-
|
|
3774
|
+
constructor(identifierType) {
|
|
3775
|
+
const identifierDescriptor = IdentifierDescriptors[identifierType];
|
|
3776
|
+
super(identifierDescriptor);
|
|
3777
|
+
this._requiresCheckCharacterPair = identifierDescriptor.requiresCheckCharacterPair;
|
|
3602
3778
|
}
|
|
3603
3779
|
/**
|
|
3604
3780
|
* Determine if the identifier requires a check character pair.
|
|
@@ -3617,13 +3793,12 @@ var NonNumericIdentifierValidator = class _NonNumericIdentifierValidator extends
|
|
|
3617
3793
|
*/
|
|
3618
3794
|
validate(identifier, validation) {
|
|
3619
3795
|
const partialIdentifier = this.requiresCheckCharacterPair ? identifier.substring(0, identifier.length - 2) : identifier;
|
|
3620
|
-
super.validatePrefix(partialIdentifier
|
|
3796
|
+
super.validatePrefix(partialIdentifier);
|
|
3621
3797
|
if (!this.requiresCheckCharacterPair) {
|
|
3622
3798
|
this.referenceCreator.validate(identifier, {
|
|
3623
|
-
maximumLength: this.length
|
|
3624
|
-
positionOffset: validation?.positionOffset
|
|
3799
|
+
maximumLength: this.length
|
|
3625
3800
|
});
|
|
3626
|
-
} else if (!hasValidCheckCharacterPair(this.padIdentifier(identifier
|
|
3801
|
+
} else if (!hasValidCheckCharacterPair(this.padIdentifier(identifier))) {
|
|
3627
3802
|
throw new RangeError(i18nextGS1.t("Identifier.invalidCheckCharacterPair"));
|
|
3628
3803
|
}
|
|
3629
3804
|
if (validation?.exclusion === Exclusions2.AllNumeric) {
|
|
@@ -3631,12 +3806,67 @@ var NonNumericIdentifierValidator = class _NonNumericIdentifierValidator extends
|
|
|
3631
3806
|
}
|
|
3632
3807
|
}
|
|
3633
3808
|
};
|
|
3634
|
-
var GIAI_VALIDATOR = new NonNumericIdentifierValidator(IdentifierTypes.GIAI, 30, ContentCharacterSets.AI82);
|
|
3635
|
-
var GINC_VALIDATOR = new NonNumericIdentifierValidator(IdentifierTypes.GINC, 30, ContentCharacterSets.AI82);
|
|
3636
|
-
var CPID_VALIDATOR = new NonNumericIdentifierValidator(IdentifierTypes.CPID, 30, ContentCharacterSets.AI39);
|
|
3637
|
-
var GMN_VALIDATOR = new NonNumericIdentifierValidator(IdentifierTypes.GMN, 25, ContentCharacterSets.AI82, true);
|
|
3638
3809
|
|
|
3639
|
-
// src/
|
|
3810
|
+
// src/validators.ts
|
|
3811
|
+
var GLN_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.GLN);
|
|
3812
|
+
var SSCC_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.SSCC);
|
|
3813
|
+
var GRAI_VALIDATOR = new SerializableNumericIdentifierValidator(IdentifierTypes.GRAI);
|
|
3814
|
+
var GIAI_VALIDATOR = new NonNumericIdentifierValidator(IdentifierTypes.GIAI);
|
|
3815
|
+
var GSRN_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.GSRN);
|
|
3816
|
+
var GDTI_VALIDATOR = new SerializableNumericIdentifierValidator(IdentifierTypes.GDTI);
|
|
3817
|
+
var GINC_VALIDATOR = new NonNumericIdentifierValidator(IdentifierTypes.GINC);
|
|
3818
|
+
var GSIN_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.GSIN);
|
|
3819
|
+
var GCN_VALIDATOR = new SerializableNumericIdentifierValidator(IdentifierTypes.GCN);
|
|
3820
|
+
var CPID_VALIDATOR = new NonNumericIdentifierValidator(IdentifierTypes.CPID);
|
|
3821
|
+
var GMN_VALIDATOR = new NonNumericIdentifierValidator(IdentifierTypes.GMN);
|
|
3822
|
+
var IdentifierValidators = {
|
|
3823
|
+
[IdentifierTypes.GTIN]: GTIN_VALIDATORS,
|
|
3824
|
+
[IdentifierTypes.GLN]: GLN_VALIDATOR,
|
|
3825
|
+
[IdentifierTypes.SSCC]: SSCC_VALIDATOR,
|
|
3826
|
+
[IdentifierTypes.GRAI]: GRAI_VALIDATOR,
|
|
3827
|
+
[IdentifierTypes.GIAI]: GIAI_VALIDATOR,
|
|
3828
|
+
[IdentifierTypes.GSRN]: GSRN_VALIDATOR,
|
|
3829
|
+
[IdentifierTypes.GDTI]: GDTI_VALIDATOR,
|
|
3830
|
+
[IdentifierTypes.GINC]: GINC_VALIDATOR,
|
|
3831
|
+
[IdentifierTypes.GSIN]: GSIN_VALIDATOR,
|
|
3832
|
+
[IdentifierTypes.GCN]: GCN_VALIDATOR,
|
|
3833
|
+
[IdentifierTypes.CPID]: CPID_VALIDATOR,
|
|
3834
|
+
[IdentifierTypes.GMN]: GMN_VALIDATOR
|
|
3835
|
+
};
|
|
3836
|
+
function isGTINValidators(identifierValidatorsOrValidator) {
|
|
3837
|
+
return isGTINDescriptors(identifierValidatorsOrValidator);
|
|
3838
|
+
}
|
|
3839
|
+
function isNumericIdentifierValidator(identifierValidator) {
|
|
3840
|
+
return isNumericIdentifierDescriptor(identifierValidator);
|
|
3841
|
+
}
|
|
3842
|
+
function isGTINValidator(identifierValidator) {
|
|
3843
|
+
return isGTINDescriptor(identifierValidator);
|
|
3844
|
+
}
|
|
3845
|
+
function isNonGTINNumericIdentifierValidator(identifierValidator) {
|
|
3846
|
+
return isNonGTINNumericIdentifierDescriptor(identifierValidator);
|
|
3847
|
+
}
|
|
3848
|
+
function isSerializableNumericIdentifierValidator(identifierValidator) {
|
|
3849
|
+
return isSerializableNumericIdentifierDescriptor(identifierValidator);
|
|
3850
|
+
}
|
|
3851
|
+
function isNonNumericIdentifierValidator(identifierValidator) {
|
|
3852
|
+
return isNonNumericIdentifierDescriptor(identifierValidator);
|
|
3853
|
+
}
|
|
3854
|
+
|
|
3855
|
+
// src/gtin-creator.ts
|
|
3856
|
+
import {
|
|
3857
|
+
Exclusions as Exclusions4,
|
|
3858
|
+
NUMERIC_CREATOR as NUMERIC_CREATOR6
|
|
3859
|
+
} from "@aidc-toolkit/utility";
|
|
3860
|
+
import { Mixin } from "ts-mixer";
|
|
3861
|
+
|
|
3862
|
+
// src/abstract-numeric-identifier-creator.ts
|
|
3863
|
+
import {
|
|
3864
|
+
CharacterSetCreator as CharacterSetCreator2,
|
|
3865
|
+
Exclusions as Exclusions3,
|
|
3866
|
+
NUMERIC_CREATOR as NUMERIC_CREATOR5
|
|
3867
|
+
} from "@aidc-toolkit/utility";
|
|
3868
|
+
|
|
3869
|
+
// src/abstract-identifier-creator.ts
|
|
3640
3870
|
var AbstractIdentifierCreator = class {
|
|
3641
3871
|
/**
|
|
3642
3872
|
* Prefix provider.
|
|
@@ -3647,13 +3877,13 @@ var AbstractIdentifierCreator = class {
|
|
|
3647
3877
|
*/
|
|
3648
3878
|
_referenceLength;
|
|
3649
3879
|
/**
|
|
3650
|
-
* Initialize the prefix
|
|
3880
|
+
* Initialize the prefix provider. This method is in lieu of a constructor due to the mixin architecture.
|
|
3651
3881
|
*
|
|
3652
3882
|
* @param prefixProvider
|
|
3653
3883
|
* Prefix provider.
|
|
3654
3884
|
*
|
|
3655
3885
|
* @param prefix
|
|
3656
|
-
* Prefix within prefix
|
|
3886
|
+
* Prefix within prefix provider to use to calculate reference length.
|
|
3657
3887
|
*
|
|
3658
3888
|
* @param checkAllowance
|
|
3659
3889
|
* Number of characters to allow for check digit or check character pair.
|
|
@@ -3682,12 +3912,7 @@ var AbstractIdentifierCreator = class {
|
|
|
3682
3912
|
}
|
|
3683
3913
|
};
|
|
3684
3914
|
|
|
3685
|
-
// src/numeric-identifier-creator.ts
|
|
3686
|
-
import {
|
|
3687
|
-
CharacterSetCreator as CharacterSetCreator2,
|
|
3688
|
-
Exclusions as Exclusions3,
|
|
3689
|
-
NUMERIC_CREATOR as NUMERIC_CREATOR5
|
|
3690
|
-
} from "@aidc-toolkit/utility";
|
|
3915
|
+
// src/abstract-numeric-identifier-creator.ts
|
|
3691
3916
|
var AbstractNumericIdentifierCreator = class _AbstractNumericIdentifierCreator extends AbstractIdentifierCreator {
|
|
3692
3917
|
/**
|
|
3693
3918
|
* Capacity.
|
|
@@ -3717,13 +3942,13 @@ var AbstractNumericIdentifierCreator = class _AbstractNumericIdentifierCreator e
|
|
|
3717
3942
|
return this._capacity;
|
|
3718
3943
|
}
|
|
3719
3944
|
/**
|
|
3720
|
-
*
|
|
3945
|
+
* @inheritDoc
|
|
3721
3946
|
*/
|
|
3722
3947
|
get tweak() {
|
|
3723
3948
|
return this._tweak;
|
|
3724
3949
|
}
|
|
3725
3950
|
/**
|
|
3726
|
-
*
|
|
3951
|
+
* @inheritDoc
|
|
3727
3952
|
*/
|
|
3728
3953
|
set tweak(value) {
|
|
3729
3954
|
this._tweak = value;
|
|
@@ -3758,8 +3983,8 @@ var AbstractNumericIdentifierCreator = class _AbstractNumericIdentifierCreator e
|
|
|
3758
3983
|
* Remaining reference length. Initial value is `this.referenceLength`.
|
|
3759
3984
|
*
|
|
3760
3985
|
* @param extensionWeight
|
|
3761
|
-
* If this value is not zero, the identifier has an extension digit, this call is setting it, and this value
|
|
3762
|
-
*
|
|
3986
|
+
* If this value is not zero, the identifier has an extension digit, this call is setting it, and this value is
|
|
3987
|
+
* applied to the calculation of the check digit.
|
|
3763
3988
|
*
|
|
3764
3989
|
* @param weight
|
|
3765
3990
|
* If the extension weight is zero, this value is applied to the calculation of the check digit.
|
|
@@ -3808,11 +4033,6 @@ var AbstractNumericIdentifierCreator = class _AbstractNumericIdentifierCreator e
|
|
|
3808
4033
|
};
|
|
3809
4034
|
|
|
3810
4035
|
// src/gtin-creator.ts
|
|
3811
|
-
import {
|
|
3812
|
-
Exclusions as Exclusions4,
|
|
3813
|
-
NUMERIC_CREATOR as NUMERIC_CREATOR6
|
|
3814
|
-
} from "@aidc-toolkit/utility";
|
|
3815
|
-
import { Mixin } from "ts-mixer";
|
|
3816
4036
|
var GTINCreator = class _GTINCreator extends Mixin(GTINValidator, AbstractNumericIdentifierCreator) {
|
|
3817
4037
|
/**
|
|
3818
4038
|
* Validation parameters for required indicator digit.
|
|
@@ -3829,11 +4049,11 @@ var GTINCreator = class _GTINCreator extends Mixin(GTINValidator, AbstractNumeri
|
|
|
3829
4049
|
* @param prefixProvider
|
|
3830
4050
|
* Prefix provider.
|
|
3831
4051
|
*
|
|
3832
|
-
* @param
|
|
3833
|
-
* GTIN type.
|
|
4052
|
+
* @param gtinBaseType
|
|
4053
|
+
* GTIN base type (all except GTIN-14).
|
|
3834
4054
|
*/
|
|
3835
|
-
constructor(prefixProvider,
|
|
3836
|
-
super(
|
|
4055
|
+
constructor(prefixProvider, gtinBaseType) {
|
|
4056
|
+
super(gtinBaseType);
|
|
3837
4057
|
this.init(prefixProvider, prefixProvider.prefix);
|
|
3838
4058
|
}
|
|
3839
4059
|
/**
|
|
@@ -3967,15 +4187,9 @@ var NonGTINNumericIdentifierCreator = class extends Mixin2(NonGTINNumericIdentif
|
|
|
3967
4187
|
*
|
|
3968
4188
|
* @param identifierType
|
|
3969
4189
|
* Identifier type.
|
|
3970
|
-
*
|
|
3971
|
-
* @param length
|
|
3972
|
-
* Length.
|
|
3973
|
-
*
|
|
3974
|
-
* @param leaderType
|
|
3975
|
-
* Leader type.
|
|
3976
4190
|
*/
|
|
3977
|
-
constructor(prefixProvider, identifierType
|
|
3978
|
-
super(identifierType
|
|
4191
|
+
constructor(prefixProvider, identifierType) {
|
|
4192
|
+
super(identifierType);
|
|
3979
4193
|
this.init(prefixProvider, prefixProvider.gs1CompanyPrefix);
|
|
3980
4194
|
}
|
|
3981
4195
|
};
|
|
@@ -3993,18 +4207,9 @@ var SerializableNumericIdentifierCreator = class extends Mixin3(SerializableNume
|
|
|
3993
4207
|
*
|
|
3994
4208
|
* @param identifierType
|
|
3995
4209
|
* Identifier type.
|
|
3996
|
-
*
|
|
3997
|
-
* @param length
|
|
3998
|
-
* Length.
|
|
3999
|
-
*
|
|
4000
|
-
* @param serialComponentLength
|
|
4001
|
-
* Serial component length.
|
|
4002
|
-
*
|
|
4003
|
-
* @param serialComponentCharacterSet
|
|
4004
|
-
* Serial component character set.
|
|
4005
4210
|
*/
|
|
4006
|
-
constructor(prefixProvider, identifierType
|
|
4007
|
-
super(identifierType
|
|
4211
|
+
constructor(prefixProvider, identifierType) {
|
|
4212
|
+
super(identifierType);
|
|
4008
4213
|
this.init(prefixProvider, prefixProvider.gs1CompanyPrefix);
|
|
4009
4214
|
}
|
|
4010
4215
|
/**
|
|
@@ -4099,19 +4304,10 @@ var NonNumericIdentifierCreator = class extends Mixin4(NonNumericIdentifierValid
|
|
|
4099
4304
|
*
|
|
4100
4305
|
* @param identifierType
|
|
4101
4306
|
* Identifier type.
|
|
4102
|
-
*
|
|
4103
|
-
* @param length
|
|
4104
|
-
* Length.
|
|
4105
|
-
*
|
|
4106
|
-
* @param referenceCharacterSet
|
|
4107
|
-
* Reference character set.
|
|
4108
|
-
*
|
|
4109
|
-
* @param requiresCheckCharacterPair
|
|
4110
|
-
* True if the identifier requires a check character pair.
|
|
4111
4307
|
*/
|
|
4112
|
-
constructor(prefixProvider, identifierType
|
|
4113
|
-
super(identifierType
|
|
4114
|
-
this.init(prefixProvider, prefixProvider.gs1CompanyPrefix, 2 * Number(requiresCheckCharacterPair));
|
|
4308
|
+
constructor(prefixProvider, identifierType) {
|
|
4309
|
+
super(identifierType);
|
|
4310
|
+
this.init(prefixProvider, prefixProvider.gs1CompanyPrefix, 2 * Number(this.requiresCheckCharacterPair));
|
|
4115
4311
|
this._referenceValidation = {
|
|
4116
4312
|
minimumLength: 1,
|
|
4117
4313
|
// Maximum reference length has to account for prefix and check character pair.
|
|
@@ -4157,6 +4353,23 @@ var NonNumericIdentifierCreator = class extends Mixin4(NonNumericIdentifierValid
|
|
|
4157
4353
|
}
|
|
4158
4354
|
};
|
|
4159
4355
|
|
|
4356
|
+
// src/creators.ts
|
|
4357
|
+
function isNumericIdentifierCreator(identifierCreator) {
|
|
4358
|
+
return isNumericIdentifierDescriptor(identifierCreator);
|
|
4359
|
+
}
|
|
4360
|
+
function isGTINCreator(identifierCreator) {
|
|
4361
|
+
return isGTINDescriptor(identifierCreator);
|
|
4362
|
+
}
|
|
4363
|
+
function isNonGTINNumericIdentifierCreator(identifierCreator) {
|
|
4364
|
+
return isNonGTINNumericIdentifierDescriptor(identifierCreator);
|
|
4365
|
+
}
|
|
4366
|
+
function isSerializableNumericIdentifierCreator(identifierCreator) {
|
|
4367
|
+
return isSerializableNumericIdentifierDescriptor(identifierCreator);
|
|
4368
|
+
}
|
|
4369
|
+
function isNonNumericIdentifierCreator(identifierCreator) {
|
|
4370
|
+
return isNonNumericIdentifierDescriptor(identifierCreator);
|
|
4371
|
+
}
|
|
4372
|
+
|
|
4160
4373
|
// src/prefix-manager.ts
|
|
4161
4374
|
var PrefixManager = class _PrefixManager {
|
|
4162
4375
|
/**
|
|
@@ -4190,11 +4403,11 @@ var PrefixManager = class _PrefixManager {
|
|
|
4190
4403
|
*/
|
|
4191
4404
|
_gs1CompanyPrefix;
|
|
4192
4405
|
/**
|
|
4193
|
-
* U.P.C. Company Prefix if prefix type is {@
|
|
4406
|
+
* U.P.C. Company Prefix if prefix type is {@linkcode PrefixTypes.UPCCompanyPrefix}.
|
|
4194
4407
|
*/
|
|
4195
4408
|
_upcCompanyPrefix;
|
|
4196
4409
|
/**
|
|
4197
|
-
* GS1-8 Prefix if prefix type is {@
|
|
4410
|
+
* GS1-8 Prefix if prefix type is {@linkcode PrefixTypes.GS18Prefix}.
|
|
4198
4411
|
*/
|
|
4199
4412
|
_gs18Prefix;
|
|
4200
4413
|
/**
|
|
@@ -4212,23 +4425,19 @@ var PrefixManager = class _PrefixManager {
|
|
|
4212
4425
|
/**
|
|
4213
4426
|
* Constructor.
|
|
4214
4427
|
*
|
|
4215
|
-
* @param
|
|
4216
|
-
*
|
|
4428
|
+
* @param prefixType
|
|
4429
|
+
* Prefix type.
|
|
4430
|
+
*
|
|
4431
|
+
* @param prefix
|
|
4432
|
+
* Prefix.
|
|
4217
4433
|
*/
|
|
4218
|
-
constructor(
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
this._upcCompanyPrefix = gs1CompanyPrefix.substring(1);
|
|
4226
|
-
this._prefix = this._upcCompanyPrefix;
|
|
4227
|
-
} else {
|
|
4228
|
-
this._prefixType = PrefixTypes.GS18Prefix;
|
|
4229
|
-
this._gs18Prefix = gs1CompanyPrefix.substring(5);
|
|
4230
|
-
this._prefix = this._gs18Prefix;
|
|
4231
|
-
}
|
|
4434
|
+
constructor(prefixType, prefix) {
|
|
4435
|
+
const normalizedPrefixProvider = PrefixValidator.normalize(prefixType, prefix);
|
|
4436
|
+
this._prefixType = normalizedPrefixProvider.prefixType;
|
|
4437
|
+
this._prefix = normalizedPrefixProvider.prefix;
|
|
4438
|
+
this._gs1CompanyPrefix = normalizedPrefixProvider.gs1CompanyPrefix;
|
|
4439
|
+
this._upcCompanyPrefix = normalizedPrefixProvider.upcCompanyPrefix;
|
|
4440
|
+
this._gs18Prefix = normalizedPrefixProvider.gs18Prefix;
|
|
4232
4441
|
this._defaultTweakFactor = BigInt(`1${this.gs1CompanyPrefix}`);
|
|
4233
4442
|
this.resetTweakFactor();
|
|
4234
4443
|
}
|
|
@@ -4251,13 +4460,13 @@ var PrefixManager = class _PrefixManager {
|
|
|
4251
4460
|
return this._gs1CompanyPrefix;
|
|
4252
4461
|
}
|
|
4253
4462
|
/**
|
|
4254
|
-
* Get the U.P.C. Company Prefix if prefix type is {@
|
|
4463
|
+
* Get the U.P.C. Company Prefix if prefix type is {@linkcode PrefixTypes.UPCCompanyPrefix} or undefined if not.
|
|
4255
4464
|
*/
|
|
4256
4465
|
get upcCompanyPrefix() {
|
|
4257
4466
|
return this._upcCompanyPrefix;
|
|
4258
4467
|
}
|
|
4259
4468
|
/**
|
|
4260
|
-
* Get the GS1-8 Prefix if prefix type is {@
|
|
4469
|
+
* Get the GS1-8 Prefix if prefix type is {@linkcode PrefixTypes.GS18Prefix} or undefined if not.
|
|
4261
4470
|
*/
|
|
4262
4471
|
get gs18Prefix() {
|
|
4263
4472
|
return this._gs18Prefix;
|
|
@@ -4265,13 +4474,12 @@ var PrefixManager = class _PrefixManager {
|
|
|
4265
4474
|
/**
|
|
4266
4475
|
* Set the tweak for an identifier creator if it's a numeric identifier creator.
|
|
4267
4476
|
*
|
|
4268
|
-
* @param
|
|
4477
|
+
* @param identifierCreator
|
|
4269
4478
|
* Identifier creator.
|
|
4270
4479
|
*/
|
|
4271
|
-
setCreatorTweak(
|
|
4272
|
-
if (
|
|
4273
|
-
|
|
4274
|
-
creator.tweak = this.tweakFactor * creatorTweakFactor;
|
|
4480
|
+
setCreatorTweak(identifierCreator) {
|
|
4481
|
+
if (isNumericIdentifierCreator(identifierCreator)) {
|
|
4482
|
+
identifierCreator.tweak = this.tweakFactor * _PrefixManager.CREATOR_TWEAK_FACTORS[identifierCreator.identifierType];
|
|
4275
4483
|
}
|
|
4276
4484
|
}
|
|
4277
4485
|
/**
|
|
@@ -4314,42 +4522,33 @@ var PrefixManager = class _PrefixManager {
|
|
|
4314
4522
|
* Prefix manager with normalized prefix type and prefix.
|
|
4315
4523
|
*/
|
|
4316
4524
|
static get(prefixType, prefix) {
|
|
4317
|
-
PrefixValidator.
|
|
4318
|
-
let gs1CompanyPrefix;
|
|
4319
|
-
switch (prefixType) {
|
|
4320
|
-
case PrefixTypes.GS1CompanyPrefix:
|
|
4321
|
-
gs1CompanyPrefix = prefix;
|
|
4322
|
-
break;
|
|
4323
|
-
case PrefixTypes.UPCCompanyPrefix:
|
|
4324
|
-
gs1CompanyPrefix = "0" + prefix;
|
|
4325
|
-
break;
|
|
4326
|
-
case PrefixTypes.GS18Prefix:
|
|
4327
|
-
gs1CompanyPrefix = "00000" + prefix;
|
|
4328
|
-
break;
|
|
4329
|
-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- Method may be called by unsafe means.
|
|
4330
|
-
default:
|
|
4331
|
-
throw new RangeError(i18nextGS1.t("Prefix.invalidPrefixType"));
|
|
4332
|
-
}
|
|
4333
|
-
let prefixManager = _PrefixManager.PREFIX_MANAGERS_MAP.get(gs1CompanyPrefix);
|
|
4525
|
+
const normalizedPrefixProvider = PrefixValidator.normalize(prefixType, prefix);
|
|
4526
|
+
let prefixManager = _PrefixManager.PREFIX_MANAGERS_MAP.get(normalizedPrefixProvider.gs1CompanyPrefix);
|
|
4334
4527
|
if (prefixManager === void 0) {
|
|
4335
|
-
prefixManager = new _PrefixManager(
|
|
4336
|
-
_PrefixManager.PREFIX_MANAGERS_MAP.set(gs1CompanyPrefix, prefixManager);
|
|
4528
|
+
prefixManager = new _PrefixManager(normalizedPrefixProvider.prefixType, normalizedPrefixProvider.prefix);
|
|
4529
|
+
_PrefixManager.PREFIX_MANAGERS_MAP.set(normalizedPrefixProvider.gs1CompanyPrefix, prefixManager);
|
|
4337
4530
|
}
|
|
4338
4531
|
return prefixManager;
|
|
4339
4532
|
}
|
|
4340
4533
|
/**
|
|
4341
4534
|
* Get an identifier creator.
|
|
4342
4535
|
*
|
|
4536
|
+
* @template TIdentifierType
|
|
4537
|
+
* Identifier type type.
|
|
4538
|
+
*
|
|
4343
4539
|
* @param identifierType
|
|
4344
|
-
* Identifier type.
|
|
4540
|
+
* Identifier type used to construct identifier creator.
|
|
4541
|
+
*
|
|
4542
|
+
* @param constructorParameter
|
|
4543
|
+
* Second constructor parameter passed to constructor callback alongside this.
|
|
4345
4544
|
*
|
|
4346
|
-
* @param
|
|
4545
|
+
* @param ConstructorCallback
|
|
4347
4546
|
* Constructor callback.
|
|
4348
4547
|
*
|
|
4349
4548
|
* @returns
|
|
4350
4549
|
* Identifier creator.
|
|
4351
4550
|
*/
|
|
4352
|
-
getIdentifierCreator(identifierType,
|
|
4551
|
+
getIdentifierCreator(identifierType, constructorParameter, ConstructorCallback) {
|
|
4353
4552
|
let creator = this._identifierCreators[identifierType];
|
|
4354
4553
|
if (creator === void 0) {
|
|
4355
4554
|
if (this.prefixType === PrefixTypes.GS18Prefix && identifierType !== IdentifierTypes.GTIN) {
|
|
@@ -4357,7 +4556,7 @@ var PrefixManager = class _PrefixManager {
|
|
|
4357
4556
|
identifierType
|
|
4358
4557
|
}));
|
|
4359
4558
|
}
|
|
4360
|
-
creator =
|
|
4559
|
+
creator = new ConstructorCallback(this, constructorParameter);
|
|
4361
4560
|
this.setCreatorTweak(creator);
|
|
4362
4561
|
this._identifierCreators[identifierType] = creator;
|
|
4363
4562
|
}
|
|
@@ -4366,124 +4565,110 @@ var PrefixManager = class _PrefixManager {
|
|
|
4366
4565
|
/**
|
|
4367
4566
|
* Get non-GTIN numeric identifier creator.
|
|
4368
4567
|
*
|
|
4369
|
-
* @param
|
|
4370
|
-
*
|
|
4568
|
+
* @param identifierType
|
|
4569
|
+
* Identifier type used to construct identifier creator.
|
|
4371
4570
|
*
|
|
4372
4571
|
* @returns
|
|
4373
4572
|
* Identifier creator.
|
|
4374
4573
|
*/
|
|
4375
|
-
getNonGTINNumericIdentifierCreator(
|
|
4376
|
-
return this.getIdentifierCreator(
|
|
4574
|
+
getNonGTINNumericIdentifierCreator(identifierType) {
|
|
4575
|
+
return this.getIdentifierCreator(identifierType, identifierType, NonGTINNumericIdentifierCreator);
|
|
4377
4576
|
}
|
|
4378
4577
|
/**
|
|
4379
4578
|
* Get serialized numeric identifier creator.
|
|
4380
4579
|
*
|
|
4381
|
-
* @param
|
|
4382
|
-
*
|
|
4580
|
+
* @param identifierType
|
|
4581
|
+
* Identifier type used to construct identifier creator.
|
|
4383
4582
|
*
|
|
4384
4583
|
* @returns
|
|
4385
4584
|
* Identifier creator.
|
|
4386
4585
|
*/
|
|
4387
|
-
getSerializableNumericIdentifierCreator(
|
|
4388
|
-
return this.getIdentifierCreator(
|
|
4586
|
+
getSerializableNumericIdentifierCreator(identifierType) {
|
|
4587
|
+
return this.getIdentifierCreator(identifierType, identifierType, SerializableNumericIdentifierCreator);
|
|
4389
4588
|
}
|
|
4390
4589
|
/**
|
|
4391
4590
|
* Get non-numeric identifier creator.
|
|
4392
4591
|
*
|
|
4393
|
-
* @param
|
|
4394
|
-
*
|
|
4592
|
+
* @param identifierType
|
|
4593
|
+
* Identifier type used to construct identifier creator.
|
|
4395
4594
|
*
|
|
4396
4595
|
* @returns
|
|
4397
4596
|
* Identifier creator.
|
|
4398
4597
|
*/
|
|
4399
|
-
getNonNumericIdentifierCreator(
|
|
4400
|
-
return this.getIdentifierCreator(
|
|
4598
|
+
getNonNumericIdentifierCreator(identifierType) {
|
|
4599
|
+
return this.getIdentifierCreator(identifierType, identifierType, NonNumericIdentifierCreator);
|
|
4401
4600
|
}
|
|
4402
4601
|
/**
|
|
4403
4602
|
* Get GTIN creator.
|
|
4404
4603
|
*/
|
|
4405
4604
|
get gtinCreator() {
|
|
4406
|
-
return this.getIdentifierCreator(IdentifierTypes.GTIN,
|
|
4407
|
-
let gtinType;
|
|
4408
|
-
switch (this.prefixType) {
|
|
4409
|
-
case PrefixTypes.GS1CompanyPrefix:
|
|
4410
|
-
gtinType = GTINTypes.GTIN13;
|
|
4411
|
-
break;
|
|
4412
|
-
case PrefixTypes.UPCCompanyPrefix:
|
|
4413
|
-
gtinType = GTINTypes.GTIN12;
|
|
4414
|
-
break;
|
|
4415
|
-
case PrefixTypes.GS18Prefix:
|
|
4416
|
-
gtinType = GTINTypes.GTIN8;
|
|
4417
|
-
break;
|
|
4418
|
-
}
|
|
4419
|
-
return new GTINCreator(this, gtinType);
|
|
4420
|
-
});
|
|
4605
|
+
return this.getIdentifierCreator(IdentifierTypes.GTIN, GTIN_BASE_TYPES[this.prefixType], GTINCreator);
|
|
4421
4606
|
}
|
|
4422
4607
|
/**
|
|
4423
4608
|
* Get GLN creator.
|
|
4424
4609
|
*/
|
|
4425
4610
|
get glnCreator() {
|
|
4426
|
-
return this.getNonGTINNumericIdentifierCreator(
|
|
4611
|
+
return this.getNonGTINNumericIdentifierCreator(IdentifierTypes.GLN);
|
|
4427
4612
|
}
|
|
4428
4613
|
/**
|
|
4429
4614
|
* Get SSCC creator.
|
|
4430
4615
|
*/
|
|
4431
4616
|
get ssccCreator() {
|
|
4432
|
-
return this.getNonGTINNumericIdentifierCreator(
|
|
4617
|
+
return this.getNonGTINNumericIdentifierCreator(IdentifierTypes.SSCC);
|
|
4433
4618
|
}
|
|
4434
4619
|
/**
|
|
4435
4620
|
* Get GRAI creator.
|
|
4436
4621
|
*/
|
|
4437
4622
|
get graiCreator() {
|
|
4438
|
-
return this.getSerializableNumericIdentifierCreator(
|
|
4623
|
+
return this.getSerializableNumericIdentifierCreator(IdentifierTypes.GRAI);
|
|
4439
4624
|
}
|
|
4440
4625
|
/**
|
|
4441
4626
|
* Get GIAI creator.
|
|
4442
4627
|
*/
|
|
4443
4628
|
get giaiCreator() {
|
|
4444
|
-
return this.getNonNumericIdentifierCreator(
|
|
4629
|
+
return this.getNonNumericIdentifierCreator(IdentifierTypes.GIAI);
|
|
4445
4630
|
}
|
|
4446
4631
|
/**
|
|
4447
4632
|
* Get GSRN creator.
|
|
4448
4633
|
*/
|
|
4449
4634
|
get gsrnCreator() {
|
|
4450
|
-
return this.getNonGTINNumericIdentifierCreator(
|
|
4635
|
+
return this.getNonGTINNumericIdentifierCreator(IdentifierTypes.GSRN);
|
|
4451
4636
|
}
|
|
4452
4637
|
/**
|
|
4453
4638
|
* Get GDTI creator.
|
|
4454
4639
|
*/
|
|
4455
4640
|
get gdtiCreator() {
|
|
4456
|
-
return this.getSerializableNumericIdentifierCreator(
|
|
4641
|
+
return this.getSerializableNumericIdentifierCreator(IdentifierTypes.GDTI);
|
|
4457
4642
|
}
|
|
4458
4643
|
/**
|
|
4459
4644
|
* Get GINC creator.
|
|
4460
4645
|
*/
|
|
4461
4646
|
get gincCreator() {
|
|
4462
|
-
return this.getNonNumericIdentifierCreator(
|
|
4647
|
+
return this.getNonNumericIdentifierCreator(IdentifierTypes.GINC);
|
|
4463
4648
|
}
|
|
4464
4649
|
/**
|
|
4465
4650
|
* Get GSIN creator.
|
|
4466
4651
|
*/
|
|
4467
4652
|
get gsinCreator() {
|
|
4468
|
-
return this.getNonGTINNumericIdentifierCreator(
|
|
4653
|
+
return this.getNonGTINNumericIdentifierCreator(IdentifierTypes.GSIN);
|
|
4469
4654
|
}
|
|
4470
4655
|
/**
|
|
4471
4656
|
* Get GCN creator.
|
|
4472
4657
|
*/
|
|
4473
4658
|
get gcnCreator() {
|
|
4474
|
-
return this.getSerializableNumericIdentifierCreator(
|
|
4659
|
+
return this.getSerializableNumericIdentifierCreator(IdentifierTypes.GCN);
|
|
4475
4660
|
}
|
|
4476
4661
|
/**
|
|
4477
4662
|
* Get CPID creator.
|
|
4478
4663
|
*/
|
|
4479
4664
|
get cpidCreator() {
|
|
4480
|
-
return this.getNonNumericIdentifierCreator(
|
|
4665
|
+
return this.getNonNumericIdentifierCreator(IdentifierTypes.CPID);
|
|
4481
4666
|
}
|
|
4482
4667
|
/**
|
|
4483
4668
|
* Get GMN creator.
|
|
4484
4669
|
*/
|
|
4485
4670
|
get gmnCreator() {
|
|
4486
|
-
return this.getNonNumericIdentifierCreator(
|
|
4671
|
+
return this.getNonNumericIdentifierCreator(IdentifierTypes.GMN);
|
|
4487
4672
|
}
|
|
4488
4673
|
};
|
|
4489
4674
|
export {
|
|
@@ -4492,30 +4677,15 @@ export {
|
|
|
4492
4677
|
AI64_VALIDATOR,
|
|
4493
4678
|
AI82_CREATOR,
|
|
4494
4679
|
AI82_VALIDATOR,
|
|
4495
|
-
AbstractIdentifierCreator,
|
|
4496
|
-
AbstractIdentifierValidator,
|
|
4497
|
-
AbstractNumericIdentifierCreator,
|
|
4498
|
-
AbstractNumericIdentifierValidator,
|
|
4499
|
-
CPID_VALIDATOR,
|
|
4500
4680
|
ContentCharacterSets,
|
|
4501
|
-
GCN_VALIDATOR,
|
|
4502
|
-
GDTI_VALIDATOR,
|
|
4503
|
-
GIAI_VALIDATOR,
|
|
4504
|
-
GINC_VALIDATOR,
|
|
4505
|
-
GLN_VALIDATOR,
|
|
4506
|
-
GMN_VALIDATOR,
|
|
4507
|
-
GRAI_VALIDATOR,
|
|
4508
|
-
GSIN_VALIDATOR,
|
|
4509
|
-
GSRN_VALIDATOR,
|
|
4510
|
-
GTIN12_VALIDATOR,
|
|
4511
|
-
GTIN13_VALIDATOR,
|
|
4512
|
-
GTIN8_VALIDATOR,
|
|
4513
4681
|
GTINCreator,
|
|
4514
4682
|
GTINLevels,
|
|
4515
4683
|
GTINTypes,
|
|
4516
4684
|
GTINValidator,
|
|
4517
|
-
|
|
4685
|
+
GTIN_BASE_TYPES,
|
|
4686
|
+
IdentifierDescriptors,
|
|
4518
4687
|
IdentifierTypes,
|
|
4688
|
+
IdentifierValidators,
|
|
4519
4689
|
LeaderTypes,
|
|
4520
4690
|
NonGTINNumericIdentifierCreator,
|
|
4521
4691
|
NonGTINNumericIdentifierValidator,
|
|
@@ -4524,7 +4694,6 @@ export {
|
|
|
4524
4694
|
PrefixManager,
|
|
4525
4695
|
PrefixTypes,
|
|
4526
4696
|
PrefixValidator,
|
|
4527
|
-
SSCC_VALIDATOR,
|
|
4528
4697
|
SerializableNumericIdentifierCreator,
|
|
4529
4698
|
SerializableNumericIdentifierValidator,
|
|
4530
4699
|
checkCharacterPair,
|
|
@@ -4536,6 +4705,23 @@ export {
|
|
|
4536
4705
|
hasValidCheckDigit,
|
|
4537
4706
|
i18nGS1Init,
|
|
4538
4707
|
i18nextGS1,
|
|
4708
|
+
isGTINCreator,
|
|
4709
|
+
isGTINDescriptor,
|
|
4710
|
+
isGTINDescriptors,
|
|
4711
|
+
isGTINValidator,
|
|
4712
|
+
isGTINValidators,
|
|
4713
|
+
isNonGTINNumericIdentifierCreator,
|
|
4714
|
+
isNonGTINNumericIdentifierDescriptor,
|
|
4715
|
+
isNonGTINNumericIdentifierValidator,
|
|
4716
|
+
isNonNumericIdentifierCreator,
|
|
4717
|
+
isNonNumericIdentifierDescriptor,
|
|
4718
|
+
isNonNumericIdentifierValidator,
|
|
4719
|
+
isNumericIdentifierCreator,
|
|
4720
|
+
isNumericIdentifierDescriptor,
|
|
4721
|
+
isNumericIdentifierValidator,
|
|
4722
|
+
isSerializableNumericIdentifierCreator,
|
|
4723
|
+
isSerializableNumericIdentifierDescriptor,
|
|
4724
|
+
isSerializableNumericIdentifierValidator,
|
|
4539
4725
|
isValidPriceOrWeightCheckDigit,
|
|
4540
4726
|
priceOrWeightCheckDigit
|
|
4541
4727
|
};
|