@aidc-toolkit/gs1 0.9.8-beta → 0.9.10-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 +31 -2203
- package/dist/index.d.cts +2 -503
- package/dist/index.d.ts +2 -503
- package/dist/index.js +18 -2200
- package/package.json +8 -9
- package/src/idkey.ts +4 -1
- package/src/index.ts +16 -0
- package/src/locale/i18n.ts +3 -2
- package/test/idkey.test.ts +12 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aidc-toolkit/gs1",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.10-beta",
|
|
4
4
|
"description": "GS1 AIDC Toolkit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,23 +20,22 @@
|
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"lint": "eslint .",
|
|
23
|
-
"build": "tsup src/index.ts --clean --format cjs,esm --dts",
|
|
24
|
-
"build-doc": "npm run build && tsc src/index.ts --outDir dist --target esnext --moduleResolution nodenext --module nodenext --emitDeclarationOnly --declaration --declarationMap",
|
|
23
|
+
"build-dist": "tsup src/index.ts --clean --format cjs,esm --dts",
|
|
24
|
+
"build-doc": "npm run build-dist && tsc src/index.ts --outDir dist --target esnext --moduleResolution nodenext --module nodenext --emitDeclarationOnly --declaration --declarationMap",
|
|
25
25
|
"test": "vitest run"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@aidc-toolkit/dev": "^0.9.
|
|
29
|
-
"eslint": "^9.
|
|
30
|
-
"i18next": "^24.1.0",
|
|
28
|
+
"@aidc-toolkit/dev": "^0.9.10-beta",
|
|
29
|
+
"eslint": "^9.17.0",
|
|
31
30
|
"ts-node": "^10.9.2",
|
|
32
31
|
"tsup": "^8.3.5",
|
|
33
32
|
"typescript": "^5.7.2",
|
|
34
33
|
"vitest": "^2.1.8"
|
|
35
34
|
},
|
|
36
35
|
"dependencies": {
|
|
37
|
-
"@aidc-toolkit/core": "^0.9.
|
|
38
|
-
"@aidc-toolkit/utility": "^0.9.
|
|
39
|
-
"
|
|
36
|
+
"@aidc-toolkit/core": "^0.9.10-beta",
|
|
37
|
+
"@aidc-toolkit/utility": "^0.9.10-beta",
|
|
38
|
+
"i18next": "^24.2.1",
|
|
40
39
|
"ts-mixer": "^6.0.4"
|
|
41
40
|
}
|
|
42
41
|
}
|
package/src/idkey.ts
CHANGED
|
@@ -1054,7 +1054,7 @@ export interface NumericIdentificationKeyCreator extends NumericIdentificationKe
|
|
|
1054
1054
|
* Create all identification keys for the prefix from `0` to `capacity - 1`.
|
|
1055
1055
|
*
|
|
1056
1056
|
* The implementation creates the strings only as needed using an internal generator function. Although the result
|
|
1057
|
-
* is equivalent to calling `creator.create(new
|
|
1057
|
+
* is equivalent to calling `creator.create(new Sequence(0, creator.capacity))`, this method is significantly
|
|
1058
1058
|
* faster.
|
|
1059
1059
|
*
|
|
1060
1060
|
* @returns
|
|
@@ -1524,6 +1524,7 @@ export class SerializableNumericIdentificationKeyCreator extends Mixin(Serializa
|
|
|
1524
1524
|
result = transformIterable(serialComponentOrComponents, validateAndConcatenate);
|
|
1525
1525
|
}
|
|
1526
1526
|
|
|
1527
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type determination is handled above.
|
|
1527
1528
|
return result as TransformerOutput<T, string>;
|
|
1528
1529
|
}
|
|
1529
1530
|
|
|
@@ -1655,6 +1656,7 @@ export class NonNumericIdentificationKeyCreator extends Mixin(NonNumericIdentifi
|
|
|
1655
1656
|
result = transformIterable(referenceOrReferences, validateAndCreate);
|
|
1656
1657
|
}
|
|
1657
1658
|
|
|
1659
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type determination is handled above.
|
|
1658
1660
|
return result as TransformerOutput<T, string>;
|
|
1659
1661
|
}
|
|
1660
1662
|
}
|
|
@@ -2075,6 +2077,7 @@ export class PrefixManager {
|
|
|
2075
2077
|
* Identification key creator.
|
|
2076
2078
|
*/
|
|
2077
2079
|
private getIdentificationKeyCreator<T extends IdentificationKeyCreator>(identificationKeyType: IdentificationKeyType, constructorCallback: () => T): T {
|
|
2080
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type is paired with constructor callback.
|
|
2078
2081
|
let creator = this._identificationKeyCreatorsMap.get(identificationKeyType) as (T | undefined);
|
|
2079
2082
|
|
|
2080
2083
|
if (creator === undefined) {
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright © 2024-2025 Dolphin Data Development Ltd. and AIDC Toolkit
|
|
3
|
+
* contributors
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
1
17
|
export * from "./locale/i18n.js";
|
|
2
18
|
export * from "./character-set.js";
|
|
3
19
|
export * from "./check.js";
|
package/src/locale/i18n.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i18nAssertValidResources, i18nCoreInit, type I18NEnvironment } from "@aidc-toolkit/core";
|
|
2
2
|
import { i18nUtilityInit, utilityResources } from "@aidc-toolkit/utility";
|
|
3
|
-
import i18next from "i18next";
|
|
3
|
+
import i18next, { type i18n } from "i18next";
|
|
4
4
|
import { localeStrings as enLocaleStrings } from "./en/locale-strings.js";
|
|
5
5
|
import { localeStrings as frLocaleStrings } from "./fr/locale-strings.js";
|
|
6
6
|
|
|
@@ -25,7 +25,8 @@ export const gs1Resources = {
|
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
// Explicit type is necessary to work around bug in type discovery with linked packages.
|
|
29
|
+
export const i18nextGS1: i18n = i18next.createInstance();
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
32
|
* Initialize internationalization.
|
package/test/idkey.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { I18NEnvironment } from "@aidc-toolkit/core";
|
|
2
|
-
import { CharacterSetCreator, Exclusion, NUMERIC_CREATOR,
|
|
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,
|
|
@@ -379,8 +379,8 @@ describe("Sparse creation", () => {
|
|
|
379
379
|
|
|
380
380
|
prefixManager.tweakFactor = 0;
|
|
381
381
|
|
|
382
|
-
const sparseGTINs = Array.from(prefixManager.gtinCreator.create(new
|
|
383
|
-
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)));
|
|
384
384
|
|
|
385
385
|
test("Tweak factor 0", () => {
|
|
386
386
|
expect(sparseGTINs).toStrictEqual(straightGTINs);
|
|
@@ -424,7 +424,7 @@ function testNumericIdentificationKeyCreator(creator: NumericIdentificationKeyCr
|
|
|
424
424
|
expect(creator.referenceLength).toBe(referenceLength);
|
|
425
425
|
expect(creator.capacity).toBe(Number(CharacterSetCreator.powerOf10(referenceLength)));
|
|
426
426
|
|
|
427
|
-
const sequenceIterator = Iterator.from(creator.create(new
|
|
427
|
+
const sequenceIterator = Iterator.from(creator.create(new Sequence(0, referenceCount)));
|
|
428
428
|
|
|
429
429
|
let allCount = 0;
|
|
430
430
|
|
|
@@ -463,10 +463,10 @@ function testNumericIdentificationKeyCreator(creator: NumericIdentificationKeyCr
|
|
|
463
463
|
|
|
464
464
|
let sequenceCount = 0;
|
|
465
465
|
|
|
466
|
-
Iterator.from(creator.create(new
|
|
466
|
+
Iterator.from(creator.create(new Sequence(0, sparseReferenceCount), true)).forEach((identificationKey, index) => {
|
|
467
467
|
validate(identificationKey, index, true);
|
|
468
468
|
|
|
469
|
-
sequential
|
|
469
|
+
sequential &&= Number((hasExtensionDigit ? identificationKey.charAt(0) : "") + identificationKey.substring(referenceSubstringStart, referenceSubstringEnd)) === index;
|
|
470
470
|
|
|
471
471
|
expect(sequenceSet.has(identificationKey)).toBe(false);
|
|
472
472
|
sequenceSet.add(identificationKey);
|
|
@@ -564,7 +564,7 @@ function testGTINCreator(creator: GTINCreator): void {
|
|
|
564
564
|
test("GTIN-14 straight", () => {
|
|
565
565
|
let sequenceCount = 0;
|
|
566
566
|
|
|
567
|
-
Iterator.from(creator.createGTIN14("5", new
|
|
567
|
+
Iterator.from(creator.createGTIN14("5", new Sequence(0, referenceCount))).forEach((gtin, index) => {
|
|
568
568
|
expect(Number(gtin.substring(referenceSubstringStart, referenceSubstringEnd))).toBe(index);
|
|
569
569
|
|
|
570
570
|
validate(gtin, index, false);
|
|
@@ -597,8 +597,8 @@ function testGTINCreator(creator: GTINCreator): void {
|
|
|
597
597
|
|
|
598
598
|
let sequenceCount = 0;
|
|
599
599
|
|
|
600
|
-
Iterator.from(creator.createGTIN14("5", new
|
|
601
|
-
sequential
|
|
600
|
+
Iterator.from(creator.createGTIN14("5", new Sequence(0, sparseReferenceCount), true)).forEach((gtin, index) => {
|
|
601
|
+
sequential &&= Number(gtin.substring(referenceSubstringStart, referenceSubstringEnd)) === index;
|
|
602
602
|
|
|
603
603
|
validate(gtin, index, true);
|
|
604
604
|
|
|
@@ -942,7 +942,7 @@ function testNonNumericIdentificationKeyCreator(creator: NonNumericIdentificatio
|
|
|
942
942
|
|
|
943
943
|
let sequenceCount = 0;
|
|
944
944
|
|
|
945
|
-
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) => {
|
|
946
946
|
expect(() => {
|
|
947
947
|
creator.validate(identificationKey);
|
|
948
948
|
}).not.toThrow(RangeError);
|
|
@@ -966,14 +966,14 @@ function testNonNumericIdentificationKeyCreator(creator: NonNumericIdentificatio
|
|
|
966
966
|
|
|
967
967
|
let sequenceCount = 0;
|
|
968
968
|
|
|
969
|
-
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) => {
|
|
970
970
|
expect(() => {
|
|
971
971
|
creator.validate(identificationKey);
|
|
972
972
|
}).not.toThrow(RangeError);
|
|
973
973
|
|
|
974
974
|
expect(Number(creator.referenceCreator.valueFor(identificationKey.substring(referenceSubstringStart, referenceSubstringEnd), Exclusion.None, 123456n))).toBe(index);
|
|
975
975
|
|
|
976
|
-
sequential
|
|
976
|
+
sequential &&= Number(creator.referenceCreator.valueFor(identificationKey.substring(referenceSubstringStart, referenceSubstringEnd))) === index;
|
|
977
977
|
|
|
978
978
|
expect(identificationKey.length).toBeLessThanOrEqual(creator.length);
|
|
979
979
|
expect(identificationKey.substring(0, prefixLength)).toBe(prefix);
|