@aidc-toolkit/gs1 0.9.0 → 0.9.2
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/.idea/runConfigurations/build_dev.xml +12 -0
- package/.idea/runConfigurations/eslint.xml +12 -0
- package/eslint.config.js +1 -3
- package/package.json +14 -14
- package/src/check.ts +9 -19
- package/src/idkey.ts +242 -235
- package/src/locale/i18next.d.ts +6 -0
- package/test/check.test.ts +7 -13
- package/test/idkey.test.ts +55 -44
- package/typedoc.json +2 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<component name="ProjectRunConfigurationManager">
|
|
2
|
+
<configuration default="false" name="build-dev" type="js.build_tools.npm" nameIsGenerated="true">
|
|
3
|
+
<package-json value="$PROJECT_DIR$/package.json" />
|
|
4
|
+
<command value="run" />
|
|
5
|
+
<scripts>
|
|
6
|
+
<script value="build-dev" />
|
|
7
|
+
</scripts>
|
|
8
|
+
<node-interpreter value="project" />
|
|
9
|
+
<envs />
|
|
10
|
+
<method v="2" />
|
|
11
|
+
</configuration>
|
|
12
|
+
</component>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<component name="ProjectRunConfigurationManager">
|
|
2
|
+
<configuration default="false" name="eslint" type="js.build_tools.npm" nameIsGenerated="true">
|
|
3
|
+
<package-json value="$PROJECT_DIR$/package.json" />
|
|
4
|
+
<command value="run" />
|
|
5
|
+
<scripts>
|
|
6
|
+
<script value="eslint" />
|
|
7
|
+
</scripts>
|
|
8
|
+
<node-interpreter value="project" />
|
|
9
|
+
<envs />
|
|
10
|
+
<method v="2" />
|
|
11
|
+
</configuration>
|
|
12
|
+
</component>
|
package/eslint.config.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import tseslint from "typescript-eslint";
|
|
2
|
-
import js from "@eslint/js";
|
|
3
2
|
import stylistic from "@stylistic/eslint-plugin";
|
|
4
3
|
import jsdoc from "eslint-plugin-jsdoc";
|
|
5
4
|
import esLintConfigLove from "eslint-config-love";
|
|
6
5
|
import { esLintConfigAIDCToolkit } from "@aidc-toolkit/dev";
|
|
7
6
|
|
|
8
7
|
export default tseslint.config(
|
|
9
|
-
js.configs.recommended,
|
|
10
8
|
...tseslint.configs.strictTypeChecked,
|
|
11
9
|
stylistic.configs["recommended-flat"],
|
|
12
10
|
jsdoc.configs["flat/recommended-typescript"],
|
|
13
11
|
esLintConfigLove,
|
|
14
|
-
esLintConfigAIDCToolkit
|
|
12
|
+
...esLintConfigAIDCToolkit
|
|
15
13
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aidc-toolkit/gs1",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "GS1 AIDC Toolkit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,25 +20,25 @@
|
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"eslint": "eslint .",
|
|
23
|
-
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
23
|
+
"build": "tsup src/index.ts --clean --format cjs,esm --dts",
|
|
24
|
+
"build-dev": "npm run build && tsc src/index.ts --outDir dist --target esnext --moduleResolution nodenext --module nodenext --emitDeclarationOnly --declaration --declarationMap",
|
|
24
25
|
"test": "vitest run"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
|
-
"@aidc-toolkit/dev": "^0.9.
|
|
28
|
-
"@eslint
|
|
29
|
-
"
|
|
30
|
-
"eslint-
|
|
31
|
-
"eslint-plugin-jsdoc": "^50.2.2",
|
|
28
|
+
"@aidc-toolkit/dev": "^0.9.2",
|
|
29
|
+
"@stylistic/eslint-plugin": "^2.10.1",
|
|
30
|
+
"eslint-config-love": "^98.0.2",
|
|
31
|
+
"eslint-plugin-jsdoc": "^50.5.0",
|
|
32
32
|
"ts-node": "^10.9.2",
|
|
33
|
-
"tsup": "^8.
|
|
34
|
-
"typescript": "^5.
|
|
35
|
-
"typescript-eslint": "^8.
|
|
36
|
-
"vitest": "^2.
|
|
33
|
+
"tsup": "^8.3.5",
|
|
34
|
+
"typescript": "^5.6.3",
|
|
35
|
+
"typescript-eslint": "^8.14.0",
|
|
36
|
+
"vitest": "^2.1.4"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@aidc-toolkit/core": "^0.9.
|
|
40
|
-
"@aidc-toolkit/utility": "^0.9.
|
|
41
|
-
"i18next": "^23.
|
|
39
|
+
"@aidc-toolkit/core": "^0.9.2",
|
|
40
|
+
"@aidc-toolkit/utility": "^0.9.2",
|
|
41
|
+
"i18next": "^23.16.5",
|
|
42
42
|
"ts-mixer": "^6.0.4"
|
|
43
43
|
}
|
|
44
44
|
}
|
package/src/check.ts
CHANGED
|
@@ -55,17 +55,15 @@ export function checkDigitSum(exchangeWeights: boolean, s: string): number {
|
|
|
55
55
|
let weight3 = (s.length + Number(exchangeWeights)) % 2 === 0;
|
|
56
56
|
|
|
57
57
|
// Calculate sum of each character value multiplied by the weight at its position.
|
|
58
|
-
|
|
59
|
-
return NUMERIC_CREATOR.characterIndexes(s).reduce((accumulator, characterIndex, index) => {
|
|
58
|
+
return NUMERIC_CREATOR.characterIndexes(s).reduce<number>((accumulator, characterIndex, index) => {
|
|
60
59
|
if (characterIndex === undefined) {
|
|
61
60
|
throw new RangeError(`Invalid character '${s.charAt(index)}' at position ${index + 1}`);
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
weight3 = !weight3;
|
|
65
64
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}, 0)!;
|
|
65
|
+
return accumulator + (weight3 ? THREE_WEIGHT_RESULTS[characterIndex] : characterIndex);
|
|
66
|
+
}, 0);
|
|
69
67
|
}
|
|
70
68
|
|
|
71
69
|
/**
|
|
@@ -108,8 +106,6 @@ export function hasValidCheckDigit(s: string): boolean {
|
|
|
108
106
|
*
|
|
109
107
|
* @returns
|
|
110
108
|
* Accumulated sum of the weight result for each digit at the digit's position.
|
|
111
|
-
*
|
|
112
|
-
* @throws RangeError
|
|
113
109
|
*/
|
|
114
110
|
function priceWeightSum(weightsResults: ReadonlyArray<readonly number[]>, s: string): number {
|
|
115
111
|
if (s.length !== weightsResults.length) {
|
|
@@ -120,16 +116,14 @@ function priceWeightSum(weightsResults: ReadonlyArray<readonly number[]>, s: str
|
|
|
120
116
|
const characterIndexes = NUMERIC_CREATOR.characterIndexes(s);
|
|
121
117
|
|
|
122
118
|
// Calculate sum of each weight result for each digit at its position.
|
|
123
|
-
|
|
124
|
-
return characterIndexes.reduce((accumulator, characterIndex, index) => {
|
|
119
|
+
return characterIndexes.reduce<number>((accumulator, characterIndex, index) => {
|
|
125
120
|
if (characterIndex === undefined) {
|
|
126
121
|
throw new RangeError(`Invalid character '${s.charAt(index)}' at position ${index + 1}`);
|
|
127
122
|
}
|
|
128
123
|
|
|
129
124
|
// Add the weight result of the character index to the accumulator.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}, 0)!;
|
|
125
|
+
return accumulator + weightsResults[index][characterIndex];
|
|
126
|
+
}, 0);
|
|
133
127
|
}
|
|
134
128
|
|
|
135
129
|
/**
|
|
@@ -184,8 +178,6 @@ const CHECK_CHARACTERS = [
|
|
|
184
178
|
*
|
|
185
179
|
* @returns
|
|
186
180
|
* Check character pair.
|
|
187
|
-
*
|
|
188
|
-
* @throws RangeError
|
|
189
181
|
*/
|
|
190
182
|
export function checkCharacterPair(s: string): string {
|
|
191
183
|
// Weights are applied from right to left.
|
|
@@ -200,15 +192,13 @@ export function checkCharacterPair(s: string): string {
|
|
|
200
192
|
}
|
|
201
193
|
|
|
202
194
|
// Calculate sum of each character value multiplied by the weight at its position, mod 1021.
|
|
203
|
-
|
|
204
|
-
const checkCharacterPairSum = AI82_CREATOR.characterIndexes(s).reduce((accumulator, characterIndex, index) => {
|
|
195
|
+
const checkCharacterPairSum = AI82_CREATOR.characterIndexes(s).reduce<number>((accumulator, characterIndex, index) => {
|
|
205
196
|
if (characterIndex === undefined) {
|
|
206
197
|
throw new RangeError(`Invalid character '${s.charAt(index)}' at position ${index + 1}`);
|
|
207
198
|
}
|
|
208
199
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}, 0)! % 1021;
|
|
200
|
+
return accumulator + characterIndex * CHECK_CHARACTER_WEIGHTS[weightIndexStart + index];
|
|
201
|
+
}, 0) % 1021;
|
|
212
202
|
|
|
213
203
|
const checkCharacterPairSumMod32 = checkCharacterPairSum % 32;
|
|
214
204
|
|