@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.
@@ -1,5 +1,5 @@
1
- import { I18NEnvironment, i18nInit } from "@aidc-toolkit/core";
2
- import { CharacterSetCreator, Exclusion, NUMERIC_CREATOR, Sequencer } from "@aidc-toolkit/utility";
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 i18nInit(I18NEnvironment.CLI);
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<T extends NonGTINNumericIdentificationKeyValidator>(validator: T, isCreator: boolean, identificationKeyType: IdentificationKeyType, length: number, leaderType: LeaderType): void {
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 Sequencer(0, 10), true));
382
- const straightGTINs = Array.from(prefixManager.gtinCreator.create(new Sequencer(0, 10)));
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 Sequencer(0, referenceCount)));
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 Sequencer(0, sparseReferenceCount), true)).forEach((identificationKey, index) => {
466
+ Iterator.from(creator.create(new Sequence(0, sparseReferenceCount), true)).forEach((identificationKey, index) => {
466
467
  validate(identificationKey, index, true);
467
468
 
468
- sequential = sequential && Number((hasExtensionDigit ? identificationKey.charAt(0) : "") + identificationKey.substring(referenceSubstringStart, referenceSubstringEnd)) === index;
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 Sequencer(0, referenceCount))).forEach((gtin, index) => {
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 Sequencer(0, sparseReferenceCount), true)).forEach((gtin, index) => {
600
- sequential = sequential && Number(gtin.substring(referenceSubstringStart, referenceSubstringEnd)) === index;
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<T extends NonNumericIdentificationKeyCreator>(creator: T): void {
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 Sequencer(0, referenceCount)))).forEach((identificationKey, index) => {
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 Sequencer(0, referenceCount), Exclusion.None, 123456n))).forEach((identificationKey, index) => {
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 = sequential && Number(creator.referenceCreator.valueFor(identificationKey.substring(referenceSubstringStart, referenceSubstringEnd))) === index;
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