@aidc-toolkit/gs1 0.9.7-beta → 0.9.9-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/LICENSE +0 -27
- package/README.md +14 -0
- package/dist/index.cjs +143 -131
- package/dist/index.d.cts +145 -6
- package/dist/index.d.ts +145 -6
- package/dist/index.js +104 -105
- package/package.json +9 -8
- package/src/check.ts +24 -9
- package/src/idkey.ts +53 -99
- package/src/index.ts +18 -2
- 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 +40 -6
- package/src/locale/i18next.d.ts +5 -3
- package/test/check.test.ts +9 -8
- package/test/idkey.test.ts +17 -16
- /package/src/{character_set.ts → character-set.ts} +0 -0
package/test/idkey.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I18NEnvironment
|
|
2
|
-
import { CharacterSetCreator, Exclusion, NUMERIC_CREATOR,
|
|
1
|
+
import { I18NEnvironment } from "@aidc-toolkit/core";
|
|
2
|
+
import { CharacterSetCreator, Exclusion, NUMERIC_CREATOR, Sequence } from "@aidc-toolkit/utility";
|
|
3
3
|
import { describe, expect, test } from "vitest";
|
|
4
4
|
import {
|
|
5
5
|
AI39_CREATOR,
|
|
@@ -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,7 +42,7 @@ import {
|
|
|
41
42
|
SSCC_VALIDATOR
|
|
42
43
|
} from "../src/index.js";
|
|
43
44
|
|
|
44
|
-
await
|
|
45
|
+
await i18nGS1Init(I18NEnvironment.CLI);
|
|
45
46
|
|
|
46
47
|
function creatorFor(characterSet: ContentCharacterSet): CharacterSetCreator {
|
|
47
48
|
let creator: CharacterSetCreator;
|
|
@@ -106,7 +107,7 @@ 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
|
|
|
@@ -378,8 +379,8 @@ describe("Sparse creation", () => {
|
|
|
378
379
|
|
|
379
380
|
prefixManager.tweakFactor = 0;
|
|
380
381
|
|
|
381
|
-
const sparseGTINs = Array.from(prefixManager.gtinCreator.create(new
|
|
382
|
-
const straightGTINs = Array.from(prefixManager.gtinCreator.create(new
|
|
382
|
+
const sparseGTINs = Array.from(prefixManager.gtinCreator.create(new Sequence(0, 10), true));
|
|
383
|
+
const straightGTINs = Array.from(prefixManager.gtinCreator.create(new Sequence(0, 10)));
|
|
383
384
|
|
|
384
385
|
test("Tweak factor 0", () => {
|
|
385
386
|
expect(sparseGTINs).toStrictEqual(straightGTINs);
|
|
@@ -423,7 +424,7 @@ function testNumericIdentificationKeyCreator(creator: NumericIdentificationKeyCr
|
|
|
423
424
|
expect(creator.referenceLength).toBe(referenceLength);
|
|
424
425
|
expect(creator.capacity).toBe(Number(CharacterSetCreator.powerOf10(referenceLength)));
|
|
425
426
|
|
|
426
|
-
const sequenceIterator = Iterator.from(creator.create(new
|
|
427
|
+
const sequenceIterator = Iterator.from(creator.create(new Sequence(0, referenceCount)));
|
|
427
428
|
|
|
428
429
|
let allCount = 0;
|
|
429
430
|
|
|
@@ -462,10 +463,10 @@ function testNumericIdentificationKeyCreator(creator: NumericIdentificationKeyCr
|
|
|
462
463
|
|
|
463
464
|
let sequenceCount = 0;
|
|
464
465
|
|
|
465
|
-
Iterator.from(creator.create(new
|
|
466
|
+
Iterator.from(creator.create(new Sequence(0, sparseReferenceCount), true)).forEach((identificationKey, index) => {
|
|
466
467
|
validate(identificationKey, index, true);
|
|
467
468
|
|
|
468
|
-
sequential
|
|
469
|
+
sequential &&= Number((hasExtensionDigit ? identificationKey.charAt(0) : "") + identificationKey.substring(referenceSubstringStart, referenceSubstringEnd)) === index;
|
|
469
470
|
|
|
470
471
|
expect(sequenceSet.has(identificationKey)).toBe(false);
|
|
471
472
|
sequenceSet.add(identificationKey);
|
|
@@ -563,7 +564,7 @@ function testGTINCreator(creator: GTINCreator): void {
|
|
|
563
564
|
test("GTIN-14 straight", () => {
|
|
564
565
|
let sequenceCount = 0;
|
|
565
566
|
|
|
566
|
-
Iterator.from(creator.createGTIN14("5", new
|
|
567
|
+
Iterator.from(creator.createGTIN14("5", new Sequence(0, referenceCount))).forEach((gtin, index) => {
|
|
567
568
|
expect(Number(gtin.substring(referenceSubstringStart, referenceSubstringEnd))).toBe(index);
|
|
568
569
|
|
|
569
570
|
validate(gtin, index, false);
|
|
@@ -596,8 +597,8 @@ function testGTINCreator(creator: GTINCreator): void {
|
|
|
596
597
|
|
|
597
598
|
let sequenceCount = 0;
|
|
598
599
|
|
|
599
|
-
Iterator.from(creator.createGTIN14("5", new
|
|
600
|
-
sequential
|
|
600
|
+
Iterator.from(creator.createGTIN14("5", new Sequence(0, sparseReferenceCount), true)).forEach((gtin, index) => {
|
|
601
|
+
sequential &&= Number(gtin.substring(referenceSubstringStart, referenceSubstringEnd)) === index;
|
|
601
602
|
|
|
602
603
|
validate(gtin, index, true);
|
|
603
604
|
|
|
@@ -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;
|
|
@@ -941,7 +942,7 @@ function testNonNumericIdentificationKeyCreator<T extends NonNumericIdentificati
|
|
|
941
942
|
|
|
942
943
|
let sequenceCount = 0;
|
|
943
944
|
|
|
944
|
-
Iterator.from(creator.create(creator.referenceCreator.create(TEST_REFERENCE_LENGTH, new
|
|
945
|
+
Iterator.from(creator.create(creator.referenceCreator.create(TEST_REFERENCE_LENGTH, new Sequence(0, referenceCount)))).forEach((identificationKey, index) => {
|
|
945
946
|
expect(() => {
|
|
946
947
|
creator.validate(identificationKey);
|
|
947
948
|
}).not.toThrow(RangeError);
|
|
@@ -965,14 +966,14 @@ function testNonNumericIdentificationKeyCreator<T extends NonNumericIdentificati
|
|
|
965
966
|
|
|
966
967
|
let sequenceCount = 0;
|
|
967
968
|
|
|
968
|
-
Iterator.from(creator.create(creator.referenceCreator.create(TEST_REFERENCE_LENGTH, new
|
|
969
|
+
Iterator.from(creator.create(creator.referenceCreator.create(TEST_REFERENCE_LENGTH, new Sequence(0, referenceCount), Exclusion.None, 123456n))).forEach((identificationKey, index) => {
|
|
969
970
|
expect(() => {
|
|
970
971
|
creator.validate(identificationKey);
|
|
971
972
|
}).not.toThrow(RangeError);
|
|
972
973
|
|
|
973
974
|
expect(Number(creator.referenceCreator.valueFor(identificationKey.substring(referenceSubstringStart, referenceSubstringEnd), Exclusion.None, 123456n))).toBe(index);
|
|
974
975
|
|
|
975
|
-
sequential
|
|
976
|
+
sequential &&= Number(creator.referenceCreator.valueFor(identificationKey.substring(referenceSubstringStart, referenceSubstringEnd))) === index;
|
|
976
977
|
|
|
977
978
|
expect(identificationKey.length).toBeLessThanOrEqual(creator.length);
|
|
978
979
|
expect(identificationKey.substring(0, prefixLength)).toBe(prefix);
|
|
File without changes
|