@aidc-toolkit/gs1 1.0.25-beta → 1.0.27-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/abstract-identifier-creator.d.ts +75 -0
- package/dist/abstract-identifier-creator.d.ts.map +1 -0
- package/dist/abstract-identifier-creator.js +79 -0
- package/dist/abstract-identifier-creator.js.map +1 -0
- package/dist/abstract-non-gtin-numeric-identifier-creator.d.ts +42 -0
- package/dist/abstract-non-gtin-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/abstract-non-gtin-numeric-identifier-creator.js +40 -0
- package/dist/abstract-non-gtin-numeric-identifier-creator.js.map +1 -0
- package/dist/abstract-numeric-identifier-creator.d.ts +43 -0
- package/dist/abstract-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/abstract-numeric-identifier-creator.js +160 -0
- package/dist/abstract-numeric-identifier-creator.js.map +1 -0
- package/dist/character-set.d.ts +27 -0
- package/dist/character-set.d.ts.map +1 -0
- package/dist/character-set.js +50 -0
- package/dist/character-set.js.map +1 -0
- package/dist/check.d.ts +81 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +218 -0
- package/dist/check.js.map +1 -0
- package/dist/content-character-set-creators.d.ts +4 -0
- package/dist/content-character-set-creators.d.ts.map +1 -0
- package/dist/content-character-set-creators.js +9 -0
- package/dist/content-character-set-creators.js.map +1 -0
- package/dist/content-character-set.d.ts +26 -0
- package/dist/content-character-set.d.ts.map +1 -0
- package/dist/content-character-set.js +18 -0
- package/dist/content-character-set.js.map +1 -0
- package/dist/gtin-creator.d.ts +64 -0
- package/dist/gtin-creator.d.ts.map +1 -0
- package/dist/gtin-creator.js +156 -0
- package/dist/gtin-creator.js.map +1 -0
- package/dist/gtin-descriptor.d.ts +22 -0
- package/dist/gtin-descriptor.d.ts.map +1 -0
- package/dist/gtin-descriptor.js +2 -0
- package/dist/gtin-descriptor.js.map +1 -0
- package/dist/gtin-length.d.ts +64 -0
- package/dist/gtin-length.d.ts.map +1 -0
- package/dist/gtin-length.js +36 -0
- package/dist/gtin-length.js.map +1 -0
- package/dist/gtin-type.d.ts +26 -0
- package/dist/gtin-type.d.ts.map +1 -0
- package/dist/gtin-type.js +7 -0
- package/dist/gtin-type.js.map +1 -0
- package/dist/gtin-validator.d.ts +177 -0
- package/dist/gtin-validator.d.ts.map +1 -0
- package/dist/gtin-validator.js +443 -0
- package/dist/gtin-validator.js.map +1 -0
- package/dist/identifier-creator.d.ts +31 -0
- package/dist/identifier-creator.d.ts.map +1 -0
- package/dist/identifier-creator.js +2 -0
- package/dist/identifier-creator.js.map +1 -0
- package/dist/identifier-creators.d.ts +90 -0
- package/dist/identifier-creators.d.ts.map +1 -0
- package/dist/identifier-creators.js +74 -0
- package/dist/identifier-creators.js.map +1 -0
- package/dist/identifier-descriptor.d.ts +27 -0
- package/dist/identifier-descriptor.d.ts.map +1 -0
- package/dist/identifier-descriptor.js +2 -0
- package/dist/identifier-descriptor.js.map +1 -0
- package/dist/identifier-descriptors.d.ts +106 -0
- package/dist/identifier-descriptors.d.ts.map +1 -0
- package/dist/identifier-descriptors.js +262 -0
- package/dist/identifier-descriptors.js.map +1 -0
- package/dist/identifier-extension.d.ts +82 -0
- package/dist/identifier-extension.d.ts.map +1 -0
- package/dist/identifier-extension.js +79 -0
- package/dist/identifier-extension.js.map +1 -0
- package/dist/identifier-type.d.ts +62 -0
- package/dist/identifier-type.d.ts.map +1 -0
- package/dist/identifier-type.js +54 -0
- package/dist/identifier-type.js.map +1 -0
- package/dist/identifier-validator.d.ts +88 -0
- package/dist/identifier-validator.d.ts.map +1 -0
- package/dist/identifier-validator.js +110 -0
- package/dist/identifier-validator.js.map +1 -0
- package/dist/identifier-validators.d.ts +106 -0
- package/dist/identifier-validators.d.ts.map +1 -0
- package/dist/identifier-validators.js +153 -0
- package/dist/identifier-validators.js.map +1 -0
- package/dist/index.d.ts +58 -1949
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -4727
- package/dist/index.js.map +1 -1
- package/dist/leader-type.d.ts +26 -0
- package/dist/leader-type.d.ts.map +1 -0
- package/dist/leader-type.js +18 -0
- package/dist/leader-type.js.map +1 -0
- package/dist/locale/en/locale-resources.d.ts +42 -0
- package/dist/locale/en/locale-resources.d.ts.map +1 -0
- package/dist/locale/en/locale-resources.js +41 -0
- package/dist/locale/en/locale-resources.js.map +1 -0
- package/dist/locale/fr/locale-resources.d.ts +42 -0
- package/dist/locale/fr/locale-resources.d.ts.map +1 -0
- package/dist/locale/fr/locale-resources.js +41 -0
- package/dist/locale/fr/locale-resources.js.map +1 -0
- package/dist/locale/i18n.d.ts +27 -0
- package/dist/locale/i18n.d.ts.map +1 -0
- package/dist/locale/i18n.js +36 -0
- package/dist/locale/i18n.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-creator.d.ts +12 -0
- package/dist/non-gtin-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-creator.js +2 -0
- package/dist/non-gtin-numeric-identifier-creator.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-descriptor.d.ts +22 -0
- package/dist/non-gtin-numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-descriptor.js +2 -0
- package/dist/non-gtin-numeric-identifier-descriptor.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-type.d.ts +26 -0
- package/dist/non-gtin-numeric-identifier-type.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-type.js +8 -0
- package/dist/non-gtin-numeric-identifier-type.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-validator.d.ts +12 -0
- package/dist/non-gtin-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-validator.js +10 -0
- package/dist/non-gtin-numeric-identifier-validator.js.map +1 -0
- package/dist/non-numeric-identifier-creator.d.ts +40 -0
- package/dist/non-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/non-numeric-identifier-creator.js +82 -0
- package/dist/non-numeric-identifier-creator.js.map +1 -0
- package/dist/non-numeric-identifier-descriptor.d.ts +26 -0
- package/dist/non-numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/non-numeric-identifier-descriptor.js +2 -0
- package/dist/non-numeric-identifier-descriptor.js.map +1 -0
- package/dist/non-numeric-identifier-type.d.ts +26 -0
- package/dist/non-numeric-identifier-type.d.ts.map +1 -0
- package/dist/non-numeric-identifier-type.js +8 -0
- package/dist/non-numeric-identifier-type.js.map +1 -0
- package/dist/non-numeric-identifier-validator.d.ts +41 -0
- package/dist/non-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/non-numeric-identifier-validator.js +69 -0
- package/dist/non-numeric-identifier-validator.js.map +1 -0
- package/dist/non-serializable-numeric-identifier-creator.d.ts +10 -0
- package/dist/non-serializable-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/non-serializable-numeric-identifier-creator.js +8 -0
- package/dist/non-serializable-numeric-identifier-creator.js.map +1 -0
- package/dist/non-serializable-numeric-identifier-descriptor.d.ts +7 -0
- package/dist/non-serializable-numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/non-serializable-numeric-identifier-descriptor.js +2 -0
- package/dist/non-serializable-numeric-identifier-descriptor.js.map +1 -0
- package/dist/non-serializable-numeric-identifier-type.d.ts +26 -0
- package/dist/non-serializable-numeric-identifier-type.d.ts.map +1 -0
- package/dist/non-serializable-numeric-identifier-type.js +7 -0
- package/dist/non-serializable-numeric-identifier-type.js.map +1 -0
- package/dist/non-serializable-numeric-identifier-validator.d.ts +16 -0
- package/dist/non-serializable-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/non-serializable-numeric-identifier-validator.js +17 -0
- package/dist/non-serializable-numeric-identifier-validator.js.map +1 -0
- package/dist/numeric-identifier-creator.d.ts +53 -0
- package/dist/numeric-identifier-creator.d.ts.map +1 -0
- package/dist/numeric-identifier-creator.js +2 -0
- package/dist/numeric-identifier-creator.js.map +1 -0
- package/dist/numeric-identifier-descriptor.d.ts +22 -0
- package/dist/numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/numeric-identifier-descriptor.js +2 -0
- package/dist/numeric-identifier-descriptor.js.map +1 -0
- package/dist/numeric-identifier-type.d.ts +26 -0
- package/dist/numeric-identifier-type.d.ts.map +1 -0
- package/dist/numeric-identifier-type.js +7 -0
- package/dist/numeric-identifier-type.js.map +1 -0
- package/dist/numeric-identifier-validator.d.ts +38 -0
- package/dist/numeric-identifier-validator.d.ts.map +1 -0
- package/dist/numeric-identifier-validator.js +61 -0
- package/dist/numeric-identifier-validator.js.map +1 -0
- package/dist/prefix-manager.d.ts +136 -0
- package/dist/prefix-manager.d.ts.map +1 -0
- package/dist/prefix-manager.js +339 -0
- package/dist/prefix-manager.js.map +1 -0
- package/dist/prefix-provider.d.ts +27 -0
- package/dist/prefix-provider.d.ts.map +1 -0
- package/dist/prefix-provider.js +2 -0
- package/dist/prefix-provider.js.map +1 -0
- package/dist/prefix-type.d.ts +26 -0
- package/dist/prefix-type.d.ts.map +1 -0
- package/dist/prefix-type.js +18 -0
- package/dist/prefix-type.js.map +1 -0
- package/dist/prefix-validator.d.ts +70 -0
- package/dist/prefix-validator.d.ts.map +1 -0
- package/dist/prefix-validator.js +208 -0
- package/dist/prefix-validator.js.map +1 -0
- package/dist/serializable-numeric-identifier-creator.d.ts +48 -0
- package/dist/serializable-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-creator.js +93 -0
- package/dist/serializable-numeric-identifier-creator.js.map +1 -0
- package/dist/serializable-numeric-identifier-descriptor.d.ts +26 -0
- package/dist/serializable-numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-descriptor.js +2 -0
- package/dist/serializable-numeric-identifier-descriptor.js.map +1 -0
- package/dist/serializable-numeric-identifier-type.d.ts +26 -0
- package/dist/serializable-numeric-identifier-type.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-type.js +8 -0
- package/dist/serializable-numeric-identifier-type.js.map +1 -0
- package/dist/serializable-numeric-identifier-validator.d.ts +41 -0
- package/dist/serializable-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-validator.js +78 -0
- package/dist/serializable-numeric-identifier-validator.js.map +1 -0
- package/package.json +11 -8
- package/src/abstract-identifier-creator.ts +157 -76
- package/src/abstract-non-gtin-numeric-identifier-creator.ts +86 -0
- package/src/abstract-numeric-identifier-creator.ts +205 -136
- package/src/check.ts +2 -2
- package/src/content-character-set-creators.ts +9 -0
- package/src/gtin-creator.ts +20 -19
- package/src/gtin-descriptor.ts +10 -4
- package/src/gtin-length.ts +61 -0
- package/src/gtin-type.ts +6 -37
- package/src/gtin-validator.ts +39 -46
- package/src/identifier-creator.ts +6 -6
- package/src/{creators.ts → identifier-creators.ts} +45 -31
- package/src/identifier-descriptor.ts +3 -3
- package/src/{descriptors.ts → identifier-descriptors.ts} +65 -63
- package/src/identifier-extension.ts +155 -0
- package/src/identifier-validator.ts +94 -11
- package/src/{validators.ts → identifier-validators.ts} +56 -41
- package/src/index.ts +50 -43
- package/src/leader-type.ts +29 -0
- package/src/locale/i18n.ts +3 -3
- package/src/locale/i18next.d.ts +1 -1
- package/src/non-gtin-numeric-identifier-creator.ts +8 -23
- package/src/non-gtin-numeric-identifier-descriptor.ts +4 -4
- package/src/non-gtin-numeric-identifier-type.ts +14 -3
- package/src/non-gtin-numeric-identifier-validator.ts +7 -15
- package/src/non-numeric-identifier-creator.ts +21 -16
- package/src/non-numeric-identifier-descriptor.ts +4 -4
- package/src/non-numeric-identifier-type.ts +14 -3
- package/src/non-numeric-identifier-validator.ts +12 -13
- package/src/non-serializable-numeric-identifier-creator.ts +12 -0
- package/src/non-serializable-numeric-identifier-descriptor.ts +7 -0
- package/src/non-serializable-numeric-identifier-type.ts +22 -0
- package/src/non-serializable-numeric-identifier-validator.ts +19 -0
- package/src/numeric-identifier-creator.ts +9 -8
- package/src/numeric-identifier-descriptor.ts +4 -3
- package/src/numeric-identifier-type.ts +17 -35
- package/src/numeric-identifier-validator.ts +62 -7
- package/src/prefix-manager.ts +79 -76
- package/src/prefix-provider.ts +1 -1
- package/src/prefix-validator.ts +3 -3
- package/src/serializable-numeric-identifier-creator.ts +13 -27
- package/src/serializable-numeric-identifier-descriptor.ts +4 -4
- package/src/serializable-numeric-identifier-type.ts +14 -5
- package/src/serializable-numeric-identifier-validator.ts +22 -21
- package/test/check.test.ts +1 -1
- package/test/creator.test.ts +5 -5
- package/test/gtin-creator.ts +10 -3
- package/test/gtin-validator.test.ts +10 -12
- package/test/identifier-creator.ts +12 -12
- package/test/identifier-validator.ts +1 -1
- package/test/non-gtin-numeric-identifier-creator.ts +3 -3
- package/test/non-gtin-numeric-identifier-validator.ts +8 -3
- package/test/non-numeric-identifier-creator.ts +1 -1
- package/test/non-numeric-identifier-validator.ts +3 -3
- package/test/non-serializable-numeric-identifier-creator.ts +64 -0
- package/test/non-serializable-numeric-identifier-validator.ts +6 -0
- package/test/numeric-identifier-creator.ts +9 -4
- package/test/numeric-identifier-validator.ts +2 -2
- package/test/prefix-manager.test.ts +2 -2
- package/test/serializable-numeric-identifier-creator.ts +2 -2
- package/test/serializable-numeric-identifier-validator.ts +3 -3
- package/test/setup.ts +1 -1
- package/test/sparse.test.ts +1 -1
- package/test/utility.ts +1 -1
- package/test/validator.test.ts +16 -15
- package/test/variable-measure-rcn.test.ts +24 -24
- package/tsconfig-config.json +4 -0
- package/tsconfig-src.json +8 -0
- package/tsconfig-test.json +9 -0
- package/tsconfig.json +12 -1
- package/tsup.config.ts +3 -2
- package/dist/index.cjs +0 -4813
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -1949
- package/src/abstract-identifier-validator.ts +0 -140
- package/src/abstract-numeric-identifier-validator.ts +0 -69
package/dist/check.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { NUMERIC_CREATOR, utilityNS } from "@aidc-toolkit/utility";
|
|
2
|
+
import { AI82_CREATOR } from "./character-set.js";
|
|
3
|
+
import { i18nextGS1 } from "./locale/i18n.js";
|
|
4
|
+
/**
|
|
5
|
+
* Results of multiplying digits by 3.
|
|
6
|
+
*/
|
|
7
|
+
const THREE_WEIGHT_RESULTS = [
|
|
8
|
+
0, 3, 6, 9, 12, 15, 18, 21, 24, 27
|
|
9
|
+
];
|
|
10
|
+
/**
|
|
11
|
+
* Results of multiplying digits by 2, subtracting tens digit, and extracting units digit.
|
|
12
|
+
*/
|
|
13
|
+
const TWO_MINUS_WEIGHT_RESULTS = [
|
|
14
|
+
0, 2, 4, 6, 8, 9, 1, 3, 5, 7
|
|
15
|
+
];
|
|
16
|
+
/**
|
|
17
|
+
* Results of multiplying digits by 5, adding tens digit, and extracting units digit.
|
|
18
|
+
*/
|
|
19
|
+
const FIVE_PLUS_WEIGHT_RESULTS = [
|
|
20
|
+
0, 5, 1, 6, 2, 7, 3, 8, 4, 9
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* Results of multiplying digits by 5, subtracting tens digit, and extracting units digit.
|
|
24
|
+
*/
|
|
25
|
+
const FIVE_MINUS_WEIGHT_RESULTS = [
|
|
26
|
+
0, 5, 9, 4, 8, 3, 7, 2, 6, 1
|
|
27
|
+
];
|
|
28
|
+
/**
|
|
29
|
+
* Inverse mapping of FIVE_MINUS_WEIGHT_RESULTS.
|
|
30
|
+
*/
|
|
31
|
+
const INVERSE_FIVE_MINUS_WEIGHT_RESULTS = [
|
|
32
|
+
0, 9, 7, 5, 3, 1, 8, 6, 4, 2
|
|
33
|
+
];
|
|
34
|
+
/**
|
|
35
|
+
* Calculate the check digit sum for a numeric string as per section 7.9.1 of the {@link
|
|
36
|
+
* https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}.
|
|
37
|
+
*
|
|
38
|
+
* @param exchangeWeights
|
|
39
|
+
* If true, start the weights at 1 instead of 3 on the right.
|
|
40
|
+
*
|
|
41
|
+
* @param s
|
|
42
|
+
* Numeric string.
|
|
43
|
+
*
|
|
44
|
+
* @returns
|
|
45
|
+
* Accumulated sum of each digit multiplied by the weight at its position.
|
|
46
|
+
*/
|
|
47
|
+
export function checkDigitSum(exchangeWeights, s) {
|
|
48
|
+
// Initial setting will be the opposite of that used for first character because it gets flipped before being used.
|
|
49
|
+
let weight3 = (s.length + Number(exchangeWeights)) % 2 === 0;
|
|
50
|
+
// Calculate sum of each character value multiplied by the weight at its position.
|
|
51
|
+
return NUMERIC_CREATOR.characterIndexes(s).reduce((accumulator, characterIndex, index) => {
|
|
52
|
+
if (characterIndex === undefined) {
|
|
53
|
+
throw new RangeError(i18nextGS1.t("CharacterSetValidator.invalidCharacterAtPosition", {
|
|
54
|
+
ns: utilityNS,
|
|
55
|
+
c: s.charAt(index),
|
|
56
|
+
position: index + 1
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
weight3 = !weight3;
|
|
60
|
+
return accumulator + (weight3 ? THREE_WEIGHT_RESULTS[characterIndex] : characterIndex);
|
|
61
|
+
}, 0);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Calculate the check digit for a numeric string as per section 7.9.1 of the {@link
|
|
65
|
+
* https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}.
|
|
66
|
+
*
|
|
67
|
+
* @param s
|
|
68
|
+
* Numeric string.
|
|
69
|
+
*
|
|
70
|
+
* @returns
|
|
71
|
+
* Check digit 0-9 as a string.
|
|
72
|
+
*/
|
|
73
|
+
export function checkDigit(s) {
|
|
74
|
+
// Check digit is the difference from the equal or next of multiple of 10.
|
|
75
|
+
return NUMERIC_CREATOR.character(9 - (checkDigitSum(false, s) + 9) % 10);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Determine if a numeric string has a valid check digit.
|
|
79
|
+
*
|
|
80
|
+
* @param s
|
|
81
|
+
* Numeric string with check digit.
|
|
82
|
+
*
|
|
83
|
+
* @returns
|
|
84
|
+
* True if the check digit is valid.
|
|
85
|
+
*/
|
|
86
|
+
export function hasValidCheckDigit(s) {
|
|
87
|
+
// Check digit is valid if the check digit sum with the weights exchanged is a multiple of 10.
|
|
88
|
+
return checkDigitSum(true, s) % 10 === 0;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Calculate the price or weight sum for a numeric string.
|
|
92
|
+
*
|
|
93
|
+
* @param weightsResults
|
|
94
|
+
* Array of weight results arrays to apply to each digit.
|
|
95
|
+
*
|
|
96
|
+
* @param s
|
|
97
|
+
* Numeric string the same length as the weightsResults array.
|
|
98
|
+
*
|
|
99
|
+
* @returns
|
|
100
|
+
* Accumulated sum of the weight result for each digit at the digit's position.
|
|
101
|
+
*/
|
|
102
|
+
function priceOrWeightSum(weightsResults, s) {
|
|
103
|
+
// Calculate sum of each weight result for each digit at its position.
|
|
104
|
+
return NUMERIC_CREATOR.characterIndexes(s).reduce((accumulator, characterIndex, index) => {
|
|
105
|
+
if (characterIndex === undefined) {
|
|
106
|
+
throw new RangeError(i18nextGS1.t("CharacterSetValidator.invalidCharacterAtPositionOfComponent", {
|
|
107
|
+
ns: utilityNS,
|
|
108
|
+
c: s.charAt(index),
|
|
109
|
+
position: index + 1,
|
|
110
|
+
component: i18nextGS1.t("Check.priceOrWeightComponent")
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
// Add the weight result of the character index to the accumulator.
|
|
114
|
+
return accumulator + weightsResults[index][characterIndex];
|
|
115
|
+
}, 0);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Calculate the price or weight check digit for a four-or five-digit numeric string as per sections 7.9.2-7.9.4 of the
|
|
119
|
+
* {@link https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}.
|
|
120
|
+
*
|
|
121
|
+
* @param s
|
|
122
|
+
* Numeric string exactly four or five characters long.
|
|
123
|
+
*
|
|
124
|
+
* @returns
|
|
125
|
+
* Check digit 0-9 as a string.
|
|
126
|
+
*/
|
|
127
|
+
export function priceOrWeightCheckDigit(s) {
|
|
128
|
+
let checkDigit;
|
|
129
|
+
switch (s.length) {
|
|
130
|
+
case 4:
|
|
131
|
+
checkDigit = NUMERIC_CREATOR.character(priceOrWeightSum([TWO_MINUS_WEIGHT_RESULTS, TWO_MINUS_WEIGHT_RESULTS, THREE_WEIGHT_RESULTS, FIVE_MINUS_WEIGHT_RESULTS], s) * 3 % 10);
|
|
132
|
+
break;
|
|
133
|
+
case 5:
|
|
134
|
+
checkDigit = NUMERIC_CREATOR.character(INVERSE_FIVE_MINUS_WEIGHT_RESULTS[9 - (priceOrWeightSum([FIVE_PLUS_WEIGHT_RESULTS, TWO_MINUS_WEIGHT_RESULTS, FIVE_MINUS_WEIGHT_RESULTS, FIVE_PLUS_WEIGHT_RESULTS, TWO_MINUS_WEIGHT_RESULTS], s) + 9) % 10]);
|
|
135
|
+
break;
|
|
136
|
+
default:
|
|
137
|
+
throw new RangeError(i18nextGS1.t("Check.lengthOfStringForPriceOrWeightMustBeExactly", {
|
|
138
|
+
length: s.length
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
return checkDigit;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Determine if a price or weight check digit is valid for numeric string.
|
|
145
|
+
*
|
|
146
|
+
* @param s
|
|
147
|
+
* Numeric string exactly four or five characters long.
|
|
148
|
+
*
|
|
149
|
+
* @param checkDigit
|
|
150
|
+
* Price or weight check digit.
|
|
151
|
+
*
|
|
152
|
+
* @returns
|
|
153
|
+
* True if the check digit is valid.
|
|
154
|
+
*/
|
|
155
|
+
export function isValidPriceOrWeightCheckDigit(s, checkDigit) {
|
|
156
|
+
return priceOrWeightCheckDigit(s) === checkDigit;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Weights for check character pair calculation.
|
|
160
|
+
*/
|
|
161
|
+
const CHECK_CHARACTER_WEIGHTS = [
|
|
162
|
+
107, 103, 101, 97, 89, 83, 79, 73, 71, 67, 61, 59, 53, 47, 43, 41, 37, 31, 29, 23, 19, 17, 13, 11, 7, 5, 3, 2
|
|
163
|
+
];
|
|
164
|
+
/**
|
|
165
|
+
* Characters used to build check character pair.
|
|
166
|
+
*/
|
|
167
|
+
const CHECK_CHARACTERS = [
|
|
168
|
+
"2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H",
|
|
169
|
+
"J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
|
|
170
|
+
];
|
|
171
|
+
/**
|
|
172
|
+
* Calculate the check character for a GS1 AI encodable character set 82 string as per section 7.9.5 of the {@link
|
|
173
|
+
* https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}.
|
|
174
|
+
*
|
|
175
|
+
* @param s
|
|
176
|
+
* GS1 AI encodable character set 82 string.
|
|
177
|
+
*
|
|
178
|
+
* @returns
|
|
179
|
+
* Check character pair.
|
|
180
|
+
*/
|
|
181
|
+
export function checkCharacterPair(s) {
|
|
182
|
+
// Weights are applied from right to left.
|
|
183
|
+
const weightIndexStart = CHECK_CHARACTER_WEIGHTS.length - s.length;
|
|
184
|
+
if (weightIndexStart < 0) {
|
|
185
|
+
throw new RangeError(i18nextGS1.t("Check.lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo", {
|
|
186
|
+
length: s.length,
|
|
187
|
+
maximumLength: CHECK_CHARACTER_WEIGHTS.length
|
|
188
|
+
}));
|
|
189
|
+
}
|
|
190
|
+
// Calculate sum of each character value multiplied by the weight at its position, mod 1021.
|
|
191
|
+
const checkCharacterPairSum = AI82_CREATOR.characterIndexes(s).reduce((accumulator, characterIndex, index) => {
|
|
192
|
+
if (characterIndex === undefined) {
|
|
193
|
+
throw new RangeError(i18nextGS1.t("CharacterSetValidator.invalidCharacterAtPosition", {
|
|
194
|
+
ns: utilityNS,
|
|
195
|
+
c: s.charAt(index),
|
|
196
|
+
position: index + 1
|
|
197
|
+
}));
|
|
198
|
+
}
|
|
199
|
+
return accumulator + characterIndex * CHECK_CHARACTER_WEIGHTS[weightIndexStart + index];
|
|
200
|
+
}, 0) % 1021;
|
|
201
|
+
const checkCharacterPairSumMod32 = checkCharacterPairSum % 32;
|
|
202
|
+
// Check character pair is the concatenation of the character at position sum div 32 and the character at the position sum mod 32.
|
|
203
|
+
return CHECK_CHARACTERS[(checkCharacterPairSum - checkCharacterPairSumMod32) / 32] + CHECK_CHARACTERS[checkCharacterPairSumMod32];
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Determine if a GS1 AI encodable character set 82 string has a valid check character pair.
|
|
207
|
+
*
|
|
208
|
+
* @param s
|
|
209
|
+
* GS1 AI encodable character set 82 string with check character pair.
|
|
210
|
+
*
|
|
211
|
+
* @returns
|
|
212
|
+
* True if the check character pair is valid.
|
|
213
|
+
*/
|
|
214
|
+
export function hasValidCheckCharacterPair(s) {
|
|
215
|
+
const checkCharacterPairIndex = s.length - 2;
|
|
216
|
+
return checkCharacterPair(s.substring(0, checkCharacterPairIndex)) === s.substring(checkCharacterPairIndex);
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;GAEG;AACH,MAAM,oBAAoB,GAAsB;IAC5C,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE;CACrC,CAAC;AAEF;;GAEG;AACH,MAAM,wBAAwB,GAAsB;IAChD,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;CAC/B,CAAC;AAEF;;GAEG;AACH,MA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KAAK,CAAC,CAAC;IAC5F,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC;IAEb,MAAM,0BAA0B,GAAG,qBAAqB,GAAG,EAAE,CAAC;IAE9D,kIAAkI;IAClI,OAAO,gBAAgB,CAAC,CAAC,qBAAqB,GAAG,0BAA0B,CAAC,GAAG,EAAE,CAAC,GAAG,gBAAgB,CAAC,0BAA0B,CAAC,CAAC;AACtI,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,0BAA0B,CAAC,CAAS;IAChD,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAE7C,OAAO,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,uBAAuB,CAAC,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAAC;AAChH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type CharacterSetCreator } from "@aidc-toolkit/utility";
|
|
2
|
+
import { type ContentCharacterSet } from "./content-character-set.js";
|
|
3
|
+
export declare const CONTENT_CHARACTER_SET_CREATORS: Record<ContentCharacterSet, CharacterSetCreator>;
|
|
4
|
+
//# sourceMappingURL=content-character-set-creators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-character-set-creators.d.ts","sourceRoot":"","sources":["../src/content-character-set-creators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAmB,MAAM,uBAAuB,CAAC;AAElF,OAAO,EAAE,KAAK,mBAAmB,EAAwB,MAAM,4BAA4B,CAAC;AAE5F,eAAO,MAAM,8BAA8B,EAAE,MAAM,CAAC,mBAAmB,EAAE,mBAAmB,CAI3F,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NUMERIC_CREATOR } from "@aidc-toolkit/utility";
|
|
2
|
+
import { AI39_CREATOR, AI82_CREATOR } from "./character-set.js";
|
|
3
|
+
import { ContentCharacterSets } from "./content-character-set.js";
|
|
4
|
+
export const CONTENT_CHARACTER_SET_CREATORS = {
|
|
5
|
+
[ContentCharacterSets.Numeric]: NUMERIC_CREATOR,
|
|
6
|
+
[ContentCharacterSets.AI82]: AI82_CREATOR,
|
|
7
|
+
[ContentCharacterSets.AI39]: AI39_CREATOR
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=content-character-set-creators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-character-set-creators.js","sourceRoot":"","sources":["../src/content-character-set-creators.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAA4B,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAE5F,MAAM,CAAC,MAAM,8BAA8B,GAAqD;IAC5F,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE,eAAe;IAC/C,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,YAAY;IACzC,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,YAAY;CAC5C,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Character sets supported by the reference portion of an identifier or the serial component of a numeric identifier.
|
|
3
|
+
*/
|
|
4
|
+
export declare const ContentCharacterSets: {
|
|
5
|
+
/**
|
|
6
|
+
* Numeric.
|
|
7
|
+
*/
|
|
8
|
+
readonly Numeric: "Numeric";
|
|
9
|
+
/**
|
|
10
|
+
* GS1 AI encodable character set 82.
|
|
11
|
+
*/
|
|
12
|
+
readonly AI82: "AI82";
|
|
13
|
+
/**
|
|
14
|
+
* GS1 AI encodable character set 39.
|
|
15
|
+
*/
|
|
16
|
+
readonly AI39: "AI39";
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Content character set key.
|
|
20
|
+
*/
|
|
21
|
+
export type ContentCharacterSetKey = keyof typeof ContentCharacterSets;
|
|
22
|
+
/**
|
|
23
|
+
* Content character set.
|
|
24
|
+
*/
|
|
25
|
+
export type ContentCharacterSet = typeof ContentCharacterSets[ContentCharacterSetKey];
|
|
26
|
+
//# sourceMappingURL=content-character-set.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-character-set.d.ts","sourceRoot":"","sources":["../src/content-character-set.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,oBAAoB;IAC7B;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;CAEG,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,MAAM,OAAO,oBAAoB,CAAC;AAEvE;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,OAAO,oBAAoB,CAAC,sBAAsB,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Character sets supported by the reference portion of an identifier or the serial component of a numeric identifier.
|
|
3
|
+
*/
|
|
4
|
+
export const ContentCharacterSets = {
|
|
5
|
+
/**
|
|
6
|
+
* Numeric.
|
|
7
|
+
*/
|
|
8
|
+
Numeric: "Numeric",
|
|
9
|
+
/**
|
|
10
|
+
* GS1 AI encodable character set 82.
|
|
11
|
+
*/
|
|
12
|
+
AI82: "AI82",
|
|
13
|
+
/**
|
|
14
|
+
* GS1 AI encodable character set 39.
|
|
15
|
+
*/
|
|
16
|
+
AI39: "AI39"
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=content-character-set.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-character-set.js","sourceRoot":"","sources":["../src/content-character-set.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAChC;;OAEG;IACH,OAAO,EAAE,SAAS;IAElB;;OAEG;IACH,IAAI,EAAE,MAAM;IAEZ;;OAEG;IACH,IAAI,EAAE,MAAM;CACN,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type TransformerInput, type TransformerOutput } from "@aidc-toolkit/utility";
|
|
2
|
+
import { type GTINBaseLength } from "./gtin-length.js";
|
|
3
|
+
import { GTINValidator } from "./gtin-validator.js";
|
|
4
|
+
import type { PrefixProvider } from "./prefix-provider.js";
|
|
5
|
+
declare const GTINCreator_base: import("./abstract-numeric-identifier-creator.js").NumericIdentifierCreatorConstructor<[GTINBaseLength], "GTIN", GTINValidator>;
|
|
6
|
+
/**
|
|
7
|
+
* GTIN creator. Applicable to GTIN-13, GTIN-12, and GTIN-8 types; no applicable to GTIN-14 type.
|
|
8
|
+
*/
|
|
9
|
+
export declare class GTINCreator extends GTINCreator_base {
|
|
10
|
+
#private;
|
|
11
|
+
/**
|
|
12
|
+
* Constructor.
|
|
13
|
+
*
|
|
14
|
+
* @param prefixProvider
|
|
15
|
+
* Prefix provider.
|
|
16
|
+
*
|
|
17
|
+
* @param gtinBaseLength
|
|
18
|
+
* GTIN base length (all except GTIN-14).
|
|
19
|
+
*/
|
|
20
|
+
constructor(prefixProvider: PrefixProvider, gtinBaseLength: GTINBaseLength);
|
|
21
|
+
/**
|
|
22
|
+
* @inheritDoc
|
|
23
|
+
*/
|
|
24
|
+
get prefix(): string;
|
|
25
|
+
/**
|
|
26
|
+
* Create GTIN-14(s) with an indicator digit and reference(s) based on numeric value(s). The value(s) is/are
|
|
27
|
+
* converted to reference(s) of the appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
28
|
+
*
|
|
29
|
+
* @template TTransformerInput
|
|
30
|
+
* Transformer input type.
|
|
31
|
+
*
|
|
32
|
+
* @param indicatorDigit
|
|
33
|
+
* Indicator digit.
|
|
34
|
+
*
|
|
35
|
+
* @param valueOrValues
|
|
36
|
+
* Numeric value(s).
|
|
37
|
+
*
|
|
38
|
+
* @param sparse
|
|
39
|
+
* If true, the value(s) is/are mapped to a sparse sequence resistant to discovery. Default is false.
|
|
40
|
+
*
|
|
41
|
+
* @returns
|
|
42
|
+
* GTIN-14(s).
|
|
43
|
+
*/
|
|
44
|
+
createGTIN14<TTransformerInput extends TransformerInput<number | bigint>>(indicatorDigit: string, valueOrValues: TTransformerInput, sparse?: boolean): TransformerOutput<TTransformerInput, string>;
|
|
45
|
+
/**
|
|
46
|
+
* Create a Restricted Circulation Number (RCN) using a variable measure trade item format. See {@linkcode
|
|
47
|
+
* GTINValidator.parseVariableMeasureRCN} for format details.
|
|
48
|
+
*
|
|
49
|
+
* @param format
|
|
50
|
+
* Format.
|
|
51
|
+
*
|
|
52
|
+
* @param itemReference
|
|
53
|
+
* Item reference.
|
|
54
|
+
*
|
|
55
|
+
* @param priceOrWeight
|
|
56
|
+
* Price or weight (whole number only).
|
|
57
|
+
*
|
|
58
|
+
* @returns
|
|
59
|
+
* RCN-12 or RCN-13.
|
|
60
|
+
*/
|
|
61
|
+
static createVariableMeasureRCN(format: string, itemReference: number, priceOrWeight: number): string;
|
|
62
|
+
}
|
|
63
|
+
export {};
|
|
64
|
+
//# sourceMappingURL=gtin-creator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gtin-creator.d.ts","sourceRoot":"","sources":["../src/gtin-creator.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACzB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,KAAK,cAAc,EAAe,MAAM,kBAAkB,CAAC;AAEpE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;;AAE3D;;GAEG;AACH,qBAAa,WAAY,SAAQ,gBAIjB;;IAUZ;;;;;;;;OAQG;gBACS,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc;IAI1E;;OAEG;IACH,IAAa,MAAM,IAAI,MAAM,CAE5B;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,YAAY,CAAC,iBAAiB,SAAS,gBAAgB,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,UAAQ,GAAG,iBAAiB,CAAC,iBAAiB,EAAE,MAAM,CAAC;IAUjM;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM;CAmGxG"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { Exclusions, NUMERIC_CREATOR } from "@aidc-toolkit/utility";
|
|
2
|
+
import { MixinAbstractNumericIdentifierCreator } from "./abstract-numeric-identifier-creator.js";
|
|
3
|
+
import { checkDigit, priceOrWeightCheckDigit } from "./check.js";
|
|
4
|
+
import { GTINLengths } from "./gtin-length.js";
|
|
5
|
+
import { GTINValidator } from "./gtin-validator.js";
|
|
6
|
+
import { i18nextGS1 } from "./locale/i18n.js";
|
|
7
|
+
/**
|
|
8
|
+
* GTIN creator. Applicable to GTIN-13, GTIN-12, and GTIN-8 types; no applicable to GTIN-14 type.
|
|
9
|
+
*/
|
|
10
|
+
export class GTINCreator extends MixinAbstractNumericIdentifierCreator(GTINValidator) {
|
|
11
|
+
/**
|
|
12
|
+
* Validation parameters for required indicator digit.
|
|
13
|
+
*/
|
|
14
|
+
static #REQUIRED_INDICATOR_DIGIT_VALIDATION = {
|
|
15
|
+
minimumLength: 1,
|
|
16
|
+
maximumLength: 1,
|
|
17
|
+
component: () => i18nextGS1.t("Identifier.indicatorDigit")
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Constructor.
|
|
21
|
+
*
|
|
22
|
+
* @param prefixProvider
|
|
23
|
+
* Prefix provider.
|
|
24
|
+
*
|
|
25
|
+
* @param gtinBaseLength
|
|
26
|
+
* GTIN base length (all except GTIN-14).
|
|
27
|
+
*/
|
|
28
|
+
constructor(prefixProvider, gtinBaseLength) {
|
|
29
|
+
super(prefixProvider, prefixProvider.prefix, gtinBaseLength);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @inheritDoc
|
|
33
|
+
*/
|
|
34
|
+
get prefix() {
|
|
35
|
+
return this.prefixProvider.prefix;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Create GTIN-14(s) with an indicator digit and reference(s) based on numeric value(s). The value(s) is/are
|
|
39
|
+
* converted to reference(s) of the appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
40
|
+
*
|
|
41
|
+
* @template TTransformerInput
|
|
42
|
+
* Transformer input type.
|
|
43
|
+
*
|
|
44
|
+
* @param indicatorDigit
|
|
45
|
+
* Indicator digit.
|
|
46
|
+
*
|
|
47
|
+
* @param valueOrValues
|
|
48
|
+
* Numeric value(s).
|
|
49
|
+
*
|
|
50
|
+
* @param sparse
|
|
51
|
+
* If true, the value(s) is/are mapped to a sparse sequence resistant to discovery. Default is false.
|
|
52
|
+
*
|
|
53
|
+
* @returns
|
|
54
|
+
* GTIN-14(s).
|
|
55
|
+
*/
|
|
56
|
+
createGTIN14(indicatorDigit, valueOrValues, sparse = false) {
|
|
57
|
+
NUMERIC_CREATOR.validate(indicatorDigit, GTINCreator.#REQUIRED_INDICATOR_DIGIT_VALIDATION);
|
|
58
|
+
return NUMERIC_CREATOR.create(GTINLengths.GTIN13 - this.prefixProvider.gs1CompanyPrefix.length - 1, valueOrValues, Exclusions.None, sparse ? this.tweak : undefined, (reference) => {
|
|
59
|
+
const partialIdentifier = indicatorDigit + this.prefixProvider.gs1CompanyPrefix + reference;
|
|
60
|
+
return partialIdentifier + checkDigit(partialIdentifier);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a Restricted Circulation Number (RCN) using a variable measure trade item format. See {@linkcode
|
|
65
|
+
* GTINValidator.parseVariableMeasureRCN} for format details.
|
|
66
|
+
*
|
|
67
|
+
* @param format
|
|
68
|
+
* Format.
|
|
69
|
+
*
|
|
70
|
+
* @param itemReference
|
|
71
|
+
* Item reference.
|
|
72
|
+
*
|
|
73
|
+
* @param priceOrWeight
|
|
74
|
+
* Price or weight (whole number only).
|
|
75
|
+
*
|
|
76
|
+
* @returns
|
|
77
|
+
* RCN-12 or RCN-13.
|
|
78
|
+
*/
|
|
79
|
+
static createVariableMeasureRCN(format, itemReference, priceOrWeight) {
|
|
80
|
+
const formatLength = format.length;
|
|
81
|
+
let validFormat = formatLength === 12 || formatLength === 13;
|
|
82
|
+
let rcnPrefix = "";
|
|
83
|
+
let buildingItemReference = false;
|
|
84
|
+
let itemReferenceString = "";
|
|
85
|
+
let itemReferenceLength = 0;
|
|
86
|
+
let buildingPriceOrWeight = false;
|
|
87
|
+
let priceOrWeightString = "";
|
|
88
|
+
let priceOrWeightLength = 0;
|
|
89
|
+
let calculatePriceOrWeightCheckDigit = false;
|
|
90
|
+
// RCN may be built in almost any order, so defer to builders that will be in ordered array.
|
|
91
|
+
const rcnPrefixBuilder = (partialRCN) => partialRCN + rcnPrefix;
|
|
92
|
+
const itemReferenceBuilder = (partialRCN) => partialRCN + itemReferenceString;
|
|
93
|
+
const priceOrWeightBuilder = (partialRCN) => partialRCN + priceOrWeightString;
|
|
94
|
+
const priceOrWeightCheckDigitBuilder = (partialRCN) => partialRCN + priceOrWeightCheckDigit(priceOrWeightString);
|
|
95
|
+
const checkDigitBuilder = (partialRCN) => partialRCN + checkDigit(partialRCN);
|
|
96
|
+
const rcnBuilders = [rcnPrefixBuilder];
|
|
97
|
+
for (let index = 0; validFormat && index < formatLength; index++) {
|
|
98
|
+
const formatChar = format.charAt(index);
|
|
99
|
+
if (index === 0) {
|
|
100
|
+
validFormat = formatChar === "2";
|
|
101
|
+
rcnPrefix = formatChar;
|
|
102
|
+
}
|
|
103
|
+
else if (formatLength === 13 && index === 1) {
|
|
104
|
+
validFormat = NUMERIC_CREATOR.characterIndex(formatChar) !== undefined;
|
|
105
|
+
rcnPrefix += formatChar;
|
|
106
|
+
}
|
|
107
|
+
else if (index === formatLength - 1) {
|
|
108
|
+
validFormat = formatChar === "C";
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
switch (formatChar) {
|
|
112
|
+
case "I":
|
|
113
|
+
if (!buildingItemReference) {
|
|
114
|
+
// Item reference can't appear more than once.
|
|
115
|
+
validFormat = itemReferenceLength === 0;
|
|
116
|
+
buildingItemReference = true;
|
|
117
|
+
buildingPriceOrWeight = false;
|
|
118
|
+
rcnBuilders.push(itemReferenceBuilder);
|
|
119
|
+
}
|
|
120
|
+
itemReferenceLength++;
|
|
121
|
+
break;
|
|
122
|
+
case "P":
|
|
123
|
+
if (!buildingPriceOrWeight) {
|
|
124
|
+
// Price or weight can't appear more than once.
|
|
125
|
+
validFormat = priceOrWeightLength === 0;
|
|
126
|
+
buildingPriceOrWeight = true;
|
|
127
|
+
buildingItemReference = false;
|
|
128
|
+
rcnBuilders.push(priceOrWeightBuilder);
|
|
129
|
+
}
|
|
130
|
+
priceOrWeightLength++;
|
|
131
|
+
break;
|
|
132
|
+
case "V":
|
|
133
|
+
// Price or weight check digit can't appear more than once.
|
|
134
|
+
validFormat = !calculatePriceOrWeightCheckDigit;
|
|
135
|
+
buildingItemReference = false;
|
|
136
|
+
buildingPriceOrWeight = false;
|
|
137
|
+
calculatePriceOrWeightCheckDigit = true;
|
|
138
|
+
rcnBuilders.push(priceOrWeightCheckDigitBuilder);
|
|
139
|
+
break;
|
|
140
|
+
default:
|
|
141
|
+
validFormat = false;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
validFormat &&= itemReferenceLength !== 0 && priceOrWeightLength !== 0;
|
|
147
|
+
if (!validFormat) {
|
|
148
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidVariableMeasureRCNFormat"));
|
|
149
|
+
}
|
|
150
|
+
itemReferenceString = NUMERIC_CREATOR.create(itemReferenceLength, itemReference);
|
|
151
|
+
priceOrWeightString = NUMERIC_CREATOR.create(priceOrWeightLength, priceOrWeight);
|
|
152
|
+
rcnBuilders.push(checkDigitBuilder);
|
|
153
|
+
return rcnBuilders.reduce((partialRCN, rcnBuilder) => rcnBuilder(partialRCN), "");
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=gtin-creator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gtin-creator.js","sourceRoot":"","sources":["../src/gtin-creator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,UAAU,EACV,eAAe,EAGlB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,qCAAqC,EAAE,MAAM,0CAA0C,CAAC;AACjG,OAAO,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAuB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,qCAAqC,CAIpE,aAAa,CAAC;IACZ;;OAEG;IACH,MAAM,CAAU,oCAAoC,GAA2B;QAC3E,aAAa,EAAE,CAAC;QAChB,aAAa,EAAE,CAAC;QAChB,SAAS,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,2BAA2B,CAAC;KAC7D,CAAC;IAEF;;;;;;;;OAQG;IACH,YAAY,cAA8B,EAAE,cAA8B;QACtE,KAAK,CAAC,cAAc,EAAE,cAAc,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACjE,CAAC;IAED;;OAEG;IACH,IAAa,MAAM;QACf,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC;IACtC,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,YAAY,CAA8D,cAAsB,EAAE,aAAg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ACtF,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { GTINBaseLength } from "./gtin-length.js";
|
|
2
|
+
import type { GTINType } from "./gtin-type.js";
|
|
3
|
+
import type { LeaderTypes } from "./leader-type.js";
|
|
4
|
+
import type { NumericIdentifierDescriptor } from "./numeric-identifier-descriptor.js";
|
|
5
|
+
/**
|
|
6
|
+
* GTIN descriptor.
|
|
7
|
+
*/
|
|
8
|
+
export interface GTINDescriptor extends NumericIdentifierDescriptor {
|
|
9
|
+
/**
|
|
10
|
+
* @inheritDoc
|
|
11
|
+
*/
|
|
12
|
+
readonly identifierType: GTINType;
|
|
13
|
+
/**
|
|
14
|
+
* @inheritDoc
|
|
15
|
+
*/
|
|
16
|
+
readonly length: GTINBaseLength;
|
|
17
|
+
/**
|
|
18
|
+
* @inheritDoc
|
|
19
|
+
*/
|
|
20
|
+
readonly leaderType: typeof LeaderTypes.IndicatorDigit;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=gtin-descriptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gtin-descriptor.d.ts","sourceRoot":"","sources":["../src/gtin-descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAEtF;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,2BAA2B;IAC/D;;OAEG;IACH,QAAQ,CAAC,cAAc,EAAE,QAAQ,CAAC;IAElC;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAEhC;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,OAAO,WAAW,CAAC,cAAc,CAAC;CAC1D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gtin-descriptor.js","sourceRoot":"","sources":["../src/gtin-descriptor.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type PrefixType } from "./prefix-type.js";
|
|
2
|
+
/**
|
|
3
|
+
* GTIN lengths. The numeric values are equal to the lengths of the GTINs.
|
|
4
|
+
*/
|
|
5
|
+
export declare const GTINLengths: {
|
|
6
|
+
/**
|
|
7
|
+
* GTIN-13.
|
|
8
|
+
*/
|
|
9
|
+
readonly GTIN13: 13;
|
|
10
|
+
/**
|
|
11
|
+
* GTIN-12.
|
|
12
|
+
*/
|
|
13
|
+
readonly GTIN12: 12;
|
|
14
|
+
/**
|
|
15
|
+
* GTIN-8.
|
|
16
|
+
*/
|
|
17
|
+
readonly GTIN8: 8;
|
|
18
|
+
/**
|
|
19
|
+
* GTIN-14.
|
|
20
|
+
*/
|
|
21
|
+
readonly GTIN14: 14;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* GTIN length key.
|
|
25
|
+
*/
|
|
26
|
+
export type GTINLengthKey = keyof typeof GTINLengths;
|
|
27
|
+
/**
|
|
28
|
+
* GTIN length.
|
|
29
|
+
*/
|
|
30
|
+
export type GTINLength = typeof GTINLengths[GTINLengthKey];
|
|
31
|
+
/**
|
|
32
|
+
* GTIN base lengths (all except GTIN-14).
|
|
33
|
+
*/
|
|
34
|
+
export declare const GTINBaseLengths: Omit<{
|
|
35
|
+
/**
|
|
36
|
+
* GTIN-13.
|
|
37
|
+
*/
|
|
38
|
+
readonly GTIN13: 13;
|
|
39
|
+
/**
|
|
40
|
+
* GTIN-12.
|
|
41
|
+
*/
|
|
42
|
+
readonly GTIN12: 12;
|
|
43
|
+
/**
|
|
44
|
+
* GTIN-8.
|
|
45
|
+
*/
|
|
46
|
+
readonly GTIN8: 8;
|
|
47
|
+
/**
|
|
48
|
+
* GTIN-14.
|
|
49
|
+
*/
|
|
50
|
+
readonly GTIN14: 14;
|
|
51
|
+
}, "GTIN14">;
|
|
52
|
+
/**
|
|
53
|
+
* GTIN base length key.
|
|
54
|
+
*/
|
|
55
|
+
export type GTINBaseLengthKey = keyof typeof GTINBaseLengths;
|
|
56
|
+
/**
|
|
57
|
+
* GTIN length.
|
|
58
|
+
*/
|
|
59
|
+
export type GTINBaseLength = typeof GTINBaseLengths[GTINBaseLengthKey];
|
|
60
|
+
/**
|
|
61
|
+
* GTIN base lengths by prefix type. Used to determine the GTIN length supported by a prefix type.
|
|
62
|
+
*/
|
|
63
|
+
export declare const GTIN_BASE_TYPES: Readonly<Record<PrefixType, GTINBaseLength>>;
|
|
64
|
+
//# sourceMappingURL=gtin-length.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gtin-length.d.ts","sourceRoot":"","sources":["../src/gtin-length.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAAe,MAAM,kBAAkB,CAAC;AAEhE;;GAEG;AACH,eAAO,MAAM,WAAW;IACpB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;CAEG,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,WAAW,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,WAAW,CAAC,aAAa,CAAC,CAAC;AAE3D;;GAEG;AACH,eAAO,MAAM,eAAe;IAlCxB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;YAiBmD,CAAC;AAE3D;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,eAAe,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,eAAe,CAAC,iBAAiB,CAAC,CAAC;AAEvE;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,CAIxE,CAAC"}
|