@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/src/locale/i18next.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { UtilityLocaleStrings } from "@aidc-toolkit/utility";
|
|
2
|
+
import type { GS1LocaleStrings } from "./i18n.js";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Internationalization module.
|
|
@@ -8,9 +9,10 @@ declare module "i18next" {
|
|
|
8
9
|
* Custom type options for this package.
|
|
9
10
|
*/
|
|
10
11
|
interface CustomTypeOptions {
|
|
12
|
+
defaultNS: "aidct_gs1";
|
|
11
13
|
resources: {
|
|
12
|
-
|
|
13
|
-
aidct_gs1:
|
|
14
|
+
aidct_utility: UtilityLocaleStrings;
|
|
15
|
+
aidct_gs1: GS1LocaleStrings;
|
|
14
16
|
};
|
|
15
17
|
}
|
|
16
18
|
}
|
package/test/check.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I18NEnvironment
|
|
1
|
+
import { I18NEnvironment } from "@aidc-toolkit/core";
|
|
2
2
|
import { NUMERIC_CREATOR } from "@aidc-toolkit/utility";
|
|
3
3
|
import { describe, expect, test } from "vitest";
|
|
4
4
|
import {
|
|
@@ -8,10 +8,11 @@ import {
|
|
|
8
8
|
fiveDigitPriceWeightCheckDigit,
|
|
9
9
|
fourDigitPriceWeightCheckDigit,
|
|
10
10
|
hasValidCheckCharacterPair,
|
|
11
|
-
hasValidCheckDigit
|
|
11
|
+
hasValidCheckDigit,
|
|
12
|
+
i18nGS1Init
|
|
12
13
|
} from "../src/index.js";
|
|
13
14
|
|
|
14
|
-
await
|
|
15
|
+
await i18nGS1Init(I18NEnvironment.CLI, true);
|
|
15
16
|
|
|
16
17
|
describe("Check digit", () => {
|
|
17
18
|
const testNumericString = "1234567890";
|
|
@@ -93,8 +94,8 @@ describe("Price/weight check digit", () => {
|
|
|
93
94
|
testFourDigitPriceWeightCheckDigit("9012");
|
|
94
95
|
|
|
95
96
|
expect(() => fourDigitPriceWeightCheckDigit("l234")).toThrow("Invalid character 'l' at position 1");
|
|
96
|
-
expect(() => fourDigitPriceWeightCheckDigit("123")).toThrow("
|
|
97
|
-
expect(() => fourDigitPriceWeightCheckDigit("12345")).toThrow("
|
|
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");
|
|
98
99
|
});
|
|
99
100
|
|
|
100
101
|
test("Five-digit", () => {
|
|
@@ -109,9 +110,9 @@ describe("Price/weight check digit", () => {
|
|
|
109
110
|
testFiveDigitPriceWeightCheckDigit("89012");
|
|
110
111
|
testFiveDigitPriceWeightCheckDigit("90123");
|
|
111
112
|
|
|
112
|
-
expect(() => fiveDigitPriceWeightCheckDigit("l2345")).toThrow("Invalid character 'l' at position 1");
|
|
113
|
-
expect(() => fiveDigitPriceWeightCheckDigit("1234")).toThrow("
|
|
114
|
-
expect(() => fiveDigitPriceWeightCheckDigit("123456")).toThrow("
|
|
113
|
+
expect(() => fiveDigitPriceWeightCheckDigit("l2345")).toThrow("Invalid character 'l' at position 1 of price or weight");
|
|
114
|
+
expect(() => fiveDigitPriceWeightCheckDigit("1234")).toThrow("Length 4 of string for price or weight sum must be exactly 5");
|
|
115
|
+
expect(() => fiveDigitPriceWeightCheckDigit("123456")).toThrow("Length 6 of string for price or weight sum must be exactly 5");
|
|
115
116
|
});
|
|
116
117
|
});
|
|
117
118
|
|
package/test/idkey.test.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { I18NEnvironment
|
|
1
|
+
import { I18NEnvironment } from "@aidc-toolkit/core";
|
|
2
2
|
import { CharacterSetCreator, Exclusion, NUMERIC_CREATOR, Sequencer } from "@aidc-toolkit/utility";
|
|
3
3
|
import { describe, expect, test } from "vitest";
|
|
4
4
|
import {
|
|
5
5
|
AI39_CREATOR,
|
|
6
6
|
AI82_CREATOR,
|
|
7
|
-
|
|
7
|
+
ContentCharacterSet,
|
|
8
8
|
CPID_VALIDATOR,
|
|
9
9
|
GCN_VALIDATOR,
|
|
10
10
|
GDTI_VALIDATOR,
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
type GTINValidator,
|
|
26
26
|
hasValidCheckCharacterPair,
|
|
27
27
|
hasValidCheckDigit,
|
|
28
|
+
i18nGS1Init,
|
|
28
29
|
IdentificationKeyType,
|
|
29
30
|
type IdentificationKeyValidator,
|
|
30
31
|
LeaderType,
|
|
@@ -41,21 +42,21 @@ import {
|
|
|
41
42
|
SSCC_VALIDATOR
|
|
42
43
|
} from "../src/index.js";
|
|
43
44
|
|
|
44
|
-
await
|
|
45
|
+
await i18nGS1Init(I18NEnvironment.CLI);
|
|
45
46
|
|
|
46
|
-
function creatorFor(characterSet:
|
|
47
|
+
function creatorFor(characterSet: ContentCharacterSet): CharacterSetCreator {
|
|
47
48
|
let creator: CharacterSetCreator;
|
|
48
49
|
|
|
49
50
|
switch (characterSet) {
|
|
50
|
-
case
|
|
51
|
+
case ContentCharacterSet.Numeric:
|
|
51
52
|
creator = NUMERIC_CREATOR;
|
|
52
53
|
break;
|
|
53
54
|
|
|
54
|
-
case
|
|
55
|
+
case ContentCharacterSet.AI82:
|
|
55
56
|
creator = AI82_CREATOR;
|
|
56
57
|
break;
|
|
57
58
|
|
|
58
|
-
case
|
|
59
|
+
case ContentCharacterSet.AI39:
|
|
59
60
|
creator = AI39_CREATOR;
|
|
60
61
|
break;
|
|
61
62
|
}
|
|
@@ -73,7 +74,7 @@ function validateNumericIdentificationKeyValidator(validator: NumericIdentificat
|
|
|
73
74
|
validateIdentificationKeyValidator(validator, identificationKeyType, prefixType, length);
|
|
74
75
|
|
|
75
76
|
expect(validator.leaderType).toBe(leaderType);
|
|
76
|
-
expect(validator.referenceCharacterSet).toBe(
|
|
77
|
+
expect(validator.referenceCharacterSet).toBe(ContentCharacterSet.Numeric);
|
|
77
78
|
expect(validator.referenceCreator).toBe(NUMERIC_CREATOR);
|
|
78
79
|
|
|
79
80
|
if (isCreator) {
|
|
@@ -106,11 +107,11 @@ function validateGTINValidator(validator: GTINValidator, isCreator: boolean, gti
|
|
|
106
107
|
expect(validator.gtinType).toBe(gtinType);
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
function validateNonGTINNumericIdentificationKeyValidator
|
|
110
|
+
function validateNonGTINNumericIdentificationKeyValidator(validator: NonGTINNumericIdentificationKeyValidator, isCreator: boolean, identificationKeyType: IdentificationKeyType, length: number, leaderType: LeaderType): void {
|
|
110
111
|
validateNumericIdentificationKeyValidator(validator, isCreator, identificationKeyType, PrefixType.GS1CompanyPrefix, length, leaderType);
|
|
111
112
|
}
|
|
112
113
|
|
|
113
|
-
function validateSerializableNumericIdentificationKeyValidator(validator: SerializableNumericIdentificationKeyValidator, isCreator: boolean, identificationKeyType: IdentificationKeyType, length: number, leaderType: LeaderType, serialLength: number, serialCharacterSet:
|
|
114
|
+
function validateSerializableNumericIdentificationKeyValidator(validator: SerializableNumericIdentificationKeyValidator, isCreator: boolean, identificationKeyType: IdentificationKeyType, length: number, leaderType: LeaderType, serialLength: number, serialCharacterSet: ContentCharacterSet): void {
|
|
114
115
|
validateNonGTINNumericIdentificationKeyValidator(validator, isCreator, identificationKeyType, length, leaderType);
|
|
115
116
|
|
|
116
117
|
const serialCreator = creatorFor(serialCharacterSet);
|
|
@@ -124,7 +125,7 @@ function validateSerializableNumericIdentificationKeyValidator(validator: Serial
|
|
|
124
125
|
}
|
|
125
126
|
}
|
|
126
127
|
|
|
127
|
-
function validateNonNumericIdentificationKeyValidator(validator: NonNumericIdentificationKeyValidator, isCreator: boolean, identificationKeyType: IdentificationKeyType, length: number, referenceCharacterSet:
|
|
128
|
+
function validateNonNumericIdentificationKeyValidator(validator: NonNumericIdentificationKeyValidator, isCreator: boolean, identificationKeyType: IdentificationKeyType, length: number, referenceCharacterSet: ContentCharacterSet, requiresCheckCharacterPair: boolean): void {
|
|
128
129
|
validateIdentificationKeyValidator(validator, identificationKeyType, PrefixType.GS1CompanyPrefix, length);
|
|
129
130
|
|
|
130
131
|
const referenceCreator = creatorFor(referenceCharacterSet);
|
|
@@ -151,15 +152,15 @@ describe("Validators", () => {
|
|
|
151
152
|
validateGTINValidator(GTIN8_VALIDATOR, false, GTINType.GTIN8);
|
|
152
153
|
validateNonGTINNumericIdentificationKeyValidator(GLN_VALIDATOR, false, IdentificationKeyType.GLN, 13, LeaderType.None);
|
|
153
154
|
validateNonGTINNumericIdentificationKeyValidator(SSCC_VALIDATOR, false, IdentificationKeyType.SSCC, 18, LeaderType.ExtensionDigit);
|
|
154
|
-
validateSerializableNumericIdentificationKeyValidator(GRAI_VALIDATOR, false, IdentificationKeyType.GRAI, 13, LeaderType.None, 16,
|
|
155
|
-
validateNonNumericIdentificationKeyValidator(GIAI_VALIDATOR, false, IdentificationKeyType.GIAI, 30,
|
|
155
|
+
validateSerializableNumericIdentificationKeyValidator(GRAI_VALIDATOR, false, IdentificationKeyType.GRAI, 13, LeaderType.None, 16, ContentCharacterSet.AI82);
|
|
156
|
+
validateNonNumericIdentificationKeyValidator(GIAI_VALIDATOR, false, IdentificationKeyType.GIAI, 30, ContentCharacterSet.AI82, false);
|
|
156
157
|
validateNonGTINNumericIdentificationKeyValidator(GSRN_VALIDATOR, false, IdentificationKeyType.GSRN, 18, LeaderType.None);
|
|
157
|
-
validateSerializableNumericIdentificationKeyValidator(GDTI_VALIDATOR, false, IdentificationKeyType.GDTI, 13, LeaderType.None, 17,
|
|
158
|
-
validateNonNumericIdentificationKeyValidator(GINC_VALIDATOR, false, IdentificationKeyType.GINC, 30,
|
|
158
|
+
validateSerializableNumericIdentificationKeyValidator(GDTI_VALIDATOR, false, IdentificationKeyType.GDTI, 13, LeaderType.None, 17, ContentCharacterSet.AI82);
|
|
159
|
+
validateNonNumericIdentificationKeyValidator(GINC_VALIDATOR, false, IdentificationKeyType.GINC, 30, ContentCharacterSet.AI82, false);
|
|
159
160
|
validateNonGTINNumericIdentificationKeyValidator(GSIN_VALIDATOR, false, IdentificationKeyType.GSIN, 17, LeaderType.None);
|
|
160
|
-
validateSerializableNumericIdentificationKeyValidator(GCN_VALIDATOR, false, IdentificationKeyType.GCN, 13, LeaderType.None, 12,
|
|
161
|
-
validateNonNumericIdentificationKeyValidator(CPID_VALIDATOR, false, IdentificationKeyType.CPID, 30,
|
|
162
|
-
validateNonNumericIdentificationKeyValidator(GMN_VALIDATOR, false, IdentificationKeyType.GMN, 25,
|
|
161
|
+
validateSerializableNumericIdentificationKeyValidator(GCN_VALIDATOR, false, IdentificationKeyType.GCN, 13, LeaderType.None, 12, ContentCharacterSet.Numeric);
|
|
162
|
+
validateNonNumericIdentificationKeyValidator(CPID_VALIDATOR, false, IdentificationKeyType.CPID, 30, ContentCharacterSet.AI39, false);
|
|
163
|
+
validateNonNumericIdentificationKeyValidator(GMN_VALIDATOR, false, IdentificationKeyType.GMN, 25, ContentCharacterSet.AI82, true);
|
|
163
164
|
});
|
|
164
165
|
});
|
|
165
166
|
|
|
@@ -202,15 +203,15 @@ function validateIdentificationKeyCreators(prefixManager: PrefixManager): void {
|
|
|
202
203
|
|
|
203
204
|
validateNonGTINNumericIdentificationKeyValidator(prefixManager.glnCreator, true, IdentificationKeyType.GLN, 13, LeaderType.None);
|
|
204
205
|
validateNonGTINNumericIdentificationKeyValidator(prefixManager.ssccCreator, true, IdentificationKeyType.SSCC, 18, LeaderType.ExtensionDigit);
|
|
205
|
-
validateSerializableNumericIdentificationKeyValidator(prefixManager.graiCreator, true, IdentificationKeyType.GRAI, 13, LeaderType.None, 16,
|
|
206
|
-
validateNonNumericIdentificationKeyValidator(prefixManager.giaiCreator, true, IdentificationKeyType.GIAI, 30,
|
|
206
|
+
validateSerializableNumericIdentificationKeyValidator(prefixManager.graiCreator, true, IdentificationKeyType.GRAI, 13, LeaderType.None, 16, ContentCharacterSet.AI82);
|
|
207
|
+
validateNonNumericIdentificationKeyValidator(prefixManager.giaiCreator, true, IdentificationKeyType.GIAI, 30, ContentCharacterSet.AI82, false);
|
|
207
208
|
validateNonGTINNumericIdentificationKeyValidator(prefixManager.gsrnCreator, true, IdentificationKeyType.GSRN, 18, LeaderType.None);
|
|
208
|
-
validateSerializableNumericIdentificationKeyValidator(prefixManager.gdtiCreator, true, IdentificationKeyType.GDTI, 13, LeaderType.None, 17,
|
|
209
|
-
validateNonNumericIdentificationKeyValidator(prefixManager.gincCreator, true, IdentificationKeyType.GINC, 30,
|
|
209
|
+
validateSerializableNumericIdentificationKeyValidator(prefixManager.gdtiCreator, true, IdentificationKeyType.GDTI, 13, LeaderType.None, 17, ContentCharacterSet.AI82);
|
|
210
|
+
validateNonNumericIdentificationKeyValidator(prefixManager.gincCreator, true, IdentificationKeyType.GINC, 30, ContentCharacterSet.AI82, false);
|
|
210
211
|
validateNonGTINNumericIdentificationKeyValidator(prefixManager.gsinCreator, true, IdentificationKeyType.GSIN, 17, LeaderType.None);
|
|
211
|
-
validateSerializableNumericIdentificationKeyValidator(prefixManager.gcnCreator, true, IdentificationKeyType.GCN, 13, LeaderType.None, 12,
|
|
212
|
-
validateNonNumericIdentificationKeyValidator(prefixManager.cpidCreator, true, IdentificationKeyType.CPID, 30,
|
|
213
|
-
validateNonNumericIdentificationKeyValidator(prefixManager.gmnCreator, true, IdentificationKeyType.GMN, 25,
|
|
212
|
+
validateSerializableNumericIdentificationKeyValidator(prefixManager.gcnCreator, true, IdentificationKeyType.GCN, 13, LeaderType.None, 12, ContentCharacterSet.Numeric);
|
|
213
|
+
validateNonNumericIdentificationKeyValidator(prefixManager.cpidCreator, true, IdentificationKeyType.CPID, 30, ContentCharacterSet.AI39, false);
|
|
214
|
+
validateNonNumericIdentificationKeyValidator(prefixManager.gmnCreator, true, IdentificationKeyType.GMN, 25, ContentCharacterSet.AI82, true);
|
|
214
215
|
} else {
|
|
215
216
|
expect(() => prefixManager.glnCreator).toThrow("GLN not supported by GS1-8 Prefix");
|
|
216
217
|
expect(() => prefixManager.ssccCreator).toThrow("SSCC not supported by GS1-8 Prefix");
|
|
@@ -902,15 +903,15 @@ function testSerializableNumericIdentificationKeyCreator(creator: SerializableNu
|
|
|
902
903
|
let invalidSerial: string;
|
|
903
904
|
|
|
904
905
|
switch (creator.serialComponentCharacterSet) {
|
|
905
|
-
case
|
|
906
|
+
case ContentCharacterSet.Numeric:
|
|
906
907
|
invalidSerial = "1234A5678";
|
|
907
908
|
break;
|
|
908
909
|
|
|
909
|
-
case
|
|
910
|
+
case ContentCharacterSet.AI82:
|
|
910
911
|
invalidSerial = "ABCD~1234";
|
|
911
912
|
break;
|
|
912
913
|
|
|
913
|
-
case
|
|
914
|
+
case ContentCharacterSet.AI39:
|
|
914
915
|
invalidSerial = "ABCD%1234";
|
|
915
916
|
break;
|
|
916
917
|
}
|
|
@@ -927,7 +928,7 @@ function testSerializableNumericIdentificationKeyCreator(creator: SerializableNu
|
|
|
927
928
|
|
|
928
929
|
const TEST_REFERENCE_LENGTH = 2;
|
|
929
930
|
|
|
930
|
-
function testNonNumericIdentificationKeyCreator
|
|
931
|
+
function testNonNumericIdentificationKeyCreator(creator: NonNumericIdentificationKeyCreator): void {
|
|
931
932
|
describe(creator.identificationKeyType, () => {
|
|
932
933
|
const prefix = creator.prefix;
|
|
933
934
|
const prefixLength = prefix.length;
|
|
File without changes
|