@aidc-toolkit/gs1 0.9.18-beta → 0.9.20-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/README.md +41 -14
- package/dist/check.d.ts +8 -5
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +13 -11
- package/dist/check.js.map +1 -1
- package/dist/idkey.d.ts +64 -1
- package/dist/idkey.d.ts.map +1 -1
- package/dist/idkey.js +206 -6
- package/dist/idkey.js.map +1 -1
- package/dist/locale/en/locale-strings.d.ts +4 -0
- package/dist/locale/en/locale-strings.d.ts.map +1 -1
- package/dist/locale/en/locale-strings.js +4 -0
- package/dist/locale/en/locale-strings.js.map +1 -1
- package/dist/locale/fr/locale-strings.d.ts +4 -0
- package/dist/locale/fr/locale-strings.d.ts.map +1 -1
- package/dist/locale/fr/locale-strings.js +4 -0
- package/dist/locale/fr/locale-strings.js.map +1 -1
- package/dist/locale/i18n.d.ts +4 -83
- package/dist/locale/i18n.d.ts.map +1 -1
- package/dist/locale/i18n.js.map +1 -1
- package/package.json +6 -6
- package/src/check.ts +13 -12
- package/src/idkey.ts +269 -9
- package/src/locale/en/locale-strings.ts +4 -0
- package/src/locale/fr/locale-strings.ts +4 -0
- package/src/locale/i18n.ts +4 -4
- package/test/check.test.ts +17 -12
- package/test/idkey.test.ts +201 -3
package/test/idkey.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { I18nEnvironment } from "@aidc-toolkit/core";
|
|
2
2
|
import { CharacterSetCreator, Exclusion, NUMERIC_CREATOR, Sequence } from "@aidc-toolkit/utility";
|
|
3
3
|
import { describe, expect, test } from "vitest";
|
|
4
4
|
import {
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
GTIN13_VALIDATOR,
|
|
20
20
|
GTIN8_VALIDATOR,
|
|
21
21
|
GTIN_VALIDATORS,
|
|
22
|
-
|
|
22
|
+
GTINCreator,
|
|
23
23
|
GTINLevel,
|
|
24
24
|
GTINType,
|
|
25
25
|
GTINValidator,
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
i18nGS1Init,
|
|
29
29
|
IdentificationKeyType,
|
|
30
30
|
type IdentificationKeyValidator,
|
|
31
|
+
isValidPriceOrWeightCheckDigit,
|
|
31
32
|
LeaderType,
|
|
32
33
|
type NonGTINNumericIdentificationKeyCreator,
|
|
33
34
|
type NonGTINNumericIdentificationKeyValidator,
|
|
@@ -37,12 +38,13 @@ import {
|
|
|
37
38
|
type NumericIdentificationKeyValidator,
|
|
38
39
|
PrefixManager,
|
|
39
40
|
PrefixType,
|
|
41
|
+
type RCNReference,
|
|
40
42
|
type SerializableNumericIdentificationKeyCreator,
|
|
41
43
|
type SerializableNumericIdentificationKeyValidator,
|
|
42
44
|
SSCC_VALIDATOR
|
|
43
45
|
} from "../src";
|
|
44
46
|
|
|
45
|
-
await i18nGS1Init(
|
|
47
|
+
await i18nGS1Init(I18nEnvironment.CLI);
|
|
46
48
|
|
|
47
49
|
function creatorFor(characterSet: ContentCharacterSet): CharacterSetCreator {
|
|
48
50
|
let creator: CharacterSetCreator;
|
|
@@ -872,6 +874,201 @@ function testGTINValidationAndNormalization(): void {
|
|
|
872
874
|
});
|
|
873
875
|
}
|
|
874
876
|
|
|
877
|
+
function testVariableMeasureRCN(): void {
|
|
878
|
+
describe("Variable measure RCN", () => {
|
|
879
|
+
test("RCN-12", () => {
|
|
880
|
+
const rcn1 = GTINCreator.createVariableMeasureRCN("2IIIIIVPPPPC", 12345, 4321);
|
|
881
|
+
|
|
882
|
+
expect(rcn1.length).toBe(12);
|
|
883
|
+
expect(rcn1.charAt(0)).toBe("2");
|
|
884
|
+
expect(rcn1.substring(1, 6)).toBe("12345");
|
|
885
|
+
expect(rcn1.substring(7, 11)).toBe("4321");
|
|
886
|
+
expect(isValidPriceOrWeightCheckDigit(rcn1.substring(7, 11), rcn1.charAt(6))).toBe(true);
|
|
887
|
+
expect(hasValidCheckDigit(rcn1)).toBe(true);
|
|
888
|
+
expect(() => {
|
|
889
|
+
GTINValidator.parseVariableMeasureRCN("2IIIIIVPPPPC", rcn1);
|
|
890
|
+
}).not.toThrow(RangeError);
|
|
891
|
+
expect(GTINValidator.parseVariableMeasureRCN("2IIIIIVPPPPC", rcn1)).toEqual({
|
|
892
|
+
itemReference: 12345,
|
|
893
|
+
priceOrWeight: 4321
|
|
894
|
+
} satisfies RCNReference);
|
|
895
|
+
|
|
896
|
+
const rcn2 = GTINCreator.createVariableMeasureRCN("2IIIIPPPPPVC", 1234, 54321);
|
|
897
|
+
|
|
898
|
+
expect(rcn2.length).toBe(12);
|
|
899
|
+
expect(rcn2.charAt(0)).toBe("2");
|
|
900
|
+
expect(rcn2.substring(1, 5)).toBe("1234");
|
|
901
|
+
expect(rcn2.substring(5, 10)).toBe("54321");
|
|
902
|
+
expect(isValidPriceOrWeightCheckDigit(rcn2.substring(5, 10), rcn2.charAt(10))).toBe(true);
|
|
903
|
+
expect(hasValidCheckDigit(rcn2)).toBe(true);
|
|
904
|
+
expect(() => {
|
|
905
|
+
GTINValidator.parseVariableMeasureRCN("2IIIIPPPPPVC", rcn2);
|
|
906
|
+
}).not.toThrow(RangeError);
|
|
907
|
+
expect(GTINValidator.parseVariableMeasureRCN("2IIIIPPPPPVC", rcn2)).toEqual({
|
|
908
|
+
itemReference: 1234,
|
|
909
|
+
priceOrWeight: 54321
|
|
910
|
+
} satisfies RCNReference);
|
|
911
|
+
|
|
912
|
+
const rcn3 = GTINCreator.createVariableMeasureRCN("2PPPPPIIIIIC", 12345, 54321);
|
|
913
|
+
|
|
914
|
+
expect(rcn3.length).toBe(12);
|
|
915
|
+
expect(rcn3.charAt(0)).toBe("2");
|
|
916
|
+
expect(rcn3.substring(1, 6)).toBe("54321");
|
|
917
|
+
expect(rcn3.substring(6, 11)).toBe("12345");
|
|
918
|
+
expect(hasValidCheckDigit(rcn3)).toBe(true);
|
|
919
|
+
expect(() => {
|
|
920
|
+
GTINValidator.parseVariableMeasureRCN("2PPPPPIIIIIC", rcn3);
|
|
921
|
+
}).not.toThrow(RangeError);
|
|
922
|
+
expect(GTINValidator.parseVariableMeasureRCN("2PPPPPIIIIIC", rcn3)).toEqual({
|
|
923
|
+
itemReference: 12345,
|
|
924
|
+
priceOrWeight: 54321
|
|
925
|
+
} satisfies RCNReference);
|
|
926
|
+
|
|
927
|
+
expect(() => GTINCreator.createVariableMeasureRCN("3PPPPPIIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
928
|
+
expect(() => GTINCreator.createVariableMeasureRCN("20PPPPPIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
929
|
+
expect(() => GTINCreator.createVariableMeasureRCN("2PPPPPIIIIII", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
930
|
+
expect(() => GTINCreator.createVariableMeasureRCN("2PPPPPIIIIKC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
931
|
+
expect(() => GTINCreator.createVariableMeasureRCN("2PPPPPIIPIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
932
|
+
expect(() => GTINCreator.createVariableMeasureRCN("2PPIPPIIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
933
|
+
expect(() => GTINCreator.createVariableMeasureRCN("2PPPPPIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
934
|
+
expect(() => GTINCreator.createVariableMeasureRCN("2PPPPPIIIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
935
|
+
expect(() => GTINCreator.createVariableMeasureRCN("2PPPPPPPPPPC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
936
|
+
expect(() => GTINCreator.createVariableMeasureRCN("2IIIIIIIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
937
|
+
|
|
938
|
+
expect(() => {
|
|
939
|
+
GTINCreator.parseVariableMeasureRCN("3PPPPPIIIIIC", "2543211234540");
|
|
940
|
+
}).toThrow("RCN length must match format length");
|
|
941
|
+
expect(() => {
|
|
942
|
+
GTINCreator.parseVariableMeasureRCN("3PPPPPIIIIIC", "25432112345");
|
|
943
|
+
}).toThrow("RCN length must match format length");
|
|
944
|
+
expect(() => {
|
|
945
|
+
GTINCreator.parseVariableMeasureRCN("3PPPPPIIIIIC", "254321123454");
|
|
946
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
947
|
+
expect(() => {
|
|
948
|
+
GTINCreator.parseVariableMeasureRCN("20PPPPPIIIIC", "254321123454");
|
|
949
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
950
|
+
expect(() => {
|
|
951
|
+
GTINCreator.parseVariableMeasureRCN("2PPPPPIIIIII", "254321123454");
|
|
952
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
953
|
+
expect(() => {
|
|
954
|
+
GTINCreator.parseVariableMeasureRCN("2PPPPPIIIIKC", "254321123454");
|
|
955
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
956
|
+
expect(() => {
|
|
957
|
+
GTINCreator.parseVariableMeasureRCN("2PPPPPIIPIIC", "254321123454");
|
|
958
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
959
|
+
expect(() => {
|
|
960
|
+
GTINCreator.parseVariableMeasureRCN("2PPIPPIIIIIC", "254321123454");
|
|
961
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
962
|
+
expect(() => {
|
|
963
|
+
GTINCreator.parseVariableMeasureRCN("2PPPPPIIIIC", "25432112345");
|
|
964
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
965
|
+
expect(() => {
|
|
966
|
+
GTINCreator.parseVariableMeasureRCN("2PPPPPIIIIIIC", "2543211234540");
|
|
967
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
968
|
+
expect(() => {
|
|
969
|
+
GTINCreator.parseVariableMeasureRCN("2PPPPPPPPPPC", "254321123454");
|
|
970
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
971
|
+
expect(() => {
|
|
972
|
+
GTINCreator.parseVariableMeasureRCN("2IIIIIIIIIIC", "254321123454");
|
|
973
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
974
|
+
});
|
|
975
|
+
|
|
976
|
+
test("RCN-13", () => {
|
|
977
|
+
const rcn1 = GTINCreator.createVariableMeasureRCN("24IIIIIVPPPPC", 12345, 4321);
|
|
978
|
+
|
|
979
|
+
expect(rcn1.length).toBe(13);
|
|
980
|
+
expect(rcn1.substring(0, 2)).toBe("24");
|
|
981
|
+
expect(rcn1.substring(2, 7)).toBe("12345");
|
|
982
|
+
expect(rcn1.substring(8, 12)).toBe("4321");
|
|
983
|
+
expect(isValidPriceOrWeightCheckDigit(rcn1.substring(8, 12), rcn1.charAt(7))).toBe(true);
|
|
984
|
+
expect(hasValidCheckDigit(rcn1)).toBe(true);
|
|
985
|
+
expect(() => {
|
|
986
|
+
GTINValidator.parseVariableMeasureRCN("24IIIIIVPPPPC", rcn1);
|
|
987
|
+
}).not.toThrow(RangeError);
|
|
988
|
+
expect(GTINValidator.parseVariableMeasureRCN("24IIIIIVPPPPC", rcn1)).toEqual({
|
|
989
|
+
itemReference: 12345,
|
|
990
|
+
priceOrWeight: 4321
|
|
991
|
+
} satisfies RCNReference);
|
|
992
|
+
|
|
993
|
+
const rcn2 = GTINCreator.createVariableMeasureRCN("21IIIIPPPPPVC", 1234, 54321);
|
|
994
|
+
|
|
995
|
+
expect(rcn2.length).toBe(13);
|
|
996
|
+
expect(rcn2.substring(0, 2)).toBe("21");
|
|
997
|
+
expect(rcn2.substring(2, 6)).toBe("1234");
|
|
998
|
+
expect(rcn2.substring(6, 11)).toBe("54321");
|
|
999
|
+
expect(isValidPriceOrWeightCheckDigit(rcn2.substring(6, 11), rcn2.charAt(11))).toBe(true);
|
|
1000
|
+
expect(hasValidCheckDigit(rcn2)).toBe(true);
|
|
1001
|
+
expect(() => {
|
|
1002
|
+
GTINValidator.parseVariableMeasureRCN("21IIIIPPPPPVC", rcn2);
|
|
1003
|
+
}).not.toThrow(RangeError);
|
|
1004
|
+
expect(GTINValidator.parseVariableMeasureRCN("21IIIIPPPPPVC", rcn2)).toEqual({
|
|
1005
|
+
itemReference: 1234,
|
|
1006
|
+
priceOrWeight: 54321
|
|
1007
|
+
} satisfies RCNReference);
|
|
1008
|
+
|
|
1009
|
+
const rcn3 = GTINCreator.createVariableMeasureRCN("27PPPPPIIIIIC", 12345, 54321);
|
|
1010
|
+
|
|
1011
|
+
expect(rcn3.length).toBe(13);
|
|
1012
|
+
expect(rcn3.substring(0, 2)).toBe("27");
|
|
1013
|
+
expect(rcn3.substring(2, 7)).toBe("54321");
|
|
1014
|
+
expect(rcn3.substring(7, 12)).toBe("12345");
|
|
1015
|
+
expect(hasValidCheckDigit(rcn3)).toBe(true);
|
|
1016
|
+
expect(() => {
|
|
1017
|
+
GTINValidator.parseVariableMeasureRCN("27PPPPPIIIIIC", rcn3);
|
|
1018
|
+
}).not.toThrow(RangeError);
|
|
1019
|
+
expect(GTINValidator.parseVariableMeasureRCN("27PPPPPIIIIIC", rcn3)).toEqual({
|
|
1020
|
+
itemReference: 12345,
|
|
1021
|
+
priceOrWeight: 54321
|
|
1022
|
+
} satisfies RCNReference);
|
|
1023
|
+
|
|
1024
|
+
expect(() => GTINCreator.createVariableMeasureRCN("30PPPPPIIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
1025
|
+
expect(() => GTINCreator.createVariableMeasureRCN("2PPPPPPIIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
1026
|
+
expect(() => GTINCreator.createVariableMeasureRCN("20PPPPPIIIIII", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
1027
|
+
expect(() => GTINCreator.createVariableMeasureRCN("21PPPPPIIIIKC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
1028
|
+
expect(() => GTINCreator.createVariableMeasureRCN("22PPPPPIIPIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
1029
|
+
expect(() => GTINCreator.createVariableMeasureRCN("23PPIPPIIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
1030
|
+
expect(() => GTINCreator.createVariableMeasureRCN("24PPPPPIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
1031
|
+
expect(() => GTINCreator.createVariableMeasureRCN("25PPPPPIIIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
1032
|
+
expect(() => GTINCreator.createVariableMeasureRCN("26PPPPPPPPPPC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
1033
|
+
expect(() => GTINCreator.createVariableMeasureRCN("27IIIIIIIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
1034
|
+
|
|
1035
|
+
expect(() => {
|
|
1036
|
+
GTINCreator.parseVariableMeasureRCN("30PPPPPIIIIIC", "27543211234570");
|
|
1037
|
+
}).toThrow("RCN length must match format length");
|
|
1038
|
+
expect(() => {
|
|
1039
|
+
GTINCreator.parseVariableMeasureRCN("30PPPPPIIIIIC", "275432112345");
|
|
1040
|
+
}).toThrow("RCN length must match format length");
|
|
1041
|
+
expect(() => {
|
|
1042
|
+
GTINCreator.parseVariableMeasureRCN("30PPPPPIIIIIC", "2754321123457");
|
|
1043
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
1044
|
+
expect(() => {
|
|
1045
|
+
GTINCreator.parseVariableMeasureRCN("20PPPPPIIIIII", "2754321123457");
|
|
1046
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
1047
|
+
expect(() => {
|
|
1048
|
+
GTINCreator.parseVariableMeasureRCN("21PPPPPIIIIKC", "2754321123457");
|
|
1049
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
1050
|
+
expect(() => {
|
|
1051
|
+
GTINCreator.parseVariableMeasureRCN("22PPPPPIIPIIC", "2754321123457");
|
|
1052
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
1053
|
+
expect(() => {
|
|
1054
|
+
GTINCreator.parseVariableMeasureRCN("23PPIPPIIIIIC", "2754321123457");
|
|
1055
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
1056
|
+
expect(() => {
|
|
1057
|
+
GTINCreator.parseVariableMeasureRCN("24PPPPPIIIIC", "275432112345");
|
|
1058
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
1059
|
+
expect(() => {
|
|
1060
|
+
GTINCreator.parseVariableMeasureRCN("25PPPPPIIIIIIC", "27543211234570");
|
|
1061
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
1062
|
+
expect(() => {
|
|
1063
|
+
GTINCreator.parseVariableMeasureRCN("26PPPPPPPPPPC", "2754321123457");
|
|
1064
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
1065
|
+
expect(() => {
|
|
1066
|
+
GTINCreator.parseVariableMeasureRCN("27IIIIIIIIIIC", "2754321123457");
|
|
1067
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
1068
|
+
});
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
|
|
875
1072
|
function testNonGTINNumericIdentificationKeyCreator(creator: NonGTINNumericIdentificationKeyCreator, preTestCallback?: () => void, postTestCallback?: () => void): void {
|
|
876
1073
|
testNumericIdentificationKeyCreator(creator, preTestCallback, postTestCallback);
|
|
877
1074
|
}
|
|
@@ -1030,6 +1227,7 @@ prefixManager = PrefixManager.get(PrefixType.GS18Prefix, "9521");
|
|
|
1030
1227
|
testGTINCreator(prefixManager.gtinCreator);
|
|
1031
1228
|
|
|
1032
1229
|
testGTINValidationAndNormalization();
|
|
1230
|
+
testVariableMeasureRCN();
|
|
1033
1231
|
|
|
1034
1232
|
prefixManager = PrefixManager.get(PrefixType.GS1CompanyPrefix, "952123456");
|
|
1035
1233
|
|