@aidc-toolkit/gs1 0.9.6-beta → 0.9.8-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 +2398 -214
- package/dist/index.d.cts +659 -17
- package/dist/index.d.ts +659 -17
- package/dist/index.js +2370 -190
- package/package.json +7 -6
- package/src/check.ts +24 -9
- package/src/idkey.ts +72 -121
- package/src/index.ts +2 -1
- package/src/locale/en/{locale_strings.ts → locale-strings.ts} +2 -0
- package/src/locale/fr/{locale_strings.ts → locale-strings.ts} +2 -0
- package/src/locale/i18n.ts +39 -6
- package/src/locale/i18next.d.ts +5 -3
- package/test/check.test.ts +9 -8
- package/test/idkey.test.ts +30 -29
- /package/src/{character_set.ts → character-set.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aidc-toolkit/gs1",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.8-beta",
|
|
4
4
|
"description": "GS1 AIDC Toolkit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -25,17 +25,18 @@
|
|
|
25
25
|
"test": "vitest run"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@aidc-toolkit/dev": "^0.9.
|
|
28
|
+
"@aidc-toolkit/dev": "^0.9.8-beta",
|
|
29
29
|
"eslint": "^9.16.0",
|
|
30
|
+
"i18next": "^24.1.0",
|
|
30
31
|
"ts-node": "^10.9.2",
|
|
31
32
|
"tsup": "^8.3.5",
|
|
32
33
|
"typescript": "^5.7.2",
|
|
33
|
-
"vitest": "^2.1.
|
|
34
|
+
"vitest": "^2.1.8"
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"@aidc-toolkit/core": "^0.9.
|
|
37
|
-
"@aidc-toolkit/utility": "^0.9.
|
|
38
|
-
"@rollup/rollup-linux-x64-gnu": "^4.28.
|
|
37
|
+
"@aidc-toolkit/core": "^0.9.8-beta",
|
|
38
|
+
"@aidc-toolkit/utility": "^0.9.8-beta",
|
|
39
|
+
"@rollup/rollup-linux-x64-gnu": "^4.28.1",
|
|
39
40
|
"ts-mixer": "^6.0.4"
|
|
40
41
|
}
|
|
41
42
|
}
|
package/src/check.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { NUMERIC_CREATOR } from "@aidc-toolkit/utility";
|
|
2
|
-
import { AI82_CREATOR } from "./
|
|
3
|
-
import
|
|
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
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Results of multiplying digits by 3.
|
|
@@ -57,7 +57,11 @@ export function checkDigitSum(exchangeWeights: boolean, s: string): number {
|
|
|
57
57
|
// Calculate sum of each character value multiplied by the weight at its position.
|
|
58
58
|
return NUMERIC_CREATOR.characterIndexes(s).reduce<number>((accumulator, characterIndex, index) => {
|
|
59
59
|
if (characterIndex === undefined) {
|
|
60
|
-
throw new RangeError(
|
|
60
|
+
throw new RangeError(i18nextGS1.t("CharacterSetValidator.invalidCharacterAtPosition", {
|
|
61
|
+
ns: utilityNS,
|
|
62
|
+
c: s.charAt(index),
|
|
63
|
+
position: index + 1
|
|
64
|
+
}));
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
weight3 = !weight3;
|
|
@@ -109,7 +113,10 @@ export function hasValidCheckDigit(s: string): boolean {
|
|
|
109
113
|
*/
|
|
110
114
|
function priceWeightSum(weightsResults: ReadonlyArray<readonly number[]>, s: string): number {
|
|
111
115
|
if (s.length !== weightsResults.length) {
|
|
112
|
-
throw new RangeError(
|
|
116
|
+
throw new RangeError(i18nextGS1.t("Check.lengthOfStringForPriceOrWeightMustBeExactly", {
|
|
117
|
+
length: s.length,
|
|
118
|
+
exactLength: weightsResults.length
|
|
119
|
+
}));
|
|
113
120
|
}
|
|
114
121
|
|
|
115
122
|
// The value of each character is its index in the character set.
|
|
@@ -118,7 +125,12 @@ function priceWeightSum(weightsResults: ReadonlyArray<readonly number[]>, s: str
|
|
|
118
125
|
// Calculate sum of each weight result for each digit at its position.
|
|
119
126
|
return characterIndexes.reduce<number>((accumulator, characterIndex, index) => {
|
|
120
127
|
if (characterIndex === undefined) {
|
|
121
|
-
throw new RangeError(
|
|
128
|
+
throw new RangeError(i18nextGS1.t("CharacterSetValidator.invalidCharacterAtPositionOfComponent", {
|
|
129
|
+
ns: utilityNS,
|
|
130
|
+
c: s.charAt(index),
|
|
131
|
+
position: index + 1,
|
|
132
|
+
component: i18nextGS1.t("Check.priceOrWeightComponent")
|
|
133
|
+
}));
|
|
122
134
|
}
|
|
123
135
|
|
|
124
136
|
// Add the weight result of the character index to the accumulator.
|
|
@@ -184,8 +196,7 @@ export function checkCharacterPair(s: string): string {
|
|
|
184
196
|
const weightIndexStart = CHECK_CHARACTER_WEIGHTS.length - s.length;
|
|
185
197
|
|
|
186
198
|
if (weightIndexStart < 0) {
|
|
187
|
-
throw new RangeError(
|
|
188
|
-
ns: gs1NS,
|
|
199
|
+
throw new RangeError(i18nextGS1.t("Check.lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo", {
|
|
189
200
|
length: s.length,
|
|
190
201
|
maximumLength: CHECK_CHARACTER_WEIGHTS.length
|
|
191
202
|
}));
|
|
@@ -194,7 +205,11 @@ export function checkCharacterPair(s: string): string {
|
|
|
194
205
|
// Calculate sum of each character value multiplied by the weight at its position, mod 1021.
|
|
195
206
|
const checkCharacterPairSum = AI82_CREATOR.characterIndexes(s).reduce<number>((accumulator, characterIndex, index) => {
|
|
196
207
|
if (characterIndex === undefined) {
|
|
197
|
-
throw new RangeError(
|
|
208
|
+
throw new RangeError(i18nextGS1.t("CharacterSetValidator.invalidCharacterAtPosition", {
|
|
209
|
+
ns: utilityNS,
|
|
210
|
+
c: s.charAt(index),
|
|
211
|
+
position: index + 1
|
|
212
|
+
}));
|
|
198
213
|
}
|
|
199
214
|
|
|
200
215
|
return accumulator + characterIndex * CHECK_CHARACTER_WEIGHTS[weightIndexStart + index];
|