@aidc-toolkit/gs1 0.9.16-beta → 0.9.18-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/character-set.d.ts +11 -1
- package/dist/character-set.d.ts.map +1 -1
- package/dist/character-set.js +10 -0
- package/dist/character-set.js.map +1 -1
- package/dist/check.d.ts +7 -8
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +24 -19
- package/dist/check.js.map +1 -1
- package/dist/idkey.d.ts +22 -1
- package/dist/idkey.d.ts.map +1 -1
- package/dist/idkey.js +18 -3
- package/dist/idkey.js.map +1 -1
- package/dist/locale/en/locale-strings.d.ts +3 -3
- package/dist/locale/en/locale-strings.js +3 -3
- package/dist/locale/en/locale-strings.js.map +1 -1
- package/dist/locale/fr/locale-strings.d.ts +3 -3
- package/dist/locale/fr/locale-strings.js +3 -3
- package/dist/locale/fr/locale-strings.js.map +1 -1
- package/dist/locale/i18n.d.ts +6 -6
- package/gs1.iml +9 -0
- package/package.json +6 -8
- package/src/character-set.ts +13 -1
- package/src/check.ts +29 -21
- package/src/idkey.ts +25 -4
- package/src/locale/en/locale-strings.ts +3 -3
- package/src/locale/fr/locale-strings.ts +3 -3
- package/test/check.test.ts +13 -14
- package/test/idkey.test.ts +32 -32
- package/typedoc.json +1 -3
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export declare const localeStrings: {
|
|
2
2
|
readonly Check: {
|
|
3
|
-
readonly lengthOfStringForPriceOrWeightMustBeExactly: "La longueur {{
|
|
3
|
+
readonly lengthOfStringForPriceOrWeightMustBeExactly: "La longueur {{length, number}} de la chaîne pour le prix ou le poids doit être 4 ou 5";
|
|
4
4
|
readonly priceOrWeightComponent: "prix ou poids";
|
|
5
|
-
readonly lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "La longueur {{length}} de la chaîne pour la paire de caractères de vérification doit être inférieure ou égale à {{maximum Length}}";
|
|
5
|
+
readonly lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "La longueur {{length, number}} de la chaîne pour la paire de caractères de vérification doit être inférieure ou égale à {{maximum Length}}";
|
|
6
6
|
};
|
|
7
7
|
readonly IdentificationKey: {
|
|
8
|
-
readonly identificationKeyTypeLength: "{{identificationKeyType}} doit comporter {{length}} chiffres";
|
|
8
|
+
readonly identificationKeyTypeLength: "{{identificationKeyType}} doit comporter {{length, number}} chiffres";
|
|
9
9
|
readonly invalidCheckDigit: "Chiffre de contrôle non valide";
|
|
10
10
|
readonly invalidGTINLength: "Le GTIN doit comporter 13, 12, 8 ou 14 chiffres";
|
|
11
11
|
readonly invalidGTIN14Length: "Le GTIN doit comporter 14 chiffres";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export const localeStrings = {
|
|
2
2
|
Check: {
|
|
3
|
-
lengthOfStringForPriceOrWeightMustBeExactly: "La longueur {{
|
|
3
|
+
lengthOfStringForPriceOrWeightMustBeExactly: "La longueur {{length, number}} de la chaîne pour le prix ou le poids doit être 4 ou 5",
|
|
4
4
|
priceOrWeightComponent: "prix ou poids",
|
|
5
|
-
lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "La longueur {{length}} de la chaîne pour la paire de caractères de vérification doit être inférieure ou égale à {{maximum Length}}"
|
|
5
|
+
lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "La longueur {{length, number}} de la chaîne pour la paire de caractères de vérification doit être inférieure ou égale à {{maximum Length}}"
|
|
6
6
|
},
|
|
7
7
|
IdentificationKey: {
|
|
8
|
-
identificationKeyTypeLength: "{{identificationKeyType}} doit comporter {{length}} chiffres",
|
|
8
|
+
identificationKeyTypeLength: "{{identificationKeyType}} doit comporter {{length, number}} chiffres",
|
|
9
9
|
invalidCheckDigit: "Chiffre de contrôle non valide",
|
|
10
10
|
invalidGTINLength: "Le GTIN doit comporter 13, 12, 8 ou 14 chiffres",
|
|
11
11
|
invalidGTIN14Length: "Le GTIN doit comporter 14 chiffres",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locale-strings.js","sourceRoot":"","sources":["../../../src/locale/fr/locale-strings.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG;IACzB,KAAK,EAAE;QACH,2CAA2C,EAAE,
|
|
1
|
+
{"version":3,"file":"locale-strings.js","sourceRoot":"","sources":["../../../src/locale/fr/locale-strings.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG;IACzB,KAAK,EAAE;QACH,2CAA2C,EAAE,uFAAuF;QACpI,sBAAsB,EAAE,eAAe;QACvC,0DAA0D,EAAE,4IAA4I;KAC3M;IACD,iBAAiB,EAAE;QACf,2BAA2B,EAAE,sEAAsE;QACnG,iBAAiB,EAAE,gCAAgC;QACnD,iBAAiB,EAAE,iDAAiD;QACpE,mBAAmB,EAAE,oCAAoC;QACzD,2BAA2B,EAAE,4CAA4C;QACzE,6BAA6B,EAAE,+CAA+C;QAC9E,mCAAmC,EAAE,2DAA2D;QAChG,mCAAmC,EAAE,2DAA2D;QAChG,qBAAqB,EAAE,4FAA4F;QACnH,mBAAmB,EAAE,mFAAmF;QACxG,4BAA4B,EAAE,qGAAqG;QACnI,cAAc,EAAE,oBAAoB;QACpC,eAAe,EAAE,iBAAiB;QAClC,SAAS,EAAE,WAAW;QACtB,yBAAyB,EAAE,qDAAqD;QAChF,yBAAyB,EAAE,4CAA4C;KAC1E;IACD,MAAM,EAAE;QACJ,gBAAgB,EAAE,6BAA6B;QAC/C,gBAAgB,EAAE,gCAAgC;QAClD,UAAU,EAAE,eAAe;QAC3B,iBAAiB,EAAE,0BAA0B;QAC7C,8BAA8B,EAAE,gEAAgE;QAChG,kCAAkC,EAAE,oEAAoE;QACxG,mCAAmC,EAAE,qEAAqE;QAC1G,iCAAiC,EAAE,sEAAsE;QACzG,wBAAwB,EAAE,kDAAkD;QAC5E,6CAA6C,EAAE,mEAAmE;KACrH;CACK,CAAC"}
|
package/dist/locale/i18n.d.ts
CHANGED
|
@@ -13,12 +13,12 @@ export declare const gs1Resources: {
|
|
|
13
13
|
en: {
|
|
14
14
|
aidct_gs1: {
|
|
15
15
|
readonly Check: {
|
|
16
|
-
readonly lengthOfStringForPriceOrWeightMustBeExactly: "Length {{length}} of string for price or weight
|
|
16
|
+
readonly lengthOfStringForPriceOrWeightMustBeExactly: "Length {{length, number}} of string for price or weight must be 4 or 5";
|
|
17
17
|
readonly priceOrWeightComponent: "price or weight";
|
|
18
|
-
readonly lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "Length {{length}} of string for check character pair must be less than or equal to {{maximumLength}}";
|
|
18
|
+
readonly lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "Length {{length, number}} of string for check character pair must be less than or equal to {{maximumLength, number}}";
|
|
19
19
|
};
|
|
20
20
|
readonly IdentificationKey: {
|
|
21
|
-
readonly identificationKeyTypeLength: "{{identificationKeyType}} must be {{length}} digits long";
|
|
21
|
+
readonly identificationKeyTypeLength: "{{identificationKeyType}} must be {{length, number}} digits long";
|
|
22
22
|
readonly invalidCheckDigit: "Invalid check digit";
|
|
23
23
|
readonly invalidGTINLength: "GTIN must be 13, 12, 8, or 14 digits long";
|
|
24
24
|
readonly invalidGTIN14Length: "GTIN must be 14 digits long";
|
|
@@ -52,12 +52,12 @@ export declare const gs1Resources: {
|
|
|
52
52
|
fr: {
|
|
53
53
|
aidct_gs1: {
|
|
54
54
|
readonly Check: {
|
|
55
|
-
readonly lengthOfStringForPriceOrWeightMustBeExactly: "La longueur {{
|
|
55
|
+
readonly lengthOfStringForPriceOrWeightMustBeExactly: "La longueur {{length, number}} de la chaîne pour le prix ou le poids doit être 4 ou 5";
|
|
56
56
|
readonly priceOrWeightComponent: "prix ou poids";
|
|
57
|
-
readonly lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "La longueur {{length}} de la chaîne pour la paire de caractères de vérification doit être inférieure ou égale à {{maximum Length}}";
|
|
57
|
+
readonly lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "La longueur {{length, number}} de la chaîne pour la paire de caractères de vérification doit être inférieure ou égale à {{maximum Length}}";
|
|
58
58
|
};
|
|
59
59
|
readonly IdentificationKey: {
|
|
60
|
-
readonly identificationKeyTypeLength: "{{identificationKeyType}} doit comporter {{length}} chiffres";
|
|
60
|
+
readonly identificationKeyTypeLength: "{{identificationKeyType}} doit comporter {{length, number}} chiffres";
|
|
61
61
|
readonly invalidCheckDigit: "Chiffre de contrôle non valide";
|
|
62
62
|
readonly invalidGTINLength: "Le GTIN doit comporter 13, 12, 8 ou 14 chiffres";
|
|
63
63
|
readonly invalidGTIN14Length: "Le GTIN doit comporter 14 chiffres";
|
package/gs1.iml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="WEB_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
4
|
+
<exclude-output />
|
|
5
|
+
<content url="file://$MODULE_DIR$" />
|
|
6
|
+
<orderEntry type="inheritedJdk" />
|
|
7
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
8
|
+
</component>
|
|
9
|
+
</module>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aidc-toolkit/gs1",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.18-beta",
|
|
4
4
|
"description": "GS1 AIDC Toolkit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,23 +19,21 @@
|
|
|
19
19
|
"url": "https://www.linkedin.com/in/kdean"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
|
-
"update-aidc-toolkit": "npm update @aidc-toolkit/dev @aidc-toolkit/core @aidc-toolkit/utility",
|
|
23
22
|
"lint": "eslint",
|
|
24
23
|
"build:core": "rimraf dist && tsc --project",
|
|
25
24
|
"build:dev": "npm run build:core -- node_modules/@aidc-toolkit/dev/tsconfig-build-dev.json",
|
|
26
25
|
"build:release": "npm run build:core -- node_modules/@aidc-toolkit/dev/tsconfig-build.json",
|
|
27
26
|
"build:doc": "npm run build:dev",
|
|
28
|
-
"publish-dev": "publish-dev",
|
|
29
27
|
"test": "vitest run"
|
|
30
28
|
},
|
|
31
29
|
"devDependencies": {
|
|
32
|
-
"@aidc-toolkit/dev": "^0.9.
|
|
33
|
-
"vitest": "^3.
|
|
30
|
+
"@aidc-toolkit/dev": "^0.9.18-beta",
|
|
31
|
+
"vitest": "^3.2.2"
|
|
34
32
|
},
|
|
35
33
|
"dependencies": {
|
|
36
|
-
"@aidc-toolkit/core": "^0.9.
|
|
37
|
-
"@aidc-toolkit/utility": "^0.9.
|
|
38
|
-
"i18next": "^
|
|
34
|
+
"@aidc-toolkit/core": "^0.9.18-beta",
|
|
35
|
+
"@aidc-toolkit/utility": "^0.9.18-beta",
|
|
36
|
+
"i18next": "^25.2.1",
|
|
39
37
|
"ts-mixer": "^6.0.4"
|
|
40
38
|
}
|
|
41
39
|
}
|
package/src/character-set.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CharacterSetCreator, Exclusion } from "@aidc-toolkit/utility";
|
|
1
|
+
import { CharacterSetCreator, type CharacterSetValidator, Exclusion } from "@aidc-toolkit/utility";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* GS1 AI encodable character set 82 creator as defined in section 7.11 of the {@link https://www.gs1.org/genspecs | GS1
|
|
@@ -15,6 +15,12 @@ export const AI82_CREATOR = new CharacterSetCreator([
|
|
|
15
15
|
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
|
|
16
16
|
], Exclusion.AllNumeric);
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* GS1 AI encodable character set 82 validator as defined in section 7.11 of the {@link https://www.gs1.org/genspecs |
|
|
20
|
+
* GS1 General Specifications}. Supports {@linkcode Exclusion.AllNumeric}.
|
|
21
|
+
*/
|
|
22
|
+
export const AI82_VALIDATOR = AI82_CREATOR as CharacterSetValidator;
|
|
23
|
+
|
|
18
24
|
/**
|
|
19
25
|
* GS1 AI encodable character set 39 creator as defined in section 7.11 of the {@link https://www.gs1.org/genspecs | GS1
|
|
20
26
|
* General Specifications}. Supports {@linkcode Exclusion.AllNumeric}.
|
|
@@ -25,3 +31,9 @@ export const AI39_CREATOR = new CharacterSetCreator([
|
|
|
25
31
|
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
|
|
26
32
|
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
|
|
27
33
|
], Exclusion.AllNumeric);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* GS1 AI encodable character set 39 validator as defined in section 7.11 of the {@link https://www.gs1.org/genspecs |
|
|
37
|
+
* GS1 General Specifications}. Supports {@linkcode Exclusion.AllNumeric}.
|
|
38
|
+
*/
|
|
39
|
+
export const AI39_VALIDATOR = AI39_CREATOR as CharacterSetValidator;
|
package/src/check.ts
CHANGED
|
@@ -112,18 +112,8 @@ export function hasValidCheckDigit(s: string): boolean {
|
|
|
112
112
|
* Accumulated sum of the weight result for each digit at the digit's position.
|
|
113
113
|
*/
|
|
114
114
|
function priceWeightSum(weightsResults: ReadonlyArray<readonly number[]>, s: string): number {
|
|
115
|
-
if (s.length !== weightsResults.length) {
|
|
116
|
-
throw new RangeError(i18nextGS1.t("Check.lengthOfStringForPriceOrWeightMustBeExactly", {
|
|
117
|
-
length: s.length,
|
|
118
|
-
exactLength: weightsResults.length
|
|
119
|
-
}));
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// The value of each character is its index in the character set.
|
|
123
|
-
const characterIndexes = NUMERIC_CREATOR.characterIndexes(s);
|
|
124
|
-
|
|
125
115
|
// Calculate sum of each weight result for each digit at its position.
|
|
126
|
-
return characterIndexes.reduce<number>((accumulator, characterIndex, index) => {
|
|
116
|
+
return NUMERIC_CREATOR.characterIndexes(s).reduce<number>((accumulator, characterIndex, index) => {
|
|
127
117
|
if (characterIndex === undefined) {
|
|
128
118
|
throw new RangeError(i18nextGS1.t("CharacterSetValidator.invalidCharacterAtPositionOfComponent", {
|
|
129
119
|
ns: utilityNS,
|
|
@@ -139,31 +129,49 @@ function priceWeightSum(weightsResults: ReadonlyArray<readonly number[]>, s: str
|
|
|
139
129
|
}
|
|
140
130
|
|
|
141
131
|
/**
|
|
142
|
-
* Calculate the price/weight check digit for a four-digit numeric string as per section 7.9.3 of the {@link
|
|
132
|
+
* Calculate the price/weight check digit for a four-or five-digit numeric string as per section 7.9.3 of the {@link
|
|
143
133
|
* https://www.gs1.org/genspecs | GS1 General Specifications}.
|
|
144
134
|
*
|
|
145
135
|
* @param s
|
|
146
|
-
* Numeric string exactly four characters long.
|
|
136
|
+
* Numeric string exactly four or five characters long.
|
|
147
137
|
*
|
|
148
138
|
* @returns
|
|
149
139
|
* Check digit 0-9 as a string.
|
|
150
140
|
*/
|
|
151
|
-
export function
|
|
152
|
-
|
|
141
|
+
export function priceWeightCheckDigit(s: string): string {
|
|
142
|
+
let checkDigit: string;
|
|
143
|
+
|
|
144
|
+
switch (s.length) {
|
|
145
|
+
case 4:
|
|
146
|
+
checkDigit = NUMERIC_CREATOR.character(priceWeightSum([TWO_MINUS_WEIGHT_RESULTS, TWO_MINUS_WEIGHT_RESULTS, THREE_WEIGHT_RESULTS, FIVE_MINUS_WEIGHT_RESULTS], s) * 3 % 10);
|
|
147
|
+
break;
|
|
148
|
+
|
|
149
|
+
case 5:
|
|
150
|
+
checkDigit = NUMERIC_CREATOR.character(INVERSE_FIVE_MINUS_WEIGHT_RESULTS[9 - (priceWeightSum([FIVE_PLUS_WEIGHT_RESULTS, TWO_MINUS_WEIGHT_RESULTS, FIVE_MINUS_WEIGHT_RESULTS, FIVE_PLUS_WEIGHT_RESULTS, TWO_MINUS_WEIGHT_RESULTS], s) + 9) % 10]);
|
|
151
|
+
break;
|
|
152
|
+
|
|
153
|
+
default:
|
|
154
|
+
throw new RangeError(i18nextGS1.t("Check.lengthOfStringForPriceOrWeightMustBeExactly", {
|
|
155
|
+
length: s.length
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return checkDigit;
|
|
153
160
|
}
|
|
154
161
|
|
|
155
162
|
/**
|
|
156
|
-
*
|
|
157
|
-
* https://www.gs1.org/genspecs | GS1 General Specifications}.
|
|
163
|
+
* Determine if a numeric string has a valid price/weight check digit.
|
|
158
164
|
*
|
|
159
165
|
* @param s
|
|
160
|
-
* Numeric string exactly five characters long.
|
|
166
|
+
* Numeric string exactly five or six characters long.
|
|
161
167
|
*
|
|
162
168
|
* @returns
|
|
163
|
-
*
|
|
169
|
+
* True if the check digit is valid.
|
|
164
170
|
*/
|
|
165
|
-
export function
|
|
166
|
-
|
|
171
|
+
export function hasValidPriceWeightCheckDigit(s: string): boolean {
|
|
172
|
+
const priceWeightCheckDigitIndex = s.length - 1;
|
|
173
|
+
|
|
174
|
+
return priceWeightCheckDigit(s.substring(0, priceWeightCheckDigitIndex)) === s.charAt(priceWeightCheckDigitIndex);
|
|
167
175
|
}
|
|
168
176
|
|
|
169
177
|
/**
|
package/src/idkey.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
type StringValidator,
|
|
9
9
|
type TransformerInput,
|
|
10
10
|
type TransformerOutput,
|
|
11
|
-
|
|
11
|
+
mapIterable
|
|
12
12
|
} from "@aidc-toolkit/utility";
|
|
13
13
|
import { Mixin } from "ts-mixer";
|
|
14
14
|
import { AI39_CREATOR, AI82_CREATOR } from "./character-set.js";
|
|
@@ -141,6 +141,9 @@ export interface IdentificationKeyValidation extends StringValidation {
|
|
|
141
141
|
/**
|
|
142
142
|
* Identification key validator. Validates an identification key against its definition in section 3 of the {@link
|
|
143
143
|
* https://www.gs1.org/genspecs | GS1 General Specifications}.
|
|
144
|
+
*
|
|
145
|
+
* @template TIdentificationKeyValidation
|
|
146
|
+
* Identification key validation type.
|
|
144
147
|
*/
|
|
145
148
|
export interface IdentificationKeyValidator<TIdentificationKeyValidation extends IdentificationKeyValidation = IdentificationKeyValidation> extends StringValidator<TIdentificationKeyValidation> {
|
|
146
149
|
/**
|
|
@@ -167,7 +170,7 @@ export interface IdentificationKeyValidator<TIdentificationKeyValidation extends
|
|
|
167
170
|
get referenceCharacterSet(): ContentCharacterSet;
|
|
168
171
|
|
|
169
172
|
/**
|
|
170
|
-
* Get the reference
|
|
173
|
+
* Get the reference creator.
|
|
171
174
|
*/
|
|
172
175
|
get referenceCreator(): CharacterSetCreator;
|
|
173
176
|
|
|
@@ -1194,6 +1197,9 @@ export interface NumericIdentificationKeyCreator extends NumericIdentificationKe
|
|
|
1194
1197
|
* Create identification key(s) with reference(s) based on numeric value(s). The value(s) is/are converted to
|
|
1195
1198
|
* references of the appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
1196
1199
|
*
|
|
1200
|
+
* @template TTransformerInput
|
|
1201
|
+
* Transformer input type.
|
|
1202
|
+
*
|
|
1197
1203
|
* @param valueOrValues
|
|
1198
1204
|
* Numeric value(s).
|
|
1199
1205
|
*
|
|
@@ -1405,6 +1411,9 @@ export class GTINCreator extends Mixin(GTINValidator, AbstractNumericIdentificat
|
|
|
1405
1411
|
* Create GTIN-14(s) with an indicator digit and reference(s) based on numeric value(s). The value(s) is/are
|
|
1406
1412
|
* converted to reference(s) of the appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
1407
1413
|
*
|
|
1414
|
+
* @template TTransformerInput
|
|
1415
|
+
* Transformer input type.
|
|
1416
|
+
*
|
|
1408
1417
|
* @param indicatorDigit
|
|
1409
1418
|
* Indicator digit.
|
|
1410
1419
|
*
|
|
@@ -1487,6 +1496,9 @@ export class SerializableNumericIdentificationKeyCreator extends Mixin(Serializa
|
|
|
1487
1496
|
/**
|
|
1488
1497
|
* Concatenate a validated base identification key with serial component(s).
|
|
1489
1498
|
*
|
|
1499
|
+
* @template TTransformerInput
|
|
1500
|
+
* Transformer input type.
|
|
1501
|
+
*
|
|
1490
1502
|
* @param baseIdentificationKey
|
|
1491
1503
|
* Base identification key.
|
|
1492
1504
|
*
|
|
@@ -1521,7 +1533,7 @@ export class SerializableNumericIdentificationKeyCreator extends Mixin(Serializa
|
|
|
1521
1533
|
if (typeof serialComponentOrComponents !== "object") {
|
|
1522
1534
|
result = validateAndConcatenate(serialComponentOrComponents);
|
|
1523
1535
|
} else {
|
|
1524
|
-
result =
|
|
1536
|
+
result = mapIterable(serialComponentOrComponents, validateAndConcatenate);
|
|
1525
1537
|
}
|
|
1526
1538
|
|
|
1527
1539
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type determination is handled above.
|
|
@@ -1532,6 +1544,9 @@ export class SerializableNumericIdentificationKeyCreator extends Mixin(Serializa
|
|
|
1532
1544
|
* Create serialized identification key(s) with a reference based on a numeric value concatenated with serial
|
|
1533
1545
|
* component(s). The value is converted to a reference of the appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
1534
1546
|
*
|
|
1547
|
+
* @template TTransformerInput
|
|
1548
|
+
* Transformer input type.
|
|
1549
|
+
*
|
|
1535
1550
|
* @param value
|
|
1536
1551
|
* Numeric value of the reference.
|
|
1537
1552
|
*
|
|
@@ -1551,6 +1566,9 @@ export class SerializableNumericIdentificationKeyCreator extends Mixin(Serializa
|
|
|
1551
1566
|
/**
|
|
1552
1567
|
* Concatenate a base identification key with serial component(s).
|
|
1553
1568
|
*
|
|
1569
|
+
* @template TTransformerInput
|
|
1570
|
+
* Transformer input type.
|
|
1571
|
+
*
|
|
1554
1572
|
* @param baseIdentificationKey
|
|
1555
1573
|
* Base identification key.
|
|
1556
1574
|
*
|
|
@@ -1618,6 +1636,9 @@ export class NonNumericIdentificationKeyCreator extends Mixin(NonNumericIdentifi
|
|
|
1618
1636
|
/**
|
|
1619
1637
|
* Create identification key(s) with reference(s).
|
|
1620
1638
|
*
|
|
1639
|
+
* @template TTransformerInput
|
|
1640
|
+
* Transformer input type.
|
|
1641
|
+
*
|
|
1621
1642
|
* @param referenceOrReferences
|
|
1622
1643
|
* Reference(s).
|
|
1623
1644
|
*
|
|
@@ -1653,7 +1674,7 @@ export class NonNumericIdentificationKeyCreator extends Mixin(NonNumericIdentifi
|
|
|
1653
1674
|
if (typeof referenceOrReferences !== "object") {
|
|
1654
1675
|
result = validateAndCreate(referenceOrReferences);
|
|
1655
1676
|
} else {
|
|
1656
|
-
result =
|
|
1677
|
+
result = mapIterable(referenceOrReferences, validateAndCreate);
|
|
1657
1678
|
}
|
|
1658
1679
|
|
|
1659
1680
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type determination is handled above.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export const localeStrings = {
|
|
2
2
|
Check: {
|
|
3
|
-
lengthOfStringForPriceOrWeightMustBeExactly: "Length {{length}} of string for price or weight
|
|
3
|
+
lengthOfStringForPriceOrWeightMustBeExactly: "Length {{length, number}} of string for price or weight must be 4 or 5",
|
|
4
4
|
priceOrWeightComponent: "price or weight",
|
|
5
|
-
lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "Length {{length}} of string for check character pair must be less than or equal to {{maximumLength}}"
|
|
5
|
+
lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "Length {{length, number}} of string for check character pair must be less than or equal to {{maximumLength, number}}"
|
|
6
6
|
},
|
|
7
7
|
IdentificationKey: {
|
|
8
|
-
identificationKeyTypeLength: "{{identificationKeyType}} must be {{length}} digits long",
|
|
8
|
+
identificationKeyTypeLength: "{{identificationKeyType}} must be {{length, number}} digits long",
|
|
9
9
|
invalidCheckDigit: "Invalid check digit",
|
|
10
10
|
invalidGTINLength: "GTIN must be 13, 12, 8, or 14 digits long",
|
|
11
11
|
invalidGTIN14Length: "GTIN must be 14 digits long",
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export const localeStrings = {
|
|
2
2
|
Check: {
|
|
3
|
-
lengthOfStringForPriceOrWeightMustBeExactly: "La longueur {{
|
|
3
|
+
lengthOfStringForPriceOrWeightMustBeExactly: "La longueur {{length, number}} de la chaîne pour le prix ou le poids doit être 4 ou 5",
|
|
4
4
|
priceOrWeightComponent: "prix ou poids",
|
|
5
|
-
lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "La longueur {{length}} de la chaîne pour la paire de caractères de vérification doit être inférieure ou égale à {{maximum Length}}"
|
|
5
|
+
lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "La longueur {{length, number}} de la chaîne pour la paire de caractères de vérification doit être inférieure ou égale à {{maximum Length}}"
|
|
6
6
|
},
|
|
7
7
|
IdentificationKey: {
|
|
8
|
-
identificationKeyTypeLength: "{{identificationKeyType}} doit comporter {{length}} chiffres",
|
|
8
|
+
identificationKeyTypeLength: "{{identificationKeyType}} doit comporter {{length, number}} chiffres",
|
|
9
9
|
invalidCheckDigit: "Chiffre de contrôle non valide",
|
|
10
10
|
invalidGTINLength: "Le GTIN doit comporter 13, 12, 8 ou 14 chiffres",
|
|
11
11
|
invalidGTIN14Length: "Le GTIN doit comporter 14 chiffres",
|
package/test/check.test.ts
CHANGED
|
@@ -5,12 +5,11 @@ import {
|
|
|
5
5
|
checkCharacterPair,
|
|
6
6
|
checkDigit,
|
|
7
7
|
checkDigitSum,
|
|
8
|
-
fiveDigitPriceWeightCheckDigit,
|
|
9
|
-
fourDigitPriceWeightCheckDigit,
|
|
10
8
|
hasValidCheckCharacterPair,
|
|
11
|
-
hasValidCheckDigit,
|
|
12
|
-
i18nGS1Init
|
|
13
|
-
|
|
9
|
+
hasValidCheckDigit, hasValidPriceWeightCheckDigit,
|
|
10
|
+
i18nGS1Init,
|
|
11
|
+
priceWeightCheckDigit
|
|
12
|
+
} from "../src";
|
|
14
13
|
|
|
15
14
|
await i18nGS1Init(I18NEnvironment.CLI, true);
|
|
16
15
|
|
|
@@ -69,7 +68,8 @@ describe("Price/weight check digit", () => {
|
|
|
69
68
|
|
|
70
69
|
const sum = weight2Minus(characterIndexes[0]) + weight2Minus(characterIndexes[1]) + weight3(characterIndexes[2]) + weight5Minus(characterIndexes[3]);
|
|
71
70
|
|
|
72
|
-
expect(
|
|
71
|
+
expect(priceWeightCheckDigit(s)).toBe(NUMERIC_CREATOR.character(sum * 3 % 10));
|
|
72
|
+
expect(hasValidPriceWeightCheckDigit(s + priceWeightCheckDigit(s))).toBe(true);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
function testFiveDigitPriceWeightCheckDigit(s: string): void {
|
|
@@ -78,7 +78,8 @@ describe("Price/weight check digit", () => {
|
|
|
78
78
|
|
|
79
79
|
const sum = weight5Plus(characterIndexes[0]) + weight2Minus(characterIndexes[1]) + weight5Minus(characterIndexes[2]) + weight5Plus(characterIndexes[3]) + weight2Minus(characterIndexes[4]);
|
|
80
80
|
|
|
81
|
-
expect(weight5Minus(Number(
|
|
81
|
+
expect(weight5Minus(Number(priceWeightCheckDigit(s)))).toBe(9 - (sum + 9) % 10);
|
|
82
|
+
expect(hasValidPriceWeightCheckDigit(s + priceWeightCheckDigit(s))).toBe(true);
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
test("Four-digit", () => {
|
|
@@ -92,10 +93,6 @@ describe("Price/weight check digit", () => {
|
|
|
92
93
|
testFourDigitPriceWeightCheckDigit("7890");
|
|
93
94
|
testFourDigitPriceWeightCheckDigit("8901");
|
|
94
95
|
testFourDigitPriceWeightCheckDigit("9012");
|
|
95
|
-
|
|
96
|
-
expect(() => fourDigitPriceWeightCheckDigit("l234")).toThrow("Invalid character 'l' at position 1");
|
|
97
|
-
expect(() => fourDigitPriceWeightCheckDigit("123")).toThrow("Length 3 of string for price or weight sum must be exactly 4");
|
|
98
|
-
expect(() => fourDigitPriceWeightCheckDigit("12345")).toThrow("Length 5 of string for price or weight sum must be exactly 4");
|
|
99
96
|
});
|
|
100
97
|
|
|
101
98
|
test("Five-digit", () => {
|
|
@@ -109,10 +106,12 @@ describe("Price/weight check digit", () => {
|
|
|
109
106
|
testFiveDigitPriceWeightCheckDigit("78901");
|
|
110
107
|
testFiveDigitPriceWeightCheckDigit("89012");
|
|
111
108
|
testFiveDigitPriceWeightCheckDigit("90123");
|
|
109
|
+
});
|
|
112
110
|
|
|
113
|
-
|
|
114
|
-
expect(() =>
|
|
115
|
-
expect(() =>
|
|
111
|
+
test("Invalid", () => {
|
|
112
|
+
expect(() => priceWeightCheckDigit("l2345")).toThrow("Invalid character 'l' at position 1 of price or weight");
|
|
113
|
+
expect(() => priceWeightCheckDigit("123")).toThrow("Length 3 of string for price or weight must be 4 or 5");
|
|
114
|
+
expect(() => priceWeightCheckDigit("123456")).toThrow("Length 6 of string for price or weight must be 4 or 5");
|
|
116
115
|
});
|
|
117
116
|
});
|
|
118
117
|
|
package/test/idkey.test.ts
CHANGED
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
type SerializableNumericIdentificationKeyCreator,
|
|
41
41
|
type SerializableNumericIdentificationKeyValidator,
|
|
42
42
|
SSCC_VALIDATOR
|
|
43
|
-
} from "../src
|
|
43
|
+
} from "../src";
|
|
44
44
|
|
|
45
45
|
await i18nGS1Init(I18NEnvironment.CLI);
|
|
46
46
|
|
|
@@ -427,20 +427,20 @@ function testNumericIdentificationKeyCreator(creator: NumericIdentificationKeyCr
|
|
|
427
427
|
expect(creator.referenceLength).toBe(referenceLength);
|
|
428
428
|
expect(creator.capacity).toBe(Number(CharacterSetCreator.powerOf10(referenceLength)));
|
|
429
429
|
|
|
430
|
-
const sequenceIterator =
|
|
430
|
+
const sequenceIterator = creator.create(new Sequence(0, referenceCount))[Symbol.iterator]();
|
|
431
431
|
|
|
432
|
-
let
|
|
432
|
+
let index = 0;
|
|
433
433
|
|
|
434
|
-
|
|
434
|
+
for (const identificationKey of creator.createAll()) {
|
|
435
435
|
validate(identificationKey, index, false);
|
|
436
436
|
|
|
437
437
|
expect(Number((hasExtensionDigit ? identificationKey.charAt(0) : "") + identificationKey.substring(referenceSubstringStart, referenceSubstringEnd))).toBe(index);
|
|
438
438
|
expect(sequenceIterator.next().value).toBe(identificationKey);
|
|
439
439
|
|
|
440
|
-
|
|
441
|
-
}
|
|
440
|
+
index++;
|
|
441
|
+
}
|
|
442
442
|
|
|
443
|
-
expect(
|
|
443
|
+
expect(index).toBe(referenceCount);
|
|
444
444
|
expect(sequenceIterator.next().value).toBeUndefined();
|
|
445
445
|
|
|
446
446
|
const randomValues = new Array<number>();
|
|
@@ -464,9 +464,9 @@ function testNumericIdentificationKeyCreator(creator: NumericIdentificationKeyCr
|
|
|
464
464
|
|
|
465
465
|
const sequenceSet = new Set<string>();
|
|
466
466
|
|
|
467
|
-
let
|
|
467
|
+
let index = 0;
|
|
468
468
|
|
|
469
|
-
|
|
469
|
+
for (const identificationKey of creator.create(new Sequence(0, sparseReferenceCount), true)) {
|
|
470
470
|
validate(identificationKey, index, true);
|
|
471
471
|
|
|
472
472
|
sequential &&= Number((hasExtensionDigit ? identificationKey.charAt(0) : "") + identificationKey.substring(referenceSubstringStart, referenceSubstringEnd)) === index;
|
|
@@ -474,11 +474,11 @@ function testNumericIdentificationKeyCreator(creator: NumericIdentificationKeyCr
|
|
|
474
474
|
expect(sequenceSet.has(identificationKey)).toBe(false);
|
|
475
475
|
sequenceSet.add(identificationKey);
|
|
476
476
|
|
|
477
|
-
|
|
478
|
-
}
|
|
477
|
+
index++;
|
|
478
|
+
}
|
|
479
479
|
|
|
480
480
|
expect(sequential).toBe(false);
|
|
481
|
-
expect(
|
|
481
|
+
expect(index).toBe(sparseReferenceCount);
|
|
482
482
|
|
|
483
483
|
const randomValues = new Array<number>();
|
|
484
484
|
const identificationKeys = new Array<string>();
|
|
@@ -565,17 +565,17 @@ function testGTINCreator(creator: GTINCreator): void {
|
|
|
565
565
|
}
|
|
566
566
|
|
|
567
567
|
test("GTIN-14 straight", () => {
|
|
568
|
-
let
|
|
568
|
+
let index = 0;
|
|
569
569
|
|
|
570
|
-
|
|
570
|
+
for (const gtin of creator.createGTIN14("5", new Sequence(0, referenceCount))) {
|
|
571
571
|
expect(Number(gtin.substring(referenceSubstringStart, referenceSubstringEnd))).toBe(index);
|
|
572
572
|
|
|
573
573
|
validate(gtin, index, false);
|
|
574
574
|
|
|
575
|
-
|
|
576
|
-
}
|
|
575
|
+
index++;
|
|
576
|
+
}
|
|
577
577
|
|
|
578
|
-
expect(
|
|
578
|
+
expect(index).toBe(referenceCount);
|
|
579
579
|
|
|
580
580
|
const randomValues = new Array<number>();
|
|
581
581
|
const identificationKeys = new Array<string>();
|
|
@@ -598,9 +598,9 @@ function testGTINCreator(creator: GTINCreator): void {
|
|
|
598
598
|
|
|
599
599
|
const sequenceSet = new Set<string>();
|
|
600
600
|
|
|
601
|
-
let
|
|
601
|
+
let index = 0;
|
|
602
602
|
|
|
603
|
-
|
|
603
|
+
for (const gtin of creator.createGTIN14("5", new Sequence(0, sparseReferenceCount), true)) {
|
|
604
604
|
sequential &&= Number(gtin.substring(referenceSubstringStart, referenceSubstringEnd)) === index;
|
|
605
605
|
|
|
606
606
|
validate(gtin, index, true);
|
|
@@ -608,11 +608,11 @@ function testGTINCreator(creator: GTINCreator): void {
|
|
|
608
608
|
expect(sequenceSet.has(gtin)).toBe(false);
|
|
609
609
|
sequenceSet.add(gtin);
|
|
610
610
|
|
|
611
|
-
|
|
612
|
-
}
|
|
611
|
+
index++;
|
|
612
|
+
}
|
|
613
613
|
|
|
614
614
|
expect(sequential).toBe(false);
|
|
615
|
-
expect(
|
|
615
|
+
expect(index).toBe(sparseReferenceCount);
|
|
616
616
|
|
|
617
617
|
const randomValues = new Array<number>();
|
|
618
618
|
const identificationKeys = new Array<string>();
|
|
@@ -943,9 +943,9 @@ function testNonNumericIdentificationKeyCreator(creator: NonNumericIdentificatio
|
|
|
943
943
|
test("Straight", () => {
|
|
944
944
|
expect(creator.referenceLength).toBe(referenceLength);
|
|
945
945
|
|
|
946
|
-
let
|
|
946
|
+
let index = 0;
|
|
947
947
|
|
|
948
|
-
|
|
948
|
+
for (const identificationKey of creator.create(creator.referenceCreator.create(TEST_REFERENCE_LENGTH, new Sequence(0, referenceCount)))) {
|
|
949
949
|
expect(() => {
|
|
950
950
|
creator.validate(identificationKey);
|
|
951
951
|
}).not.toThrow(RangeError);
|
|
@@ -958,18 +958,18 @@ function testNonNumericIdentificationKeyCreator(creator: NonNumericIdentificatio
|
|
|
958
958
|
|
|
959
959
|
expect(identificationKey).toBe(creator.referenceCreator.create(TEST_REFERENCE_LENGTH, index, Exclusion.None, undefined, reference => creator.create(reference)));
|
|
960
960
|
|
|
961
|
-
|
|
962
|
-
}
|
|
961
|
+
index++;
|
|
962
|
+
}
|
|
963
963
|
|
|
964
|
-
expect(
|
|
964
|
+
expect(index).toBe(referenceCount);
|
|
965
965
|
});
|
|
966
966
|
|
|
967
967
|
test("Sparse", () => {
|
|
968
968
|
let sequential = true;
|
|
969
969
|
|
|
970
|
-
let
|
|
970
|
+
let index = 0;
|
|
971
971
|
|
|
972
|
-
|
|
972
|
+
for (const identificationKey of creator.create(creator.referenceCreator.create(TEST_REFERENCE_LENGTH, new Sequence(0, referenceCount), Exclusion.None, 123456n))) {
|
|
973
973
|
expect(() => {
|
|
974
974
|
creator.validate(identificationKey);
|
|
975
975
|
}).not.toThrow(RangeError);
|
|
@@ -984,11 +984,11 @@ function testNonNumericIdentificationKeyCreator(creator: NonNumericIdentificatio
|
|
|
984
984
|
|
|
985
985
|
expect(identificationKey).toBe(creator.referenceCreator.create(TEST_REFERENCE_LENGTH, index, Exclusion.None, 123456n, reference => creator.create(reference)));
|
|
986
986
|
|
|
987
|
-
|
|
988
|
-
}
|
|
987
|
+
index++;
|
|
988
|
+
}
|
|
989
989
|
|
|
990
990
|
expect(sequential).toBe(false);
|
|
991
|
-
expect(
|
|
991
|
+
expect(index).toBe(referenceCount);
|
|
992
992
|
});
|
|
993
993
|
|
|
994
994
|
test("Position offset", () => {
|