@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.cjs
CHANGED
|
@@ -25,30 +25,15 @@ __export(index_exports, {
|
|
|
25
25
|
AI64_VALIDATOR: () => AI64_VALIDATOR,
|
|
26
26
|
AI82_CREATOR: () => AI82_CREATOR,
|
|
27
27
|
AI82_VALIDATOR: () => AI82_VALIDATOR,
|
|
28
|
-
AbstractIdentifierCreator: () => AbstractIdentifierCreator,
|
|
29
|
-
AbstractIdentifierValidator: () => AbstractIdentifierValidator,
|
|
30
|
-
AbstractNumericIdentifierCreator: () => AbstractNumericIdentifierCreator,
|
|
31
|
-
AbstractNumericIdentifierValidator: () => AbstractNumericIdentifierValidator,
|
|
32
|
-
CPID_VALIDATOR: () => CPID_VALIDATOR,
|
|
33
28
|
ContentCharacterSets: () => ContentCharacterSets,
|
|
34
|
-
GCN_VALIDATOR: () => GCN_VALIDATOR,
|
|
35
|
-
GDTI_VALIDATOR: () => GDTI_VALIDATOR,
|
|
36
|
-
GIAI_VALIDATOR: () => GIAI_VALIDATOR,
|
|
37
|
-
GINC_VALIDATOR: () => GINC_VALIDATOR,
|
|
38
|
-
GLN_VALIDATOR: () => GLN_VALIDATOR,
|
|
39
|
-
GMN_VALIDATOR: () => GMN_VALIDATOR,
|
|
40
|
-
GRAI_VALIDATOR: () => GRAI_VALIDATOR,
|
|
41
|
-
GSIN_VALIDATOR: () => GSIN_VALIDATOR,
|
|
42
|
-
GSRN_VALIDATOR: () => GSRN_VALIDATOR,
|
|
43
|
-
GTIN12_VALIDATOR: () => GTIN12_VALIDATOR,
|
|
44
|
-
GTIN13_VALIDATOR: () => GTIN13_VALIDATOR,
|
|
45
|
-
GTIN8_VALIDATOR: () => GTIN8_VALIDATOR,
|
|
46
29
|
GTINCreator: () => GTINCreator,
|
|
47
30
|
GTINLevels: () => GTINLevels,
|
|
48
31
|
GTINTypes: () => GTINTypes,
|
|
49
32
|
GTINValidator: () => GTINValidator,
|
|
50
|
-
|
|
33
|
+
GTIN_BASE_TYPES: () => GTIN_BASE_TYPES,
|
|
34
|
+
IdentifierDescriptors: () => IdentifierDescriptors,
|
|
51
35
|
IdentifierTypes: () => IdentifierTypes,
|
|
36
|
+
IdentifierValidators: () => IdentifierValidators,
|
|
52
37
|
LeaderTypes: () => LeaderTypes,
|
|
53
38
|
NonGTINNumericIdentifierCreator: () => NonGTINNumericIdentifierCreator,
|
|
54
39
|
NonGTINNumericIdentifierValidator: () => NonGTINNumericIdentifierValidator,
|
|
@@ -57,7 +42,6 @@ __export(index_exports, {
|
|
|
57
42
|
PrefixManager: () => PrefixManager,
|
|
58
43
|
PrefixTypes: () => PrefixTypes,
|
|
59
44
|
PrefixValidator: () => PrefixValidator,
|
|
60
|
-
SSCC_VALIDATOR: () => SSCC_VALIDATOR,
|
|
61
45
|
SerializableNumericIdentifierCreator: () => SerializableNumericIdentifierCreator,
|
|
62
46
|
SerializableNumericIdentifierValidator: () => SerializableNumericIdentifierValidator,
|
|
63
47
|
checkCharacterPair: () => checkCharacterPair,
|
|
@@ -69,6 +53,23 @@ __export(index_exports, {
|
|
|
69
53
|
hasValidCheckDigit: () => hasValidCheckDigit,
|
|
70
54
|
i18nGS1Init: () => i18nGS1Init,
|
|
71
55
|
i18nextGS1: () => i18nextGS1,
|
|
56
|
+
isGTINCreator: () => isGTINCreator,
|
|
57
|
+
isGTINDescriptor: () => isGTINDescriptor,
|
|
58
|
+
isGTINDescriptors: () => isGTINDescriptors,
|
|
59
|
+
isGTINValidator: () => isGTINValidator,
|
|
60
|
+
isGTINValidators: () => isGTINValidators,
|
|
61
|
+
isNonGTINNumericIdentifierCreator: () => isNonGTINNumericIdentifierCreator,
|
|
62
|
+
isNonGTINNumericIdentifierDescriptor: () => isNonGTINNumericIdentifierDescriptor,
|
|
63
|
+
isNonGTINNumericIdentifierValidator: () => isNonGTINNumericIdentifierValidator,
|
|
64
|
+
isNonNumericIdentifierCreator: () => isNonNumericIdentifierCreator,
|
|
65
|
+
isNonNumericIdentifierDescriptor: () => isNonNumericIdentifierDescriptor,
|
|
66
|
+
isNonNumericIdentifierValidator: () => isNonNumericIdentifierValidator,
|
|
67
|
+
isNumericIdentifierCreator: () => isNumericIdentifierCreator,
|
|
68
|
+
isNumericIdentifierDescriptor: () => isNumericIdentifierDescriptor,
|
|
69
|
+
isNumericIdentifierValidator: () => isNumericIdentifierValidator,
|
|
70
|
+
isSerializableNumericIdentifierCreator: () => isSerializableNumericIdentifierCreator,
|
|
71
|
+
isSerializableNumericIdentifierDescriptor: () => isSerializableNumericIdentifierDescriptor,
|
|
72
|
+
isSerializableNumericIdentifierValidator: () => isSerializableNumericIdentifierValidator,
|
|
72
73
|
isValidPriceOrWeightCheckDigit: () => isValidPriceOrWeightCheckDigit,
|
|
73
74
|
priceOrWeightCheckDigit: () => priceOrWeightCheckDigit
|
|
74
75
|
});
|
|
@@ -507,7 +508,7 @@ var postProcessor = {
|
|
|
507
508
|
return value;
|
|
508
509
|
}
|
|
509
510
|
};
|
|
510
|
-
var PATH_KEY = Symbol("i18next/PATH_KEY");
|
|
511
|
+
var PATH_KEY = /* @__PURE__ */ Symbol("i18next/PATH_KEY");
|
|
511
512
|
function createProxy() {
|
|
512
513
|
const state = [];
|
|
513
514
|
const handler = /* @__PURE__ */ Object.create(null);
|
|
@@ -2308,7 +2309,6 @@ var locale_resources_default = {
|
|
|
2308
2309
|
gs1CompanyPrefix: "GS1 Company Prefix",
|
|
2309
2310
|
upcCompanyPrefix: "U.P.C. Company Prefix",
|
|
2310
2311
|
gs18Prefix: "GS1-8 Prefix",
|
|
2311
|
-
invalidPrefixType: "Invalid prefix type",
|
|
2312
2312
|
gs1CompanyPrefixCantStartWith0: `GS1 Company Prefix can't start with "0"`,
|
|
2313
2313
|
gs1CompanyPrefixCantStartWith00000: `GS1 Company Prefix can't start with "00000"`,
|
|
2314
2314
|
gs1CompanyPrefixCantStartWith000000: `GS1 Company Prefix can't start with "000000"`,
|
|
@@ -2351,7 +2351,6 @@ var locale_resources_default2 = {
|
|
|
2351
2351
|
gs1CompanyPrefix: "Pr\xE9fixe de l'entreprise GS1",
|
|
2352
2352
|
upcCompanyPrefix: "Pr\xE9fixe de l'entreprise U.P.C.",
|
|
2353
2353
|
gs18Prefix: "Pr\xE9fixe GS1-8",
|
|
2354
|
-
invalidPrefixType: "Type de pr\xE9fixe invalide",
|
|
2355
2354
|
gs1CompanyPrefixCantStartWith0: `Le pr\xE9fixe de l'entreprise GS1 ne peut pas commencer par "0"`,
|
|
2356
2355
|
gs1CompanyPrefixCantStartWith00000: `Le pr\xE9fixe de l'entreprise GS1 ne peut pas commencer par "00000"`,
|
|
2357
2356
|
gs1CompanyPrefixCantStartWith000000: `Le pr\xE9fixe de l'entreprise GS1 ne peut pas commencer par "000000"`,
|
|
@@ -2827,49 +2826,6 @@ var GS1_8_PREFIX_VALIDATION = {
|
|
|
2827
2826
|
maximumLength: GS1_8_PREFIX_MAXIMUM_LENGTH,
|
|
2828
2827
|
component: () => i18nextGS1.t("Prefix.gs18Prefix")
|
|
2829
2828
|
};
|
|
2830
|
-
function validate(prefixType, allowUPCCompanyPrefix, allowGS18Prefix, prefix, isFromIdentifier = false, isNumericIdentifier = false, positionOffset) {
|
|
2831
|
-
let baseValidation;
|
|
2832
|
-
switch (prefixType) {
|
|
2833
|
-
case PrefixTypes.GS1CompanyPrefix:
|
|
2834
|
-
if (!prefix.startsWith("0")) {
|
|
2835
|
-
baseValidation = GS1_COMPANY_PREFIX_VALIDATION;
|
|
2836
|
-
} else if (!prefix.startsWith("00000")) {
|
|
2837
|
-
if (!allowUPCCompanyPrefix) {
|
|
2838
|
-
throw new RangeError(i18nextGS1.t("Prefix.gs1CompanyPrefixCantStartWith0"));
|
|
2839
|
-
}
|
|
2840
|
-
baseValidation = UPC_COMPANY_PREFIX_AS_GS1_COMPANY_PREFIX_VALIDATION;
|
|
2841
|
-
} else if (!prefix.startsWith("000000")) {
|
|
2842
|
-
if (!allowGS18Prefix) {
|
|
2843
|
-
throw new RangeError(i18nextGS1.t("Prefix.gs1CompanyPrefixCantStartWith00000"));
|
|
2844
|
-
}
|
|
2845
|
-
baseValidation = GS1_8_PREFIX_AS_GS1_COMPANY_PREFIX_VALIDATION;
|
|
2846
|
-
} else {
|
|
2847
|
-
throw new RangeError(i18nextGS1.t("Prefix.gs1CompanyPrefixCantStartWith000000"));
|
|
2848
|
-
}
|
|
2849
|
-
break;
|
|
2850
|
-
case PrefixTypes.UPCCompanyPrefix:
|
|
2851
|
-
if (prefix.startsWith("0000")) {
|
|
2852
|
-
throw new RangeError(i18nextGS1.t("Prefix.upcCompanyPrefixCantStartWith0000"));
|
|
2853
|
-
}
|
|
2854
|
-
baseValidation = UPC_COMPANY_PREFIX_VALIDATION;
|
|
2855
|
-
break;
|
|
2856
|
-
case PrefixTypes.GS18Prefix:
|
|
2857
|
-
if (prefix.startsWith("0")) {
|
|
2858
|
-
throw new RangeError(i18nextGS1.t("Prefix.gs18PrefixCantStartWith0"));
|
|
2859
|
-
}
|
|
2860
|
-
baseValidation = GS1_8_PREFIX_VALIDATION;
|
|
2861
|
-
break;
|
|
2862
|
-
}
|
|
2863
|
-
const mergedValidation = {
|
|
2864
|
-
...baseValidation,
|
|
2865
|
-
positionOffset
|
|
2866
|
-
};
|
|
2867
|
-
if (!isFromIdentifier) {
|
|
2868
|
-
import_utility4.NUMERIC_CREATOR.validate(prefix, mergedValidation);
|
|
2869
|
-
} else if (!isNumericIdentifier) {
|
|
2870
|
-
import_utility4.NUMERIC_CREATOR.validate(prefix.substring(0, Math.min(mergedValidation.minimumLength, prefix.length - 1)), mergedValidation);
|
|
2871
|
-
}
|
|
2872
|
-
}
|
|
2873
2829
|
var PrefixValidator = {
|
|
2874
2830
|
GS1_COMPANY_PREFIX_MINIMUM_LENGTH,
|
|
2875
2831
|
GS1_COMPANY_PREFIX_MAXIMUM_LENGTH,
|
|
@@ -2877,7 +2833,139 @@ var PrefixValidator = {
|
|
|
2877
2833
|
UPC_COMPANY_PREFIX_MAXIMUM_LENGTH,
|
|
2878
2834
|
GS1_8_PREFIX_MINIMUM_LENGTH,
|
|
2879
2835
|
GS1_8_PREFIX_MAXIMUM_LENGTH,
|
|
2880
|
-
|
|
2836
|
+
/**
|
|
2837
|
+
* Validate a prefix.
|
|
2838
|
+
*
|
|
2839
|
+
* @param prefixType
|
|
2840
|
+
* Prefix type.
|
|
2841
|
+
*
|
|
2842
|
+
* @param allowUPCCompanyPrefix
|
|
2843
|
+
* If true, a U.P.C. Company Prefix expressed as a GS1 Company Prefix is permitted.
|
|
2844
|
+
*
|
|
2845
|
+
* @param allowGS18Prefix
|
|
2846
|
+
* If true, a GS1-8 Prefix expressed as a GS1 Company Prefix is permitted.
|
|
2847
|
+
*
|
|
2848
|
+
* @param prefix
|
|
2849
|
+
* Prefix.
|
|
2850
|
+
*
|
|
2851
|
+
* @param isFromIdentifier
|
|
2852
|
+
* If true, the prefix is from an identifier and should be trimmed before its character set is validated.
|
|
2853
|
+
*
|
|
2854
|
+
* @param isNumericIdentifier
|
|
2855
|
+
* If true, the prefix is from a numeric identifier and its character set will be validated by the caller.
|
|
2856
|
+
*
|
|
2857
|
+
* @param positionOffset
|
|
2858
|
+
* Position offset within a larger string.
|
|
2859
|
+
*/
|
|
2860
|
+
validate(prefixType, allowUPCCompanyPrefix, allowGS18Prefix, prefix, isFromIdentifier = false, isNumericIdentifier = false, positionOffset) {
|
|
2861
|
+
let baseValidation;
|
|
2862
|
+
switch (prefixType) {
|
|
2863
|
+
case PrefixTypes.GS1CompanyPrefix:
|
|
2864
|
+
if (!prefix.startsWith("0")) {
|
|
2865
|
+
baseValidation = GS1_COMPANY_PREFIX_VALIDATION;
|
|
2866
|
+
} else if (!prefix.startsWith("00000")) {
|
|
2867
|
+
if (!allowUPCCompanyPrefix) {
|
|
2868
|
+
throw new RangeError(i18nextGS1.t("Prefix.gs1CompanyPrefixCantStartWith0"));
|
|
2869
|
+
}
|
|
2870
|
+
baseValidation = UPC_COMPANY_PREFIX_AS_GS1_COMPANY_PREFIX_VALIDATION;
|
|
2871
|
+
} else if (!prefix.startsWith("000000")) {
|
|
2872
|
+
if (!allowGS18Prefix) {
|
|
2873
|
+
throw new RangeError(i18nextGS1.t("Prefix.gs1CompanyPrefixCantStartWith00000"));
|
|
2874
|
+
}
|
|
2875
|
+
baseValidation = GS1_8_PREFIX_AS_GS1_COMPANY_PREFIX_VALIDATION;
|
|
2876
|
+
} else {
|
|
2877
|
+
throw new RangeError(i18nextGS1.t("Prefix.gs1CompanyPrefixCantStartWith000000"));
|
|
2878
|
+
}
|
|
2879
|
+
break;
|
|
2880
|
+
case PrefixTypes.UPCCompanyPrefix:
|
|
2881
|
+
if (prefix.startsWith("0000")) {
|
|
2882
|
+
throw new RangeError(i18nextGS1.t("Prefix.upcCompanyPrefixCantStartWith0000"));
|
|
2883
|
+
}
|
|
2884
|
+
baseValidation = UPC_COMPANY_PREFIX_VALIDATION;
|
|
2885
|
+
break;
|
|
2886
|
+
case PrefixTypes.GS18Prefix:
|
|
2887
|
+
if (prefix.startsWith("0")) {
|
|
2888
|
+
throw new RangeError(i18nextGS1.t("Prefix.gs18PrefixCantStartWith0"));
|
|
2889
|
+
}
|
|
2890
|
+
baseValidation = GS1_8_PREFIX_VALIDATION;
|
|
2891
|
+
break;
|
|
2892
|
+
}
|
|
2893
|
+
const mergedValidation = {
|
|
2894
|
+
...baseValidation,
|
|
2895
|
+
positionOffset
|
|
2896
|
+
};
|
|
2897
|
+
if (!isFromIdentifier) {
|
|
2898
|
+
import_utility4.NUMERIC_CREATOR.validate(prefix, mergedValidation);
|
|
2899
|
+
} else if (!isNumericIdentifier) {
|
|
2900
|
+
import_utility4.NUMERIC_CREATOR.validate(prefix.substring(0, Math.min(mergedValidation.minimumLength, prefix.length - 1)), mergedValidation);
|
|
2901
|
+
}
|
|
2902
|
+
},
|
|
2903
|
+
/**
|
|
2904
|
+
* Normalize a prefix.
|
|
2905
|
+
*
|
|
2906
|
+
* @param prefixType
|
|
2907
|
+
* Prefix type.
|
|
2908
|
+
*
|
|
2909
|
+
* @param prefix
|
|
2910
|
+
* Prefix.
|
|
2911
|
+
*
|
|
2912
|
+
* @returns
|
|
2913
|
+
* Prefix provider with normalized prefix type and prefix.
|
|
2914
|
+
*/
|
|
2915
|
+
normalize(prefixType, prefix) {
|
|
2916
|
+
this.validate(prefixType, true, true, prefix);
|
|
2917
|
+
let gs1CompanyPrefix;
|
|
2918
|
+
switch (prefixType) {
|
|
2919
|
+
case PrefixTypes.GS1CompanyPrefix:
|
|
2920
|
+
gs1CompanyPrefix = prefix;
|
|
2921
|
+
break;
|
|
2922
|
+
case PrefixTypes.UPCCompanyPrefix:
|
|
2923
|
+
gs1CompanyPrefix = "0" + prefix;
|
|
2924
|
+
break;
|
|
2925
|
+
case PrefixTypes.GS18Prefix:
|
|
2926
|
+
gs1CompanyPrefix = "00000" + prefix;
|
|
2927
|
+
break;
|
|
2928
|
+
}
|
|
2929
|
+
let normalizedPrefixType;
|
|
2930
|
+
let normalizedPrefix;
|
|
2931
|
+
let upcCompanyPrefix = void 0;
|
|
2932
|
+
let gs18Prefix = void 0;
|
|
2933
|
+
if (!gs1CompanyPrefix.startsWith("0")) {
|
|
2934
|
+
normalizedPrefixType = PrefixTypes.GS1CompanyPrefix;
|
|
2935
|
+
normalizedPrefix = gs1CompanyPrefix;
|
|
2936
|
+
} else if (!gs1CompanyPrefix.startsWith("00000")) {
|
|
2937
|
+
normalizedPrefixType = PrefixTypes.UPCCompanyPrefix;
|
|
2938
|
+
upcCompanyPrefix = gs1CompanyPrefix.substring(1);
|
|
2939
|
+
normalizedPrefix = upcCompanyPrefix;
|
|
2940
|
+
} else {
|
|
2941
|
+
normalizedPrefixType = PrefixTypes.GS18Prefix;
|
|
2942
|
+
gs18Prefix = gs1CompanyPrefix.substring(5);
|
|
2943
|
+
normalizedPrefix = gs18Prefix;
|
|
2944
|
+
}
|
|
2945
|
+
return {
|
|
2946
|
+
prefixType: normalizedPrefixType,
|
|
2947
|
+
prefix: normalizedPrefix,
|
|
2948
|
+
gs1CompanyPrefix,
|
|
2949
|
+
upcCompanyPrefix,
|
|
2950
|
+
gs18Prefix
|
|
2951
|
+
};
|
|
2952
|
+
}
|
|
2953
|
+
};
|
|
2954
|
+
|
|
2955
|
+
// src/content-character-set.ts
|
|
2956
|
+
var ContentCharacterSets = {
|
|
2957
|
+
/**
|
|
2958
|
+
* Numeric.
|
|
2959
|
+
*/
|
|
2960
|
+
Numeric: "Numeric",
|
|
2961
|
+
/**
|
|
2962
|
+
* GS1 AI encodable character set 82.
|
|
2963
|
+
*/
|
|
2964
|
+
AI82: "AI82",
|
|
2965
|
+
/**
|
|
2966
|
+
* GS1 AI encodable character set 39.
|
|
2967
|
+
*/
|
|
2968
|
+
AI39: "AI39"
|
|
2881
2969
|
};
|
|
2882
2970
|
|
|
2883
2971
|
// src/identifier-type.ts
|
|
@@ -2932,22 +3020,200 @@ var IdentifierTypes = {
|
|
|
2932
3020
|
GMN: "GMN"
|
|
2933
3021
|
};
|
|
2934
3022
|
|
|
2935
|
-
// src/identifier-
|
|
2936
|
-
var
|
|
2937
|
-
var ContentCharacterSets = {
|
|
3023
|
+
// src/numeric-identifier-type.ts
|
|
3024
|
+
var LeaderTypes = {
|
|
2938
3025
|
/**
|
|
2939
|
-
*
|
|
3026
|
+
* No leader.
|
|
2940
3027
|
*/
|
|
2941
|
-
|
|
3028
|
+
None: "None",
|
|
2942
3029
|
/**
|
|
2943
|
-
*
|
|
3030
|
+
* Indicator digit (GTIN only).
|
|
2944
3031
|
*/
|
|
2945
|
-
|
|
3032
|
+
IndicatorDigit: "Indicator digit",
|
|
2946
3033
|
/**
|
|
2947
|
-
*
|
|
3034
|
+
* Extension digit (SSCC only).
|
|
2948
3035
|
*/
|
|
2949
|
-
|
|
3036
|
+
ExtensionDigit: "Extension digit"
|
|
2950
3037
|
};
|
|
3038
|
+
|
|
3039
|
+
// src/gtin-type.ts
|
|
3040
|
+
var GTINTypes = {
|
|
3041
|
+
/**
|
|
3042
|
+
* GTIN-13.
|
|
3043
|
+
*/
|
|
3044
|
+
GTIN13: 13,
|
|
3045
|
+
/**
|
|
3046
|
+
* GTIN-12.
|
|
3047
|
+
*/
|
|
3048
|
+
GTIN12: 12,
|
|
3049
|
+
/**
|
|
3050
|
+
* GTIN-8.
|
|
3051
|
+
*/
|
|
3052
|
+
GTIN8: 8,
|
|
3053
|
+
/**
|
|
3054
|
+
* GTIN-14.
|
|
3055
|
+
*/
|
|
3056
|
+
GTIN14: 14
|
|
3057
|
+
};
|
|
3058
|
+
var GTIN_BASE_TYPES = {
|
|
3059
|
+
[PrefixTypes.GS1CompanyPrefix]: GTINTypes.GTIN13,
|
|
3060
|
+
[PrefixTypes.UPCCompanyPrefix]: GTINTypes.GTIN12,
|
|
3061
|
+
[PrefixTypes.GS18Prefix]: GTINTypes.GTIN8
|
|
3062
|
+
};
|
|
3063
|
+
|
|
3064
|
+
// src/descriptors.ts
|
|
3065
|
+
var GTIN13_DESCRIPTOR = {
|
|
3066
|
+
identifierType: IdentifierTypes.GTIN,
|
|
3067
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3068
|
+
length: GTINTypes.GTIN13,
|
|
3069
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
3070
|
+
leaderType: LeaderTypes.IndicatorDigit
|
|
3071
|
+
};
|
|
3072
|
+
var GTIN12_DESCRIPTOR = {
|
|
3073
|
+
identifierType: IdentifierTypes.GTIN,
|
|
3074
|
+
prefixType: PrefixTypes.UPCCompanyPrefix,
|
|
3075
|
+
length: GTINTypes.GTIN12,
|
|
3076
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
3077
|
+
leaderType: LeaderTypes.IndicatorDigit
|
|
3078
|
+
};
|
|
3079
|
+
var GTIN8_DESCRIPTOR = {
|
|
3080
|
+
identifierType: IdentifierTypes.GTIN,
|
|
3081
|
+
prefixType: PrefixTypes.GS18Prefix,
|
|
3082
|
+
length: GTINTypes.GTIN8,
|
|
3083
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
3084
|
+
leaderType: LeaderTypes.IndicatorDigit
|
|
3085
|
+
};
|
|
3086
|
+
var GTIN_DESCRIPTORS = {
|
|
3087
|
+
[GTINTypes.GTIN13]: GTIN13_DESCRIPTOR,
|
|
3088
|
+
[GTINTypes.GTIN12]: GTIN12_DESCRIPTOR,
|
|
3089
|
+
[GTINTypes.GTIN8]: GTIN8_DESCRIPTOR
|
|
3090
|
+
};
|
|
3091
|
+
var GLN_DESCRIPTOR = {
|
|
3092
|
+
identifierType: IdentifierTypes.GLN,
|
|
3093
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3094
|
+
length: 13,
|
|
3095
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
3096
|
+
leaderType: LeaderTypes.None
|
|
3097
|
+
};
|
|
3098
|
+
var SSCC_DESCRIPTOR = {
|
|
3099
|
+
identifierType: IdentifierTypes.SSCC,
|
|
3100
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3101
|
+
length: 18,
|
|
3102
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
3103
|
+
leaderType: LeaderTypes.ExtensionDigit
|
|
3104
|
+
};
|
|
3105
|
+
var GRAI_DESCRIPTOR = {
|
|
3106
|
+
identifierType: IdentifierTypes.GRAI,
|
|
3107
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3108
|
+
length: 13,
|
|
3109
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
3110
|
+
leaderType: LeaderTypes.None,
|
|
3111
|
+
serialComponentLength: 16,
|
|
3112
|
+
serialComponentCharacterSet: ContentCharacterSets.AI82
|
|
3113
|
+
};
|
|
3114
|
+
var GIAI_DESCRIPTOR = {
|
|
3115
|
+
identifierType: IdentifierTypes.GIAI,
|
|
3116
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3117
|
+
length: 30,
|
|
3118
|
+
referenceCharacterSet: ContentCharacterSets.AI82,
|
|
3119
|
+
requiresCheckCharacterPair: false
|
|
3120
|
+
};
|
|
3121
|
+
var GSRN_DESCRIPTOR = {
|
|
3122
|
+
identifierType: IdentifierTypes.GSRN,
|
|
3123
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3124
|
+
length: 18,
|
|
3125
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
3126
|
+
leaderType: LeaderTypes.None
|
|
3127
|
+
};
|
|
3128
|
+
var GDTI_DESCRIPTOR = {
|
|
3129
|
+
identifierType: IdentifierTypes.GDTI,
|
|
3130
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3131
|
+
length: 13,
|
|
3132
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
3133
|
+
leaderType: LeaderTypes.None,
|
|
3134
|
+
serialComponentLength: 17,
|
|
3135
|
+
serialComponentCharacterSet: ContentCharacterSets.AI82
|
|
3136
|
+
};
|
|
3137
|
+
var GINC_DESCRIPTOR = {
|
|
3138
|
+
identifierType: IdentifierTypes.GINC,
|
|
3139
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3140
|
+
length: 30,
|
|
3141
|
+
referenceCharacterSet: ContentCharacterSets.AI82,
|
|
3142
|
+
requiresCheckCharacterPair: false
|
|
3143
|
+
};
|
|
3144
|
+
var GSIN_DESCRIPTOR = {
|
|
3145
|
+
identifierType: IdentifierTypes.GSIN,
|
|
3146
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3147
|
+
length: 17,
|
|
3148
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
3149
|
+
leaderType: LeaderTypes.None
|
|
3150
|
+
};
|
|
3151
|
+
var GCN_DESCRIPTOR = {
|
|
3152
|
+
identifierType: IdentifierTypes.GCN,
|
|
3153
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3154
|
+
length: 13,
|
|
3155
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
3156
|
+
leaderType: LeaderTypes.None,
|
|
3157
|
+
serialComponentLength: 12,
|
|
3158
|
+
serialComponentCharacterSet: ContentCharacterSets.Numeric
|
|
3159
|
+
};
|
|
3160
|
+
var CPID_DESCRIPTOR = {
|
|
3161
|
+
identifierType: IdentifierTypes.CPID,
|
|
3162
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3163
|
+
length: 30,
|
|
3164
|
+
referenceCharacterSet: ContentCharacterSets.AI39,
|
|
3165
|
+
requiresCheckCharacterPair: false
|
|
3166
|
+
};
|
|
3167
|
+
var GMN_DESCRIPTOR = {
|
|
3168
|
+
identifierType: IdentifierTypes.GMN,
|
|
3169
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
3170
|
+
length: 25,
|
|
3171
|
+
referenceCharacterSet: ContentCharacterSets.AI82,
|
|
3172
|
+
requiresCheckCharacterPair: true
|
|
3173
|
+
};
|
|
3174
|
+
var IdentifierDescriptors = {
|
|
3175
|
+
[IdentifierTypes.GTIN]: GTIN_DESCRIPTORS,
|
|
3176
|
+
[IdentifierTypes.GLN]: GLN_DESCRIPTOR,
|
|
3177
|
+
[IdentifierTypes.SSCC]: SSCC_DESCRIPTOR,
|
|
3178
|
+
[IdentifierTypes.GRAI]: GRAI_DESCRIPTOR,
|
|
3179
|
+
[IdentifierTypes.GIAI]: GIAI_DESCRIPTOR,
|
|
3180
|
+
[IdentifierTypes.GSRN]: GSRN_DESCRIPTOR,
|
|
3181
|
+
[IdentifierTypes.GDTI]: GDTI_DESCRIPTOR,
|
|
3182
|
+
[IdentifierTypes.GINC]: GINC_DESCRIPTOR,
|
|
3183
|
+
[IdentifierTypes.GSIN]: GSIN_DESCRIPTOR,
|
|
3184
|
+
[IdentifierTypes.GCN]: GCN_DESCRIPTOR,
|
|
3185
|
+
[IdentifierTypes.CPID]: CPID_DESCRIPTOR,
|
|
3186
|
+
[IdentifierTypes.GMN]: GMN_DESCRIPTOR
|
|
3187
|
+
};
|
|
3188
|
+
function isGTINDescriptors(identifierDescriptorsOrDescriptor) {
|
|
3189
|
+
return !("identifierType" in identifierDescriptorsOrDescriptor);
|
|
3190
|
+
}
|
|
3191
|
+
function identifierTypesIncludes(identifierTypes, identifierType) {
|
|
3192
|
+
return identifierTypes.includes(identifierType);
|
|
3193
|
+
}
|
|
3194
|
+
var NUMERIC_IDENTIFIER_TYPES = [IdentifierTypes.GTIN, IdentifierTypes.GLN, IdentifierTypes.SSCC, IdentifierTypes.GRAI, IdentifierTypes.GSRN, IdentifierTypes.GDTI, IdentifierTypes.GSIN, IdentifierTypes.GCN];
|
|
3195
|
+
function isNumericIdentifierDescriptor(identifierDescriptor) {
|
|
3196
|
+
return identifierTypesIncludes(NUMERIC_IDENTIFIER_TYPES, identifierDescriptor.identifierType);
|
|
3197
|
+
}
|
|
3198
|
+
function isGTINDescriptor(identifierDescriptor) {
|
|
3199
|
+
return identifierDescriptor.identifierType === IdentifierTypes.GTIN;
|
|
3200
|
+
}
|
|
3201
|
+
function isNonGTINNumericIdentifierDescriptor(identifierDescriptor) {
|
|
3202
|
+
return isNumericIdentifierDescriptor(identifierDescriptor) && !isGTINDescriptor(identifierDescriptor);
|
|
3203
|
+
}
|
|
3204
|
+
var SERIALIZABLE_NUMERIC_IDENTIFIER_TYPES = [IdentifierTypes.GRAI, IdentifierTypes.GDTI, IdentifierTypes.GCN];
|
|
3205
|
+
function isSerializableNumericIdentifierDescriptor(identifierDescriptor) {
|
|
3206
|
+
return identifierTypesIncludes(SERIALIZABLE_NUMERIC_IDENTIFIER_TYPES, identifierDescriptor.identifierType);
|
|
3207
|
+
}
|
|
3208
|
+
function isNonNumericIdentifierDescriptor(identifierDescriptor) {
|
|
3209
|
+
return !isNumericIdentifierDescriptor(identifierDescriptor);
|
|
3210
|
+
}
|
|
3211
|
+
|
|
3212
|
+
// src/gtin-validator.ts
|
|
3213
|
+
var import_utility6 = require("@aidc-toolkit/utility");
|
|
3214
|
+
|
|
3215
|
+
// src/abstract-identifier-validator.ts
|
|
3216
|
+
var import_utility5 = require("@aidc-toolkit/utility");
|
|
2951
3217
|
var AbstractIdentifierValidator = class _AbstractIdentifierValidator {
|
|
2952
3218
|
static CHARACTER_SET_CREATORS = {
|
|
2953
3219
|
[ContentCharacterSets.Numeric]: import_utility5.NUMERIC_CREATOR,
|
|
@@ -2958,10 +3224,6 @@ var AbstractIdentifierValidator = class _AbstractIdentifierValidator {
|
|
|
2958
3224
|
* Identifier type.
|
|
2959
3225
|
*/
|
|
2960
3226
|
_identifierType;
|
|
2961
|
-
/**
|
|
2962
|
-
* Prefix type.
|
|
2963
|
-
*/
|
|
2964
|
-
_prefixType;
|
|
2965
3227
|
/**
|
|
2966
3228
|
* Length.
|
|
2967
3229
|
*/
|
|
@@ -2989,24 +3251,14 @@ var AbstractIdentifierValidator = class _AbstractIdentifierValidator {
|
|
|
2989
3251
|
/**
|
|
2990
3252
|
* Constructor.
|
|
2991
3253
|
*
|
|
2992
|
-
* @param
|
|
2993
|
-
* Identifier
|
|
2994
|
-
*
|
|
2995
|
-
* @param prefixType
|
|
2996
|
-
* Prefix type.
|
|
2997
|
-
*
|
|
2998
|
-
* @param length
|
|
2999
|
-
* Length.
|
|
3000
|
-
*
|
|
3001
|
-
* @param referenceCharacterSet
|
|
3002
|
-
* Reference character set.
|
|
3254
|
+
* @param identifierDescriptor
|
|
3255
|
+
* Identifier descriptor.
|
|
3003
3256
|
*/
|
|
3004
|
-
constructor(
|
|
3005
|
-
this._identifierType = identifierType;
|
|
3006
|
-
this.
|
|
3007
|
-
this.
|
|
3008
|
-
this.
|
|
3009
|
-
this._referenceCreator = _AbstractIdentifierValidator.creatorFor(referenceCharacterSet);
|
|
3257
|
+
constructor(identifierDescriptor) {
|
|
3258
|
+
this._identifierType = identifierDescriptor.identifierType;
|
|
3259
|
+
this._length = identifierDescriptor.length;
|
|
3260
|
+
this._referenceCharacterSet = identifierDescriptor.referenceCharacterSet;
|
|
3261
|
+
this._referenceCreator = _AbstractIdentifierValidator.creatorFor(identifierDescriptor.referenceCharacterSet);
|
|
3010
3262
|
}
|
|
3011
3263
|
/**
|
|
3012
3264
|
* @inheritDoc
|
|
@@ -3018,7 +3270,7 @@ var AbstractIdentifierValidator = class _AbstractIdentifierValidator {
|
|
|
3018
3270
|
* @inheritDoc
|
|
3019
3271
|
*/
|
|
3020
3272
|
get prefixType() {
|
|
3021
|
-
return
|
|
3273
|
+
return PrefixTypes.GS1CompanyPrefix;
|
|
3022
3274
|
}
|
|
3023
3275
|
/**
|
|
3024
3276
|
* @inheritDoc
|
|
@@ -3045,14 +3297,14 @@ var AbstractIdentifierValidator = class _AbstractIdentifierValidator {
|
|
|
3045
3297
|
* @param identifier
|
|
3046
3298
|
* Identifier.
|
|
3047
3299
|
*
|
|
3048
|
-
* @param
|
|
3049
|
-
*
|
|
3300
|
+
* @param positionOffset
|
|
3301
|
+
* Position offset within a larger string.
|
|
3050
3302
|
*
|
|
3051
3303
|
* @returns
|
|
3052
3304
|
* Padded identifier.
|
|
3053
3305
|
*/
|
|
3054
|
-
padIdentifier(identifier,
|
|
3055
|
-
return
|
|
3306
|
+
padIdentifier(identifier, positionOffset) {
|
|
3307
|
+
return positionOffset === void 0 ? identifier : this.referenceCreator.character(0).repeat(positionOffset).concat(identifier);
|
|
3056
3308
|
}
|
|
3057
3309
|
/**
|
|
3058
3310
|
* Validate the prefix within an identifier.
|
|
@@ -3068,21 +3320,7 @@ var AbstractIdentifierValidator = class _AbstractIdentifierValidator {
|
|
|
3068
3320
|
}
|
|
3069
3321
|
};
|
|
3070
3322
|
|
|
3071
|
-
// src/numeric-identifier-validator.ts
|
|
3072
|
-
var LeaderTypes = {
|
|
3073
|
-
/**
|
|
3074
|
-
* No leader.
|
|
3075
|
-
*/
|
|
3076
|
-
None: "None",
|
|
3077
|
-
/**
|
|
3078
|
-
* Indicator digit (GTIN only).
|
|
3079
|
-
*/
|
|
3080
|
-
IndicatorDigit: "Indicator digit",
|
|
3081
|
-
/**
|
|
3082
|
-
* Extension digit (SSCC only).
|
|
3083
|
-
*/
|
|
3084
|
-
ExtensionDigit: "Extension digit"
|
|
3085
|
-
};
|
|
3323
|
+
// src/abstract-numeric-identifier-validator.ts
|
|
3086
3324
|
var AbstractNumericIdentifierValidator = class extends AbstractIdentifierValidator {
|
|
3087
3325
|
/**
|
|
3088
3326
|
* Leader type.
|
|
@@ -3095,21 +3333,12 @@ var AbstractNumericIdentifierValidator = class extends AbstractIdentifierValidat
|
|
|
3095
3333
|
/**
|
|
3096
3334
|
* Constructor.
|
|
3097
3335
|
*
|
|
3098
|
-
* @param
|
|
3099
|
-
* Identifier
|
|
3100
|
-
*
|
|
3101
|
-
* @param prefixType
|
|
3102
|
-
* Prefix type.
|
|
3103
|
-
*
|
|
3104
|
-
* @param length
|
|
3105
|
-
* Length.
|
|
3106
|
-
*
|
|
3107
|
-
* @param leaderType
|
|
3108
|
-
* Leader type.
|
|
3336
|
+
* @param identifierDescriptor
|
|
3337
|
+
* Identifier descriptor.
|
|
3109
3338
|
*/
|
|
3110
|
-
constructor(
|
|
3111
|
-
super(
|
|
3112
|
-
this._leaderType = leaderType;
|
|
3339
|
+
constructor(identifierDescriptor) {
|
|
3340
|
+
super(identifierDescriptor);
|
|
3341
|
+
this._leaderType = identifierDescriptor.leaderType;
|
|
3113
3342
|
this._prefixPosition = Number(this.leaderType === LeaderTypes.ExtensionDigit);
|
|
3114
3343
|
}
|
|
3115
3344
|
/**
|
|
@@ -3133,32 +3362,13 @@ var AbstractNumericIdentifierValidator = class extends AbstractIdentifierValidat
|
|
|
3133
3362
|
length: this.length
|
|
3134
3363
|
}));
|
|
3135
3364
|
}
|
|
3136
|
-
if (!hasValidCheckDigit(this.padIdentifier(identifier, validation))) {
|
|
3365
|
+
if (!hasValidCheckDigit(this.padIdentifier(identifier, validation?.positionOffset))) {
|
|
3137
3366
|
throw new RangeError(i18nextGS1.t("Identifier.invalidCheckDigit"));
|
|
3138
3367
|
}
|
|
3139
3368
|
}
|
|
3140
3369
|
};
|
|
3141
3370
|
|
|
3142
3371
|
// src/gtin-validator.ts
|
|
3143
|
-
var import_utility6 = require("@aidc-toolkit/utility");
|
|
3144
|
-
var GTINTypes = {
|
|
3145
|
-
/**
|
|
3146
|
-
* GTIN-13.
|
|
3147
|
-
*/
|
|
3148
|
-
GTIN13: 13,
|
|
3149
|
-
/**
|
|
3150
|
-
* GTIN-12.
|
|
3151
|
-
*/
|
|
3152
|
-
GTIN12: 12,
|
|
3153
|
-
/**
|
|
3154
|
-
* GTIN-8.
|
|
3155
|
-
*/
|
|
3156
|
-
GTIN8: 8,
|
|
3157
|
-
/**
|
|
3158
|
-
* GTIN-14.
|
|
3159
|
-
*/
|
|
3160
|
-
GTIN14: 14
|
|
3161
|
-
};
|
|
3162
3372
|
var GTINLevels = {
|
|
3163
3373
|
/**
|
|
3164
3374
|
* Any level (level is ignored).
|
|
@@ -3189,28 +3399,26 @@ var GTINValidator = class _GTINValidator extends AbstractNumericIdentifierValida
|
|
|
3189
3399
|
minimumLength: 8,
|
|
3190
3400
|
maximumLength: 8
|
|
3191
3401
|
};
|
|
3402
|
+
/**
|
|
3403
|
+
* Prefix type.
|
|
3404
|
+
*/
|
|
3405
|
+
_prefixType;
|
|
3192
3406
|
/**
|
|
3193
3407
|
* Constructor.
|
|
3194
3408
|
*
|
|
3195
|
-
* @param
|
|
3196
|
-
* GTIN type.
|
|
3409
|
+
* @param gtinBaseType
|
|
3410
|
+
* GTIN base type (all except GTIN-14).
|
|
3197
3411
|
*/
|
|
3198
|
-
constructor(
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
prefixType = PrefixTypes.GS18Prefix;
|
|
3209
|
-
break;
|
|
3210
|
-
default:
|
|
3211
|
-
throw new Error("Not supported");
|
|
3212
|
-
}
|
|
3213
|
-
super(IdentifierTypes.GTIN, prefixType, gtinType, LeaderTypes.IndicatorDigit);
|
|
3412
|
+
constructor(gtinBaseType) {
|
|
3413
|
+
const identifierDescriptor = IdentifierDescriptors.GTIN[gtinBaseType];
|
|
3414
|
+
super(identifierDescriptor);
|
|
3415
|
+
this._prefixType = identifierDescriptor.prefixType;
|
|
3416
|
+
}
|
|
3417
|
+
/**
|
|
3418
|
+
* @inheritDoc
|
|
3419
|
+
*/
|
|
3420
|
+
get prefixType() {
|
|
3421
|
+
return this._prefixType;
|
|
3214
3422
|
}
|
|
3215
3423
|
/**
|
|
3216
3424
|
* @inheritDoc
|
|
@@ -3527,9 +3735,9 @@ var GTIN13_VALIDATOR = new GTINValidator(GTINTypes.GTIN13);
|
|
|
3527
3735
|
var GTIN12_VALIDATOR = new GTINValidator(GTINTypes.GTIN12);
|
|
3528
3736
|
var GTIN8_VALIDATOR = new GTINValidator(GTINTypes.GTIN8);
|
|
3529
3737
|
var GTIN_VALIDATORS = {
|
|
3530
|
-
[
|
|
3531
|
-
[
|
|
3532
|
-
[
|
|
3738
|
+
[GTINTypes.GTIN13]: GTIN13_VALIDATOR,
|
|
3739
|
+
[GTINTypes.GTIN12]: GTIN12_VALIDATOR,
|
|
3740
|
+
[GTINTypes.GTIN8]: GTIN8_VALIDATOR
|
|
3533
3741
|
};
|
|
3534
3742
|
|
|
3535
3743
|
// src/non-gtin-numeric-identifier-validator.ts
|
|
@@ -3539,24 +3747,14 @@ var NonGTINNumericIdentifierValidator = class extends AbstractNumericIdentifierV
|
|
|
3539
3747
|
*
|
|
3540
3748
|
* @param identifierType
|
|
3541
3749
|
* Identifier type.
|
|
3542
|
-
*
|
|
3543
|
-
* @param length
|
|
3544
|
-
* Length.
|
|
3545
|
-
*
|
|
3546
|
-
* @param leaderType
|
|
3547
|
-
* Leader type.
|
|
3548
3750
|
*/
|
|
3549
|
-
constructor(identifierType
|
|
3550
|
-
super(identifierType
|
|
3751
|
+
constructor(identifierType) {
|
|
3752
|
+
super(IdentifierDescriptors[identifierType]);
|
|
3551
3753
|
}
|
|
3552
3754
|
};
|
|
3553
|
-
var GLN_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.GLN, 13);
|
|
3554
|
-
var SSCC_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.SSCC, 18, LeaderTypes.ExtensionDigit);
|
|
3555
|
-
var GSRN_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.GSRN, 18);
|
|
3556
|
-
var GSIN_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.GSIN, 17);
|
|
3557
3755
|
|
|
3558
3756
|
// src/serializable-numeric-identifier-validator.ts
|
|
3559
|
-
var SerializableNumericIdentifierValidator = class _SerializableNumericIdentifierValidator extends
|
|
3757
|
+
var SerializableNumericIdentifierValidator = class _SerializableNumericIdentifierValidator extends AbstractNumericIdentifierValidator {
|
|
3560
3758
|
/**
|
|
3561
3759
|
* Serial component length.
|
|
3562
3760
|
*/
|
|
@@ -3578,26 +3776,18 @@ var SerializableNumericIdentifierValidator = class _SerializableNumericIdentifie
|
|
|
3578
3776
|
*
|
|
3579
3777
|
* @param identifierType
|
|
3580
3778
|
* Identifier type.
|
|
3581
|
-
*
|
|
3582
|
-
* @param length
|
|
3583
|
-
* Length.
|
|
3584
|
-
*
|
|
3585
|
-
* @param serialComponentLength
|
|
3586
|
-
* Serial component length.
|
|
3587
|
-
*
|
|
3588
|
-
* @param serialComponentCharacterSet
|
|
3589
|
-
* Serial component character set.
|
|
3590
3779
|
*/
|
|
3591
|
-
constructor(identifierType
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
this.
|
|
3780
|
+
constructor(identifierType) {
|
|
3781
|
+
const identifierDescriptor = IdentifierDescriptors[identifierType];
|
|
3782
|
+
super(identifierDescriptor);
|
|
3783
|
+
this._serialComponentLength = identifierDescriptor.serialComponentLength;
|
|
3784
|
+
this._serialComponentCharacterSet = identifierDescriptor.serialComponentCharacterSet;
|
|
3595
3785
|
this._serialComponentValidation = {
|
|
3596
3786
|
minimumLength: 1,
|
|
3597
|
-
maximumLength: serialComponentLength,
|
|
3787
|
+
maximumLength: identifierDescriptor.serialComponentLength,
|
|
3598
3788
|
component: () => i18nextGS1.t("Identifier.serialComponent")
|
|
3599
3789
|
};
|
|
3600
|
-
this._serialComponentCreator = _SerializableNumericIdentifierValidator.creatorFor(serialComponentCharacterSet);
|
|
3790
|
+
this._serialComponentCreator = _SerializableNumericIdentifierValidator.creatorFor(identifierDescriptor.serialComponentCharacterSet);
|
|
3601
3791
|
}
|
|
3602
3792
|
/**
|
|
3603
3793
|
* Get the serial component length.
|
|
@@ -3633,9 +3823,6 @@ var SerializableNumericIdentifierValidator = class _SerializableNumericIdentifie
|
|
|
3633
3823
|
}
|
|
3634
3824
|
}
|
|
3635
3825
|
};
|
|
3636
|
-
var GRAI_VALIDATOR = new SerializableNumericIdentifierValidator(IdentifierTypes.GRAI, 13, 16, ContentCharacterSets.AI82);
|
|
3637
|
-
var GDTI_VALIDATOR = new SerializableNumericIdentifierValidator(IdentifierTypes.GDTI, 13, 17, ContentCharacterSets.AI82);
|
|
3638
|
-
var GCN_VALIDATOR = new SerializableNumericIdentifierValidator(IdentifierTypes.GCN, 13, 12, ContentCharacterSets.Numeric);
|
|
3639
3826
|
|
|
3640
3827
|
// src/non-numeric-identifier-validator.ts
|
|
3641
3828
|
var import_utility7 = require("@aidc-toolkit/utility");
|
|
@@ -3660,19 +3847,11 @@ var NonNumericIdentifierValidator = class _NonNumericIdentifierValidator extends
|
|
|
3660
3847
|
*
|
|
3661
3848
|
* @param identifierType
|
|
3662
3849
|
* Identifier type.
|
|
3663
|
-
*
|
|
3664
|
-
* @param length
|
|
3665
|
-
* Length.
|
|
3666
|
-
*
|
|
3667
|
-
* @param referenceCharacterSet
|
|
3668
|
-
* Reference character set.
|
|
3669
|
-
*
|
|
3670
|
-
* @param requiresCheckCharacterPair
|
|
3671
|
-
* True if the identifier requires a check character pair.
|
|
3672
3850
|
*/
|
|
3673
|
-
constructor(identifierType
|
|
3674
|
-
|
|
3675
|
-
|
|
3851
|
+
constructor(identifierType) {
|
|
3852
|
+
const identifierDescriptor = IdentifierDescriptors[identifierType];
|
|
3853
|
+
super(identifierDescriptor);
|
|
3854
|
+
this._requiresCheckCharacterPair = identifierDescriptor.requiresCheckCharacterPair;
|
|
3676
3855
|
}
|
|
3677
3856
|
/**
|
|
3678
3857
|
* Determine if the identifier requires a check character pair.
|
|
@@ -3691,13 +3870,12 @@ var NonNumericIdentifierValidator = class _NonNumericIdentifierValidator extends
|
|
|
3691
3870
|
*/
|
|
3692
3871
|
validate(identifier, validation) {
|
|
3693
3872
|
const partialIdentifier = this.requiresCheckCharacterPair ? identifier.substring(0, identifier.length - 2) : identifier;
|
|
3694
|
-
super.validatePrefix(partialIdentifier
|
|
3873
|
+
super.validatePrefix(partialIdentifier);
|
|
3695
3874
|
if (!this.requiresCheckCharacterPair) {
|
|
3696
3875
|
this.referenceCreator.validate(identifier, {
|
|
3697
|
-
maximumLength: this.length
|
|
3698
|
-
positionOffset: validation?.positionOffset
|
|
3876
|
+
maximumLength: this.length
|
|
3699
3877
|
});
|
|
3700
|
-
} else if (!hasValidCheckCharacterPair(this.padIdentifier(identifier
|
|
3878
|
+
} else if (!hasValidCheckCharacterPair(this.padIdentifier(identifier))) {
|
|
3701
3879
|
throw new RangeError(i18nextGS1.t("Identifier.invalidCheckCharacterPair"));
|
|
3702
3880
|
}
|
|
3703
3881
|
if (validation?.exclusion === import_utility7.Exclusions.AllNumeric) {
|
|
@@ -3705,12 +3883,60 @@ var NonNumericIdentifierValidator = class _NonNumericIdentifierValidator extends
|
|
|
3705
3883
|
}
|
|
3706
3884
|
}
|
|
3707
3885
|
};
|
|
3708
|
-
var GIAI_VALIDATOR = new NonNumericIdentifierValidator(IdentifierTypes.GIAI, 30, ContentCharacterSets.AI82);
|
|
3709
|
-
var GINC_VALIDATOR = new NonNumericIdentifierValidator(IdentifierTypes.GINC, 30, ContentCharacterSets.AI82);
|
|
3710
|
-
var CPID_VALIDATOR = new NonNumericIdentifierValidator(IdentifierTypes.CPID, 30, ContentCharacterSets.AI39);
|
|
3711
|
-
var GMN_VALIDATOR = new NonNumericIdentifierValidator(IdentifierTypes.GMN, 25, ContentCharacterSets.AI82, true);
|
|
3712
3886
|
|
|
3713
|
-
// src/
|
|
3887
|
+
// src/validators.ts
|
|
3888
|
+
var GLN_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.GLN);
|
|
3889
|
+
var SSCC_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.SSCC);
|
|
3890
|
+
var GRAI_VALIDATOR = new SerializableNumericIdentifierValidator(IdentifierTypes.GRAI);
|
|
3891
|
+
var GIAI_VALIDATOR = new NonNumericIdentifierValidator(IdentifierTypes.GIAI);
|
|
3892
|
+
var GSRN_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.GSRN);
|
|
3893
|
+
var GDTI_VALIDATOR = new SerializableNumericIdentifierValidator(IdentifierTypes.GDTI);
|
|
3894
|
+
var GINC_VALIDATOR = new NonNumericIdentifierValidator(IdentifierTypes.GINC);
|
|
3895
|
+
var GSIN_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.GSIN);
|
|
3896
|
+
var GCN_VALIDATOR = new SerializableNumericIdentifierValidator(IdentifierTypes.GCN);
|
|
3897
|
+
var CPID_VALIDATOR = new NonNumericIdentifierValidator(IdentifierTypes.CPID);
|
|
3898
|
+
var GMN_VALIDATOR = new NonNumericIdentifierValidator(IdentifierTypes.GMN);
|
|
3899
|
+
var IdentifierValidators = {
|
|
3900
|
+
[IdentifierTypes.GTIN]: GTIN_VALIDATORS,
|
|
3901
|
+
[IdentifierTypes.GLN]: GLN_VALIDATOR,
|
|
3902
|
+
[IdentifierTypes.SSCC]: SSCC_VALIDATOR,
|
|
3903
|
+
[IdentifierTypes.GRAI]: GRAI_VALIDATOR,
|
|
3904
|
+
[IdentifierTypes.GIAI]: GIAI_VALIDATOR,
|
|
3905
|
+
[IdentifierTypes.GSRN]: GSRN_VALIDATOR,
|
|
3906
|
+
[IdentifierTypes.GDTI]: GDTI_VALIDATOR,
|
|
3907
|
+
[IdentifierTypes.GINC]: GINC_VALIDATOR,
|
|
3908
|
+
[IdentifierTypes.GSIN]: GSIN_VALIDATOR,
|
|
3909
|
+
[IdentifierTypes.GCN]: GCN_VALIDATOR,
|
|
3910
|
+
[IdentifierTypes.CPID]: CPID_VALIDATOR,
|
|
3911
|
+
[IdentifierTypes.GMN]: GMN_VALIDATOR
|
|
3912
|
+
};
|
|
3913
|
+
function isGTINValidators(identifierValidatorsOrValidator) {
|
|
3914
|
+
return isGTINDescriptors(identifierValidatorsOrValidator);
|
|
3915
|
+
}
|
|
3916
|
+
function isNumericIdentifierValidator(identifierValidator) {
|
|
3917
|
+
return isNumericIdentifierDescriptor(identifierValidator);
|
|
3918
|
+
}
|
|
3919
|
+
function isGTINValidator(identifierValidator) {
|
|
3920
|
+
return isGTINDescriptor(identifierValidator);
|
|
3921
|
+
}
|
|
3922
|
+
function isNonGTINNumericIdentifierValidator(identifierValidator) {
|
|
3923
|
+
return isNonGTINNumericIdentifierDescriptor(identifierValidator);
|
|
3924
|
+
}
|
|
3925
|
+
function isSerializableNumericIdentifierValidator(identifierValidator) {
|
|
3926
|
+
return isSerializableNumericIdentifierDescriptor(identifierValidator);
|
|
3927
|
+
}
|
|
3928
|
+
function isNonNumericIdentifierValidator(identifierValidator) {
|
|
3929
|
+
return isNonNumericIdentifierDescriptor(identifierValidator);
|
|
3930
|
+
}
|
|
3931
|
+
|
|
3932
|
+
// src/gtin-creator.ts
|
|
3933
|
+
var import_utility9 = require("@aidc-toolkit/utility");
|
|
3934
|
+
var import_ts_mixer = require("ts-mixer");
|
|
3935
|
+
|
|
3936
|
+
// src/abstract-numeric-identifier-creator.ts
|
|
3937
|
+
var import_utility8 = require("@aidc-toolkit/utility");
|
|
3938
|
+
|
|
3939
|
+
// src/abstract-identifier-creator.ts
|
|
3714
3940
|
var AbstractIdentifierCreator = class {
|
|
3715
3941
|
/**
|
|
3716
3942
|
* Prefix provider.
|
|
@@ -3721,13 +3947,13 @@ var AbstractIdentifierCreator = class {
|
|
|
3721
3947
|
*/
|
|
3722
3948
|
_referenceLength;
|
|
3723
3949
|
/**
|
|
3724
|
-
* Initialize the prefix
|
|
3950
|
+
* Initialize the prefix provider. This method is in lieu of a constructor due to the mixin architecture.
|
|
3725
3951
|
*
|
|
3726
3952
|
* @param prefixProvider
|
|
3727
3953
|
* Prefix provider.
|
|
3728
3954
|
*
|
|
3729
3955
|
* @param prefix
|
|
3730
|
-
* Prefix within prefix
|
|
3956
|
+
* Prefix within prefix provider to use to calculate reference length.
|
|
3731
3957
|
*
|
|
3732
3958
|
* @param checkAllowance
|
|
3733
3959
|
* Number of characters to allow for check digit or check character pair.
|
|
@@ -3756,8 +3982,7 @@ var AbstractIdentifierCreator = class {
|
|
|
3756
3982
|
}
|
|
3757
3983
|
};
|
|
3758
3984
|
|
|
3759
|
-
// src/numeric-identifier-creator.ts
|
|
3760
|
-
var import_utility8 = require("@aidc-toolkit/utility");
|
|
3985
|
+
// src/abstract-numeric-identifier-creator.ts
|
|
3761
3986
|
var AbstractNumericIdentifierCreator = class _AbstractNumericIdentifierCreator extends AbstractIdentifierCreator {
|
|
3762
3987
|
/**
|
|
3763
3988
|
* Capacity.
|
|
@@ -3787,13 +4012,13 @@ var AbstractNumericIdentifierCreator = class _AbstractNumericIdentifierCreator e
|
|
|
3787
4012
|
return this._capacity;
|
|
3788
4013
|
}
|
|
3789
4014
|
/**
|
|
3790
|
-
*
|
|
4015
|
+
* @inheritDoc
|
|
3791
4016
|
*/
|
|
3792
4017
|
get tweak() {
|
|
3793
4018
|
return this._tweak;
|
|
3794
4019
|
}
|
|
3795
4020
|
/**
|
|
3796
|
-
*
|
|
4021
|
+
* @inheritDoc
|
|
3797
4022
|
*/
|
|
3798
4023
|
set tweak(value) {
|
|
3799
4024
|
this._tweak = value;
|
|
@@ -3828,8 +4053,8 @@ var AbstractNumericIdentifierCreator = class _AbstractNumericIdentifierCreator e
|
|
|
3828
4053
|
* Remaining reference length. Initial value is `this.referenceLength`.
|
|
3829
4054
|
*
|
|
3830
4055
|
* @param extensionWeight
|
|
3831
|
-
* If this value is not zero, the identifier has an extension digit, this call is setting it, and this value
|
|
3832
|
-
*
|
|
4056
|
+
* If this value is not zero, the identifier has an extension digit, this call is setting it, and this value is
|
|
4057
|
+
* applied to the calculation of the check digit.
|
|
3833
4058
|
*
|
|
3834
4059
|
* @param weight
|
|
3835
4060
|
* If the extension weight is zero, this value is applied to the calculation of the check digit.
|
|
@@ -3878,8 +4103,6 @@ var AbstractNumericIdentifierCreator = class _AbstractNumericIdentifierCreator e
|
|
|
3878
4103
|
};
|
|
3879
4104
|
|
|
3880
4105
|
// src/gtin-creator.ts
|
|
3881
|
-
var import_utility9 = require("@aidc-toolkit/utility");
|
|
3882
|
-
var import_ts_mixer = require("ts-mixer");
|
|
3883
4106
|
var GTINCreator = class _GTINCreator extends (0, import_ts_mixer.Mixin)(GTINValidator, AbstractNumericIdentifierCreator) {
|
|
3884
4107
|
/**
|
|
3885
4108
|
* Validation parameters for required indicator digit.
|
|
@@ -3896,11 +4119,11 @@ var GTINCreator = class _GTINCreator extends (0, import_ts_mixer.Mixin)(GTINVali
|
|
|
3896
4119
|
* @param prefixProvider
|
|
3897
4120
|
* Prefix provider.
|
|
3898
4121
|
*
|
|
3899
|
-
* @param
|
|
3900
|
-
* GTIN type.
|
|
4122
|
+
* @param gtinBaseType
|
|
4123
|
+
* GTIN base type (all except GTIN-14).
|
|
3901
4124
|
*/
|
|
3902
|
-
constructor(prefixProvider,
|
|
3903
|
-
super(
|
|
4125
|
+
constructor(prefixProvider, gtinBaseType) {
|
|
4126
|
+
super(gtinBaseType);
|
|
3904
4127
|
this.init(prefixProvider, prefixProvider.prefix);
|
|
3905
4128
|
}
|
|
3906
4129
|
/**
|
|
@@ -4034,15 +4257,9 @@ var NonGTINNumericIdentifierCreator = class extends (0, import_ts_mixer2.Mixin)(
|
|
|
4034
4257
|
*
|
|
4035
4258
|
* @param identifierType
|
|
4036
4259
|
* Identifier type.
|
|
4037
|
-
*
|
|
4038
|
-
* @param length
|
|
4039
|
-
* Length.
|
|
4040
|
-
*
|
|
4041
|
-
* @param leaderType
|
|
4042
|
-
* Leader type.
|
|
4043
4260
|
*/
|
|
4044
|
-
constructor(prefixProvider, identifierType
|
|
4045
|
-
super(identifierType
|
|
4261
|
+
constructor(prefixProvider, identifierType) {
|
|
4262
|
+
super(identifierType);
|
|
4046
4263
|
this.init(prefixProvider, prefixProvider.gs1CompanyPrefix);
|
|
4047
4264
|
}
|
|
4048
4265
|
};
|
|
@@ -4060,18 +4277,9 @@ var SerializableNumericIdentifierCreator = class extends (0, import_ts_mixer3.Mi
|
|
|
4060
4277
|
*
|
|
4061
4278
|
* @param identifierType
|
|
4062
4279
|
* Identifier type.
|
|
4063
|
-
*
|
|
4064
|
-
* @param length
|
|
4065
|
-
* Length.
|
|
4066
|
-
*
|
|
4067
|
-
* @param serialComponentLength
|
|
4068
|
-
* Serial component length.
|
|
4069
|
-
*
|
|
4070
|
-
* @param serialComponentCharacterSet
|
|
4071
|
-
* Serial component character set.
|
|
4072
4280
|
*/
|
|
4073
|
-
constructor(prefixProvider, identifierType
|
|
4074
|
-
super(identifierType
|
|
4281
|
+
constructor(prefixProvider, identifierType) {
|
|
4282
|
+
super(identifierType);
|
|
4075
4283
|
this.init(prefixProvider, prefixProvider.gs1CompanyPrefix);
|
|
4076
4284
|
}
|
|
4077
4285
|
/**
|
|
@@ -4164,19 +4372,10 @@ var NonNumericIdentifierCreator = class extends (0, import_ts_mixer4.Mixin)(NonN
|
|
|
4164
4372
|
*
|
|
4165
4373
|
* @param identifierType
|
|
4166
4374
|
* Identifier type.
|
|
4167
|
-
*
|
|
4168
|
-
* @param length
|
|
4169
|
-
* Length.
|
|
4170
|
-
*
|
|
4171
|
-
* @param referenceCharacterSet
|
|
4172
|
-
* Reference character set.
|
|
4173
|
-
*
|
|
4174
|
-
* @param requiresCheckCharacterPair
|
|
4175
|
-
* True if the identifier requires a check character pair.
|
|
4176
4375
|
*/
|
|
4177
|
-
constructor(prefixProvider, identifierType
|
|
4178
|
-
super(identifierType
|
|
4179
|
-
this.init(prefixProvider, prefixProvider.gs1CompanyPrefix, 2 * Number(requiresCheckCharacterPair));
|
|
4376
|
+
constructor(prefixProvider, identifierType) {
|
|
4377
|
+
super(identifierType);
|
|
4378
|
+
this.init(prefixProvider, prefixProvider.gs1CompanyPrefix, 2 * Number(this.requiresCheckCharacterPair));
|
|
4180
4379
|
this._referenceValidation = {
|
|
4181
4380
|
minimumLength: 1,
|
|
4182
4381
|
// Maximum reference length has to account for prefix and check character pair.
|
|
@@ -4222,6 +4421,23 @@ var NonNumericIdentifierCreator = class extends (0, import_ts_mixer4.Mixin)(NonN
|
|
|
4222
4421
|
}
|
|
4223
4422
|
};
|
|
4224
4423
|
|
|
4424
|
+
// src/creators.ts
|
|
4425
|
+
function isNumericIdentifierCreator(identifierCreator) {
|
|
4426
|
+
return isNumericIdentifierDescriptor(identifierCreator);
|
|
4427
|
+
}
|
|
4428
|
+
function isGTINCreator(identifierCreator) {
|
|
4429
|
+
return isGTINDescriptor(identifierCreator);
|
|
4430
|
+
}
|
|
4431
|
+
function isNonGTINNumericIdentifierCreator(identifierCreator) {
|
|
4432
|
+
return isNonGTINNumericIdentifierDescriptor(identifierCreator);
|
|
4433
|
+
}
|
|
4434
|
+
function isSerializableNumericIdentifierCreator(identifierCreator) {
|
|
4435
|
+
return isSerializableNumericIdentifierDescriptor(identifierCreator);
|
|
4436
|
+
}
|
|
4437
|
+
function isNonNumericIdentifierCreator(identifierCreator) {
|
|
4438
|
+
return isNonNumericIdentifierDescriptor(identifierCreator);
|
|
4439
|
+
}
|
|
4440
|
+
|
|
4225
4441
|
// src/prefix-manager.ts
|
|
4226
4442
|
var PrefixManager = class _PrefixManager {
|
|
4227
4443
|
/**
|
|
@@ -4255,11 +4471,11 @@ var PrefixManager = class _PrefixManager {
|
|
|
4255
4471
|
*/
|
|
4256
4472
|
_gs1CompanyPrefix;
|
|
4257
4473
|
/**
|
|
4258
|
-
* U.P.C. Company Prefix if prefix type is {@
|
|
4474
|
+
* U.P.C. Company Prefix if prefix type is {@linkcode PrefixTypes.UPCCompanyPrefix}.
|
|
4259
4475
|
*/
|
|
4260
4476
|
_upcCompanyPrefix;
|
|
4261
4477
|
/**
|
|
4262
|
-
* GS1-8 Prefix if prefix type is {@
|
|
4478
|
+
* GS1-8 Prefix if prefix type is {@linkcode PrefixTypes.GS18Prefix}.
|
|
4263
4479
|
*/
|
|
4264
4480
|
_gs18Prefix;
|
|
4265
4481
|
/**
|
|
@@ -4277,23 +4493,19 @@ var PrefixManager = class _PrefixManager {
|
|
|
4277
4493
|
/**
|
|
4278
4494
|
* Constructor.
|
|
4279
4495
|
*
|
|
4280
|
-
* @param
|
|
4281
|
-
*
|
|
4496
|
+
* @param prefixType
|
|
4497
|
+
* Prefix type.
|
|
4498
|
+
*
|
|
4499
|
+
* @param prefix
|
|
4500
|
+
* Prefix.
|
|
4282
4501
|
*/
|
|
4283
|
-
constructor(
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
this._upcCompanyPrefix = gs1CompanyPrefix.substring(1);
|
|
4291
|
-
this._prefix = this._upcCompanyPrefix;
|
|
4292
|
-
} else {
|
|
4293
|
-
this._prefixType = PrefixTypes.GS18Prefix;
|
|
4294
|
-
this._gs18Prefix = gs1CompanyPrefix.substring(5);
|
|
4295
|
-
this._prefix = this._gs18Prefix;
|
|
4296
|
-
}
|
|
4502
|
+
constructor(prefixType, prefix) {
|
|
4503
|
+
const normalizedPrefixProvider = PrefixValidator.normalize(prefixType, prefix);
|
|
4504
|
+
this._prefixType = normalizedPrefixProvider.prefixType;
|
|
4505
|
+
this._prefix = normalizedPrefixProvider.prefix;
|
|
4506
|
+
this._gs1CompanyPrefix = normalizedPrefixProvider.gs1CompanyPrefix;
|
|
4507
|
+
this._upcCompanyPrefix = normalizedPrefixProvider.upcCompanyPrefix;
|
|
4508
|
+
this._gs18Prefix = normalizedPrefixProvider.gs18Prefix;
|
|
4297
4509
|
this._defaultTweakFactor = BigInt(`1${this.gs1CompanyPrefix}`);
|
|
4298
4510
|
this.resetTweakFactor();
|
|
4299
4511
|
}
|
|
@@ -4316,13 +4528,13 @@ var PrefixManager = class _PrefixManager {
|
|
|
4316
4528
|
return this._gs1CompanyPrefix;
|
|
4317
4529
|
}
|
|
4318
4530
|
/**
|
|
4319
|
-
* Get the U.P.C. Company Prefix if prefix type is {@
|
|
4531
|
+
* Get the U.P.C. Company Prefix if prefix type is {@linkcode PrefixTypes.UPCCompanyPrefix} or undefined if not.
|
|
4320
4532
|
*/
|
|
4321
4533
|
get upcCompanyPrefix() {
|
|
4322
4534
|
return this._upcCompanyPrefix;
|
|
4323
4535
|
}
|
|
4324
4536
|
/**
|
|
4325
|
-
* Get the GS1-8 Prefix if prefix type is {@
|
|
4537
|
+
* Get the GS1-8 Prefix if prefix type is {@linkcode PrefixTypes.GS18Prefix} or undefined if not.
|
|
4326
4538
|
*/
|
|
4327
4539
|
get gs18Prefix() {
|
|
4328
4540
|
return this._gs18Prefix;
|
|
@@ -4330,13 +4542,12 @@ var PrefixManager = class _PrefixManager {
|
|
|
4330
4542
|
/**
|
|
4331
4543
|
* Set the tweak for an identifier creator if it's a numeric identifier creator.
|
|
4332
4544
|
*
|
|
4333
|
-
* @param
|
|
4545
|
+
* @param identifierCreator
|
|
4334
4546
|
* Identifier creator.
|
|
4335
4547
|
*/
|
|
4336
|
-
setCreatorTweak(
|
|
4337
|
-
if (
|
|
4338
|
-
|
|
4339
|
-
creator.tweak = this.tweakFactor * creatorTweakFactor;
|
|
4548
|
+
setCreatorTweak(identifierCreator) {
|
|
4549
|
+
if (isNumericIdentifierCreator(identifierCreator)) {
|
|
4550
|
+
identifierCreator.tweak = this.tweakFactor * _PrefixManager.CREATOR_TWEAK_FACTORS[identifierCreator.identifierType];
|
|
4340
4551
|
}
|
|
4341
4552
|
}
|
|
4342
4553
|
/**
|
|
@@ -4379,42 +4590,33 @@ var PrefixManager = class _PrefixManager {
|
|
|
4379
4590
|
* Prefix manager with normalized prefix type and prefix.
|
|
4380
4591
|
*/
|
|
4381
4592
|
static get(prefixType, prefix) {
|
|
4382
|
-
PrefixValidator.
|
|
4383
|
-
let gs1CompanyPrefix;
|
|
4384
|
-
switch (prefixType) {
|
|
4385
|
-
case PrefixTypes.GS1CompanyPrefix:
|
|
4386
|
-
gs1CompanyPrefix = prefix;
|
|
4387
|
-
break;
|
|
4388
|
-
case PrefixTypes.UPCCompanyPrefix:
|
|
4389
|
-
gs1CompanyPrefix = "0" + prefix;
|
|
4390
|
-
break;
|
|
4391
|
-
case PrefixTypes.GS18Prefix:
|
|
4392
|
-
gs1CompanyPrefix = "00000" + prefix;
|
|
4393
|
-
break;
|
|
4394
|
-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- Method may be called by unsafe means.
|
|
4395
|
-
default:
|
|
4396
|
-
throw new RangeError(i18nextGS1.t("Prefix.invalidPrefixType"));
|
|
4397
|
-
}
|
|
4398
|
-
let prefixManager = _PrefixManager.PREFIX_MANAGERS_MAP.get(gs1CompanyPrefix);
|
|
4593
|
+
const normalizedPrefixProvider = PrefixValidator.normalize(prefixType, prefix);
|
|
4594
|
+
let prefixManager = _PrefixManager.PREFIX_MANAGERS_MAP.get(normalizedPrefixProvider.gs1CompanyPrefix);
|
|
4399
4595
|
if (prefixManager === void 0) {
|
|
4400
|
-
prefixManager = new _PrefixManager(
|
|
4401
|
-
_PrefixManager.PREFIX_MANAGERS_MAP.set(gs1CompanyPrefix, prefixManager);
|
|
4596
|
+
prefixManager = new _PrefixManager(normalizedPrefixProvider.prefixType, normalizedPrefixProvider.prefix);
|
|
4597
|
+
_PrefixManager.PREFIX_MANAGERS_MAP.set(normalizedPrefixProvider.gs1CompanyPrefix, prefixManager);
|
|
4402
4598
|
}
|
|
4403
4599
|
return prefixManager;
|
|
4404
4600
|
}
|
|
4405
4601
|
/**
|
|
4406
4602
|
* Get an identifier creator.
|
|
4407
4603
|
*
|
|
4604
|
+
* @template TIdentifierType
|
|
4605
|
+
* Identifier type type.
|
|
4606
|
+
*
|
|
4408
4607
|
* @param identifierType
|
|
4409
|
-
* Identifier type.
|
|
4608
|
+
* Identifier type used to construct identifier creator.
|
|
4609
|
+
*
|
|
4610
|
+
* @param constructorParameter
|
|
4611
|
+
* Second constructor parameter passed to constructor callback alongside this.
|
|
4410
4612
|
*
|
|
4411
|
-
* @param
|
|
4613
|
+
* @param ConstructorCallback
|
|
4412
4614
|
* Constructor callback.
|
|
4413
4615
|
*
|
|
4414
4616
|
* @returns
|
|
4415
4617
|
* Identifier creator.
|
|
4416
4618
|
*/
|
|
4417
|
-
getIdentifierCreator(identifierType,
|
|
4619
|
+
getIdentifierCreator(identifierType, constructorParameter, ConstructorCallback) {
|
|
4418
4620
|
let creator = this._identifierCreators[identifierType];
|
|
4419
4621
|
if (creator === void 0) {
|
|
4420
4622
|
if (this.prefixType === PrefixTypes.GS18Prefix && identifierType !== IdentifierTypes.GTIN) {
|
|
@@ -4422,7 +4624,7 @@ var PrefixManager = class _PrefixManager {
|
|
|
4422
4624
|
identifierType
|
|
4423
4625
|
}));
|
|
4424
4626
|
}
|
|
4425
|
-
creator =
|
|
4627
|
+
creator = new ConstructorCallback(this, constructorParameter);
|
|
4426
4628
|
this.setCreatorTweak(creator);
|
|
4427
4629
|
this._identifierCreators[identifierType] = creator;
|
|
4428
4630
|
}
|
|
@@ -4431,124 +4633,110 @@ var PrefixManager = class _PrefixManager {
|
|
|
4431
4633
|
/**
|
|
4432
4634
|
* Get non-GTIN numeric identifier creator.
|
|
4433
4635
|
*
|
|
4434
|
-
* @param
|
|
4435
|
-
*
|
|
4636
|
+
* @param identifierType
|
|
4637
|
+
* Identifier type used to construct identifier creator.
|
|
4436
4638
|
*
|
|
4437
4639
|
* @returns
|
|
4438
4640
|
* Identifier creator.
|
|
4439
4641
|
*/
|
|
4440
|
-
getNonGTINNumericIdentifierCreator(
|
|
4441
|
-
return this.getIdentifierCreator(
|
|
4642
|
+
getNonGTINNumericIdentifierCreator(identifierType) {
|
|
4643
|
+
return this.getIdentifierCreator(identifierType, identifierType, NonGTINNumericIdentifierCreator);
|
|
4442
4644
|
}
|
|
4443
4645
|
/**
|
|
4444
4646
|
* Get serialized numeric identifier creator.
|
|
4445
4647
|
*
|
|
4446
|
-
* @param
|
|
4447
|
-
*
|
|
4648
|
+
* @param identifierType
|
|
4649
|
+
* Identifier type used to construct identifier creator.
|
|
4448
4650
|
*
|
|
4449
4651
|
* @returns
|
|
4450
4652
|
* Identifier creator.
|
|
4451
4653
|
*/
|
|
4452
|
-
getSerializableNumericIdentifierCreator(
|
|
4453
|
-
return this.getIdentifierCreator(
|
|
4654
|
+
getSerializableNumericIdentifierCreator(identifierType) {
|
|
4655
|
+
return this.getIdentifierCreator(identifierType, identifierType, SerializableNumericIdentifierCreator);
|
|
4454
4656
|
}
|
|
4455
4657
|
/**
|
|
4456
4658
|
* Get non-numeric identifier creator.
|
|
4457
4659
|
*
|
|
4458
|
-
* @param
|
|
4459
|
-
*
|
|
4660
|
+
* @param identifierType
|
|
4661
|
+
* Identifier type used to construct identifier creator.
|
|
4460
4662
|
*
|
|
4461
4663
|
* @returns
|
|
4462
4664
|
* Identifier creator.
|
|
4463
4665
|
*/
|
|
4464
|
-
getNonNumericIdentifierCreator(
|
|
4465
|
-
return this.getIdentifierCreator(
|
|
4666
|
+
getNonNumericIdentifierCreator(identifierType) {
|
|
4667
|
+
return this.getIdentifierCreator(identifierType, identifierType, NonNumericIdentifierCreator);
|
|
4466
4668
|
}
|
|
4467
4669
|
/**
|
|
4468
4670
|
* Get GTIN creator.
|
|
4469
4671
|
*/
|
|
4470
4672
|
get gtinCreator() {
|
|
4471
|
-
return this.getIdentifierCreator(IdentifierTypes.GTIN,
|
|
4472
|
-
let gtinType;
|
|
4473
|
-
switch (this.prefixType) {
|
|
4474
|
-
case PrefixTypes.GS1CompanyPrefix:
|
|
4475
|
-
gtinType = GTINTypes.GTIN13;
|
|
4476
|
-
break;
|
|
4477
|
-
case PrefixTypes.UPCCompanyPrefix:
|
|
4478
|
-
gtinType = GTINTypes.GTIN12;
|
|
4479
|
-
break;
|
|
4480
|
-
case PrefixTypes.GS18Prefix:
|
|
4481
|
-
gtinType = GTINTypes.GTIN8;
|
|
4482
|
-
break;
|
|
4483
|
-
}
|
|
4484
|
-
return new GTINCreator(this, gtinType);
|
|
4485
|
-
});
|
|
4673
|
+
return this.getIdentifierCreator(IdentifierTypes.GTIN, GTIN_BASE_TYPES[this.prefixType], GTINCreator);
|
|
4486
4674
|
}
|
|
4487
4675
|
/**
|
|
4488
4676
|
* Get GLN creator.
|
|
4489
4677
|
*/
|
|
4490
4678
|
get glnCreator() {
|
|
4491
|
-
return this.getNonGTINNumericIdentifierCreator(
|
|
4679
|
+
return this.getNonGTINNumericIdentifierCreator(IdentifierTypes.GLN);
|
|
4492
4680
|
}
|
|
4493
4681
|
/**
|
|
4494
4682
|
* Get SSCC creator.
|
|
4495
4683
|
*/
|
|
4496
4684
|
get ssccCreator() {
|
|
4497
|
-
return this.getNonGTINNumericIdentifierCreator(
|
|
4685
|
+
return this.getNonGTINNumericIdentifierCreator(IdentifierTypes.SSCC);
|
|
4498
4686
|
}
|
|
4499
4687
|
/**
|
|
4500
4688
|
* Get GRAI creator.
|
|
4501
4689
|
*/
|
|
4502
4690
|
get graiCreator() {
|
|
4503
|
-
return this.getSerializableNumericIdentifierCreator(
|
|
4691
|
+
return this.getSerializableNumericIdentifierCreator(IdentifierTypes.GRAI);
|
|
4504
4692
|
}
|
|
4505
4693
|
/**
|
|
4506
4694
|
* Get GIAI creator.
|
|
4507
4695
|
*/
|
|
4508
4696
|
get giaiCreator() {
|
|
4509
|
-
return this.getNonNumericIdentifierCreator(
|
|
4697
|
+
return this.getNonNumericIdentifierCreator(IdentifierTypes.GIAI);
|
|
4510
4698
|
}
|
|
4511
4699
|
/**
|
|
4512
4700
|
* Get GSRN creator.
|
|
4513
4701
|
*/
|
|
4514
4702
|
get gsrnCreator() {
|
|
4515
|
-
return this.getNonGTINNumericIdentifierCreator(
|
|
4703
|
+
return this.getNonGTINNumericIdentifierCreator(IdentifierTypes.GSRN);
|
|
4516
4704
|
}
|
|
4517
4705
|
/**
|
|
4518
4706
|
* Get GDTI creator.
|
|
4519
4707
|
*/
|
|
4520
4708
|
get gdtiCreator() {
|
|
4521
|
-
return this.getSerializableNumericIdentifierCreator(
|
|
4709
|
+
return this.getSerializableNumericIdentifierCreator(IdentifierTypes.GDTI);
|
|
4522
4710
|
}
|
|
4523
4711
|
/**
|
|
4524
4712
|
* Get GINC creator.
|
|
4525
4713
|
*/
|
|
4526
4714
|
get gincCreator() {
|
|
4527
|
-
return this.getNonNumericIdentifierCreator(
|
|
4715
|
+
return this.getNonNumericIdentifierCreator(IdentifierTypes.GINC);
|
|
4528
4716
|
}
|
|
4529
4717
|
/**
|
|
4530
4718
|
* Get GSIN creator.
|
|
4531
4719
|
*/
|
|
4532
4720
|
get gsinCreator() {
|
|
4533
|
-
return this.getNonGTINNumericIdentifierCreator(
|
|
4721
|
+
return this.getNonGTINNumericIdentifierCreator(IdentifierTypes.GSIN);
|
|
4534
4722
|
}
|
|
4535
4723
|
/**
|
|
4536
4724
|
* Get GCN creator.
|
|
4537
4725
|
*/
|
|
4538
4726
|
get gcnCreator() {
|
|
4539
|
-
return this.getSerializableNumericIdentifierCreator(
|
|
4727
|
+
return this.getSerializableNumericIdentifierCreator(IdentifierTypes.GCN);
|
|
4540
4728
|
}
|
|
4541
4729
|
/**
|
|
4542
4730
|
* Get CPID creator.
|
|
4543
4731
|
*/
|
|
4544
4732
|
get cpidCreator() {
|
|
4545
|
-
return this.getNonNumericIdentifierCreator(
|
|
4733
|
+
return this.getNonNumericIdentifierCreator(IdentifierTypes.CPID);
|
|
4546
4734
|
}
|
|
4547
4735
|
/**
|
|
4548
4736
|
* Get GMN creator.
|
|
4549
4737
|
*/
|
|
4550
4738
|
get gmnCreator() {
|
|
4551
|
-
return this.getNonNumericIdentifierCreator(
|
|
4739
|
+
return this.getNonNumericIdentifierCreator(IdentifierTypes.GMN);
|
|
4552
4740
|
}
|
|
4553
4741
|
};
|
|
4554
4742
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -4558,30 +4746,15 @@ var PrefixManager = class _PrefixManager {
|
|
|
4558
4746
|
AI64_VALIDATOR,
|
|
4559
4747
|
AI82_CREATOR,
|
|
4560
4748
|
AI82_VALIDATOR,
|
|
4561
|
-
AbstractIdentifierCreator,
|
|
4562
|
-
AbstractIdentifierValidator,
|
|
4563
|
-
AbstractNumericIdentifierCreator,
|
|
4564
|
-
AbstractNumericIdentifierValidator,
|
|
4565
|
-
CPID_VALIDATOR,
|
|
4566
4749
|
ContentCharacterSets,
|
|
4567
|
-
GCN_VALIDATOR,
|
|
4568
|
-
GDTI_VALIDATOR,
|
|
4569
|
-
GIAI_VALIDATOR,
|
|
4570
|
-
GINC_VALIDATOR,
|
|
4571
|
-
GLN_VALIDATOR,
|
|
4572
|
-
GMN_VALIDATOR,
|
|
4573
|
-
GRAI_VALIDATOR,
|
|
4574
|
-
GSIN_VALIDATOR,
|
|
4575
|
-
GSRN_VALIDATOR,
|
|
4576
|
-
GTIN12_VALIDATOR,
|
|
4577
|
-
GTIN13_VALIDATOR,
|
|
4578
|
-
GTIN8_VALIDATOR,
|
|
4579
4750
|
GTINCreator,
|
|
4580
4751
|
GTINLevels,
|
|
4581
4752
|
GTINTypes,
|
|
4582
4753
|
GTINValidator,
|
|
4583
|
-
|
|
4754
|
+
GTIN_BASE_TYPES,
|
|
4755
|
+
IdentifierDescriptors,
|
|
4584
4756
|
IdentifierTypes,
|
|
4757
|
+
IdentifierValidators,
|
|
4585
4758
|
LeaderTypes,
|
|
4586
4759
|
NonGTINNumericIdentifierCreator,
|
|
4587
4760
|
NonGTINNumericIdentifierValidator,
|
|
@@ -4590,7 +4763,6 @@ var PrefixManager = class _PrefixManager {
|
|
|
4590
4763
|
PrefixManager,
|
|
4591
4764
|
PrefixTypes,
|
|
4592
4765
|
PrefixValidator,
|
|
4593
|
-
SSCC_VALIDATOR,
|
|
4594
4766
|
SerializableNumericIdentifierCreator,
|
|
4595
4767
|
SerializableNumericIdentifierValidator,
|
|
4596
4768
|
checkCharacterPair,
|
|
@@ -4602,6 +4774,23 @@ var PrefixManager = class _PrefixManager {
|
|
|
4602
4774
|
hasValidCheckDigit,
|
|
4603
4775
|
i18nGS1Init,
|
|
4604
4776
|
i18nextGS1,
|
|
4777
|
+
isGTINCreator,
|
|
4778
|
+
isGTINDescriptor,
|
|
4779
|
+
isGTINDescriptors,
|
|
4780
|
+
isGTINValidator,
|
|
4781
|
+
isGTINValidators,
|
|
4782
|
+
isNonGTINNumericIdentifierCreator,
|
|
4783
|
+
isNonGTINNumericIdentifierDescriptor,
|
|
4784
|
+
isNonGTINNumericIdentifierValidator,
|
|
4785
|
+
isNonNumericIdentifierCreator,
|
|
4786
|
+
isNonNumericIdentifierDescriptor,
|
|
4787
|
+
isNonNumericIdentifierValidator,
|
|
4788
|
+
isNumericIdentifierCreator,
|
|
4789
|
+
isNumericIdentifierDescriptor,
|
|
4790
|
+
isNumericIdentifierValidator,
|
|
4791
|
+
isSerializableNumericIdentifierCreator,
|
|
4792
|
+
isSerializableNumericIdentifierDescriptor,
|
|
4793
|
+
isSerializableNumericIdentifierValidator,
|
|
4605
4794
|
isValidPriceOrWeightCheckDigit,
|
|
4606
4795
|
priceOrWeightCheckDigit
|
|
4607
4796
|
});
|