@aidc-toolkit/gs1 0.9.20-beta → 0.9.21-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/character-set.d.ts +4 -4
- package/dist/character-set.d.ts.map +1 -1
- package/dist/character-set.js +7 -7
- package/dist/character-set.js.map +1 -1
- package/dist/gtin-creator.d.ts +68 -0
- package/dist/gtin-creator.d.ts.map +1 -0
- package/dist/gtin-creator.js +158 -0
- package/dist/gtin-creator.js.map +1 -0
- package/dist/gtin-validator.d.ts +202 -0
- package/dist/gtin-validator.d.ts.map +1 -0
- package/dist/gtin-validator.js +470 -0
- package/dist/gtin-validator.js.map +1 -0
- package/dist/identifier-creator.d.ts +72 -0
- package/dist/identifier-creator.d.ts.map +1 -0
- package/dist/identifier-creator.js +50 -0
- package/dist/identifier-creator.js.map +1 -0
- package/dist/identifier-type.d.ts +58 -0
- package/dist/identifier-type.d.ts.map +1 -0
- package/dist/identifier-type.js +54 -0
- package/dist/identifier-type.js.map +1 -0
- package/dist/identifier-validator.d.ts +174 -0
- package/dist/identifier-validator.d.ts.map +1 -0
- package/dist/identifier-validator.js +145 -0
- package/dist/identifier-validator.js.map +1 -0
- package/dist/index.d.ts +16 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/dist/locale/en/locale-strings.d.ts +3 -3
- package/dist/locale/en/locale-strings.js +3 -3
- package/dist/locale/en/locale-strings.js.map +1 -1
- package/dist/locale/fr/locale-strings.d.ts +3 -3
- package/dist/locale/fr/locale-strings.js +3 -3
- package/dist/locale/fr/locale-strings.js.map +1 -1
- package/dist/non-gtin-numeric-identifier-creator.d.ts +30 -0
- package/dist/non-gtin-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-creator.js +30 -0
- package/dist/non-gtin-numeric-identifier-creator.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-validator.d.ts +41 -0
- package/dist/non-gtin-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-validator.js +40 -0
- package/dist/non-gtin-numeric-identifier-validator.js.map +1 -0
- package/dist/non-numeric-identifier-creator.d.ts +55 -0
- package/dist/non-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/non-numeric-identifier-creator.js +93 -0
- package/dist/non-numeric-identifier-creator.js.map +1 -0
- package/dist/non-numeric-identifier-validator.d.ts +78 -0
- package/dist/non-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/non-numeric-identifier-validator.js +95 -0
- package/dist/non-numeric-identifier-validator.js.map +1 -0
- package/dist/numeric-identifier-creator.d.ts +121 -0
- package/dist/numeric-identifier-creator.d.ts.map +1 -0
- package/dist/numeric-identifier-creator.js +135 -0
- package/dist/numeric-identifier-creator.js.map +1 -0
- package/dist/numeric-identifier-validator.d.ts +76 -0
- package/dist/numeric-identifier-validator.d.ts.map +1 -0
- package/dist/numeric-identifier-validator.js +84 -0
- package/dist/numeric-identifier-validator.js.map +1 -0
- package/dist/prefix-manager.d.ts +224 -0
- package/dist/prefix-manager.d.ts.map +1 -0
- package/dist/prefix-manager.js +369 -0
- package/dist/prefix-manager.js.map +1 -0
- package/dist/prefix-provider.d.ts +27 -0
- package/dist/prefix-provider.d.ts.map +1 -0
- package/dist/prefix-provider.js +2 -0
- package/dist/prefix-provider.js.map +1 -0
- package/dist/prefix-type.d.ts +22 -0
- package/dist/prefix-type.d.ts.map +1 -0
- package/dist/prefix-type.js +18 -0
- package/dist/prefix-type.js.map +1 -0
- package/dist/prefix-validator.d.ts +58 -0
- package/dist/prefix-validator.d.ts.map +1 -0
- package/dist/prefix-validator.js +154 -0
- package/dist/prefix-validator.js.map +1 -0
- package/dist/serializable-numeric-identifier-creator.d.ts +86 -0
- package/dist/serializable-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-creator.js +116 -0
- package/dist/serializable-numeric-identifier-creator.js.map +1 -0
- package/dist/serializable-numeric-identifier-validator.d.ts +79 -0
- package/dist/serializable-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-validator.js +99 -0
- package/dist/serializable-numeric-identifier-validator.js.map +1 -0
- package/gs1.iml +4 -1
- package/package.json +2 -3
- package/src/character-set.ts +7 -7
- package/src/gtin-creator.ts +195 -0
- package/src/gtin-validator.ts +564 -0
- package/src/identifier-creator.ts +97 -0
- package/src/identifier-type.ts +69 -0
- package/src/identifier-validator.ts +235 -0
- package/src/index.ts +16 -1
- package/src/locale/en/locale-strings.ts +3 -3
- package/src/locale/fr/locale-strings.ts +3 -3
- package/src/non-gtin-numeric-identifier-creator.ts +33 -0
- package/src/non-gtin-numeric-identifier-validator.ts +54 -0
- package/src/non-numeric-identifier-creator.ts +111 -0
- package/src/non-numeric-identifier-validator.ts +128 -0
- package/src/numeric-identifier-creator.ts +200 -0
- package/src/numeric-identifier-validator.ts +128 -0
- package/src/prefix-manager.ts +446 -0
- package/src/prefix-provider.ts +31 -0
- package/src/prefix-type.ts +24 -0
- package/src/prefix-validator.ts +191 -0
- package/src/serializable-numeric-identifier-creator.ts +128 -0
- package/src/serializable-numeric-identifier-validator.ts +124 -0
- package/test/check.test.ts +0 -4
- package/test/creator.test.ts +30 -0
- package/test/gtin-creator.ts +239 -0
- package/test/gtin-validator.test.ts +149 -0
- package/test/identifier-creator.ts +84 -0
- package/test/identifier-validator.ts +8 -0
- package/test/non-gtin-numeric-identifier-creator.ts +98 -0
- package/test/non-gtin-numeric-identifier-validator.ts +6 -0
- package/test/non-numeric-identifier-validator.ts +24 -0
- package/test/numeric-identifier-creator.ts +132 -0
- package/test/numeric-identifier-validator.ts +23 -0
- package/test/prefix-manager.test.ts +112 -0
- package/test/serializable-numeric-identifier-creator.ts +56 -0
- package/test/serializable-numeric-identifier-validator.ts +24 -0
- package/test/setup.ts +4 -0
- package/test/sparse.test.ts +56 -0
- package/test/utility.ts +22 -0
- package/test/validator.test.ts +52 -0
- package/test/variable-measure-rcn.test.ts +201 -0
- package/vitest.config.ts +7 -0
- package/dist/idkey.d.ts +0 -1346
- package/dist/idkey.d.ts.map +0 -1
- package/dist/idkey.js +0 -2024
- package/dist/idkey.js.map +0 -1
- package/src/idkey.ts +0 -2532
- package/test/idkey.test.ts +0 -1247
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { ContentCharacterSets, type SerializableNumericIdentifierCreator } from "../src";
|
|
3
|
+
import { testNonGTINNumericIdentifierCreator } from "./non-gtin-numeric-identifier-creator.js";
|
|
4
|
+
|
|
5
|
+
export function testSerializableNumericIdentifierCreator(creator: SerializableNumericIdentifierCreator): void {
|
|
6
|
+
testNonGTINNumericIdentifierCreator(creator, undefined, () => {
|
|
7
|
+
test("Serialization", () => {
|
|
8
|
+
const identifier = creator.create(0, true);
|
|
9
|
+
const serial = "12345678";
|
|
10
|
+
const serializedIdentifier = identifier + serial;
|
|
11
|
+
const serials = [serial, "23456789", "34567890", "456789012"];
|
|
12
|
+
const serializedIdentifiers = serials.map(serial => identifier + serial);
|
|
13
|
+
|
|
14
|
+
expect(creator.createSerialized(0, serial, true)).toBe(serializedIdentifier);
|
|
15
|
+
expect(creator.concatenate(identifier, serial)).toBe(serializedIdentifier);
|
|
16
|
+
expect(Array.from(creator.createSerialized(0, serials, true))).toStrictEqual(serializedIdentifiers);
|
|
17
|
+
expect(Array.from(creator.concatenate(identifier, serials))).toStrictEqual(serializedIdentifiers);
|
|
18
|
+
|
|
19
|
+
const fullLengthSerial = "0".repeat(creator.serialComponentLength);
|
|
20
|
+
const fullLengthPlusOneSerial = fullLengthSerial + "0";
|
|
21
|
+
const fullLengthPlusOneSerialErrorMessage = `Length ${creator.serialComponentLength + 1} of serial component must be less than or equal to ${creator.serialComponentLength}`;
|
|
22
|
+
|
|
23
|
+
expect(() => creator.createSerialized(0, fullLengthSerial, true)).not.toThrow(RangeError);
|
|
24
|
+
expect(() => creator.concatenate(identifier, fullLengthSerial)).not.toThrow(RangeError);
|
|
25
|
+
expect(() => Array.from(creator.createSerialized(0, [...serials, fullLengthSerial], true))).not.toThrow(RangeError);
|
|
26
|
+
expect(() => Array.from(creator.concatenate(identifier, [...serials, fullLengthSerial]))).not.toThrow(RangeError);
|
|
27
|
+
expect(() => creator.createSerialized(0, fullLengthPlusOneSerial, true)).toThrow(fullLengthPlusOneSerialErrorMessage);
|
|
28
|
+
expect(() => creator.concatenate(identifier, fullLengthPlusOneSerial)).toThrow(fullLengthPlusOneSerialErrorMessage);
|
|
29
|
+
expect(() => Array.from(creator.createSerialized(0, [...serials, fullLengthPlusOneSerial], true))).toThrow(fullLengthPlusOneSerialErrorMessage);
|
|
30
|
+
expect(() => Array.from(creator.concatenate(identifier, [...serials, fullLengthPlusOneSerial]))).toThrow(fullLengthPlusOneSerialErrorMessage);
|
|
31
|
+
|
|
32
|
+
let invalidSerial: string;
|
|
33
|
+
|
|
34
|
+
switch (creator.serialComponentCharacterSet) {
|
|
35
|
+
case ContentCharacterSets.Numeric:
|
|
36
|
+
invalidSerial = "1234A5678";
|
|
37
|
+
break;
|
|
38
|
+
|
|
39
|
+
case ContentCharacterSets.AI82:
|
|
40
|
+
invalidSerial = "ABCD~1234";
|
|
41
|
+
break;
|
|
42
|
+
|
|
43
|
+
case ContentCharacterSets.AI39:
|
|
44
|
+
invalidSerial = "ABCD%1234";
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const invalidSerialErrorMessage = `Invalid character '${invalidSerial.charAt(4)}' at position 5 of serial component`;
|
|
49
|
+
|
|
50
|
+
expect(() => creator.createSerialized(0, invalidSerial, true)).toThrow(invalidSerialErrorMessage);
|
|
51
|
+
expect(() => creator.concatenate(identifier, invalidSerial)).toThrow(invalidSerialErrorMessage);
|
|
52
|
+
expect(() => Array.from(creator.createSerialized(0, [...serials, invalidSerial], true))).toThrow(invalidSerialErrorMessage);
|
|
53
|
+
expect(() => Array.from(creator.concatenate(identifier, [...serials, invalidSerial]))).toThrow(invalidSerialErrorMessage);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { expect } from "vitest";
|
|
2
|
+
import type {
|
|
3
|
+
ContentCharacterSet,
|
|
4
|
+
IdentifierType,
|
|
5
|
+
LeaderType,
|
|
6
|
+
SerializableNumericIdentifierCreator,
|
|
7
|
+
SerializableNumericIdentifierValidator
|
|
8
|
+
} from "../src";
|
|
9
|
+
import { validateNonGTINNumericIdentifierValidator } from "./non-gtin-numeric-identifier-validator.js";
|
|
10
|
+
import { creatorFor } from "./utility.js";
|
|
11
|
+
|
|
12
|
+
export function validateSerializableNumericIdentifierValidator(validator: SerializableNumericIdentifierValidator, isCreator: boolean, identifierType: IdentifierType, length: number, leaderType: LeaderType, serialLength: number, serialCharacterSet: ContentCharacterSet): void {
|
|
13
|
+
validateNonGTINNumericIdentifierValidator(validator, isCreator, identifierType, length, leaderType);
|
|
14
|
+
|
|
15
|
+
const serialCreator = creatorFor(serialCharacterSet);
|
|
16
|
+
|
|
17
|
+
expect(validator.serialComponentLength).toBe(serialLength);
|
|
18
|
+
expect(validator.serialComponentCharacterSet).toBe(serialCharacterSet);
|
|
19
|
+
expect(validator.serialComponentCreator).toBe(serialCreator);
|
|
20
|
+
|
|
21
|
+
if (isCreator) {
|
|
22
|
+
expect((validator as SerializableNumericIdentifierCreator).serialComponentCreator).toBe(serialCreator);
|
|
23
|
+
}
|
|
24
|
+
}
|
package/test/setup.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Sequence } from "@aidc-toolkit/utility";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
3
|
+
import { PrefixManager, PrefixTypes } from "../src";
|
|
4
|
+
|
|
5
|
+
describe("Sparse creation", () => {
|
|
6
|
+
const prefixManager = PrefixManager.get(PrefixTypes.GS1CompanyPrefix, "9521234");
|
|
7
|
+
|
|
8
|
+
const gtin1 = prefixManager.gtinCreator.create(0, true);
|
|
9
|
+
const gln1 = prefixManager.glnCreator.create(0, true);
|
|
10
|
+
|
|
11
|
+
test("Same length 1, not equal", () => {
|
|
12
|
+
expect(gln1.length).toBe(gtin1.length);
|
|
13
|
+
expect(gln1).not.toBe(gtin1);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
prefixManager.tweakFactor = 123456;
|
|
17
|
+
|
|
18
|
+
const gtin2 = prefixManager.gtinCreator.create(0, true);
|
|
19
|
+
const gln2 = prefixManager.glnCreator.create(0, true);
|
|
20
|
+
|
|
21
|
+
test("Same length 2, not equal", () => {
|
|
22
|
+
expect(gln2.length).toBe(gtin2.length);
|
|
23
|
+
expect(gln2).not.toBe(gtin2);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("Same types 1 and 2, not equal", () => {
|
|
27
|
+
expect(gtin2).not.toBe(gtin1);
|
|
28
|
+
expect(gln2).not.toBe(gln1);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
prefixManager.resetTweakFactor();
|
|
32
|
+
|
|
33
|
+
const gtin3 = prefixManager.gtinCreator.create(0, true);
|
|
34
|
+
const gln3 = prefixManager.glnCreator.create(0, true);
|
|
35
|
+
|
|
36
|
+
test("Same length 3, not equal", () => {
|
|
37
|
+
expect(gln3.length).toBe(gtin3.length);
|
|
38
|
+
expect(gln3).not.toBe(gtin3);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("Same types 1 and 3, equal", () => {
|
|
42
|
+
expect(gtin3).toBe(gtin1);
|
|
43
|
+
expect(gln3).toBe(gln1);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
prefixManager.tweakFactor = 0;
|
|
47
|
+
|
|
48
|
+
const sparseGTINs = Array.from(prefixManager.gtinCreator.create(new Sequence(0, 10), true));
|
|
49
|
+
const straightGTINs = Array.from(prefixManager.gtinCreator.create(new Sequence(0, 10)));
|
|
50
|
+
|
|
51
|
+
test("Tweak factor 0", () => {
|
|
52
|
+
expect(sparseGTINs).toStrictEqual(straightGTINs);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
prefixManager.resetTweakFactor();
|
|
56
|
+
});
|
package/test/utility.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type CharacterSetCreator, NUMERIC_CREATOR } from "@aidc-toolkit/utility";
|
|
2
|
+
import { AI39_CREATOR, AI82_CREATOR, type ContentCharacterSet, ContentCharacterSets } from "../src";
|
|
3
|
+
|
|
4
|
+
export function creatorFor(characterSet: ContentCharacterSet): CharacterSetCreator {
|
|
5
|
+
let creator: CharacterSetCreator;
|
|
6
|
+
|
|
7
|
+
switch (characterSet) {
|
|
8
|
+
case ContentCharacterSets.Numeric:
|
|
9
|
+
creator = NUMERIC_CREATOR;
|
|
10
|
+
break;
|
|
11
|
+
|
|
12
|
+
case ContentCharacterSets.AI82:
|
|
13
|
+
creator = AI82_CREATOR;
|
|
14
|
+
break;
|
|
15
|
+
|
|
16
|
+
case ContentCharacterSets.AI39:
|
|
17
|
+
creator = AI39_CREATOR;
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return creator;
|
|
22
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
ContentCharacterSets,
|
|
4
|
+
CPID_VALIDATOR,
|
|
5
|
+
GCN_VALIDATOR,
|
|
6
|
+
GDTI_VALIDATOR,
|
|
7
|
+
GIAI_VALIDATOR,
|
|
8
|
+
GINC_VALIDATOR,
|
|
9
|
+
GLN_VALIDATOR,
|
|
10
|
+
GMN_VALIDATOR,
|
|
11
|
+
GRAI_VALIDATOR,
|
|
12
|
+
GSIN_VALIDATOR,
|
|
13
|
+
GSRN_VALIDATOR,
|
|
14
|
+
GTIN12_VALIDATOR,
|
|
15
|
+
GTIN13_VALIDATOR,
|
|
16
|
+
GTIN8_VALIDATOR,
|
|
17
|
+
GTIN_VALIDATORS,
|
|
18
|
+
GTINTypes,
|
|
19
|
+
IdentifierTypes,
|
|
20
|
+
LeaderTypes,
|
|
21
|
+
PrefixTypes,
|
|
22
|
+
SSCC_VALIDATOR
|
|
23
|
+
} from "../src";
|
|
24
|
+
import { validateGTINValidator } from "./gtin-validator.test.js";
|
|
25
|
+
import { validateNonGTINNumericIdentifierValidator } from "./non-gtin-numeric-identifier-validator.js";
|
|
26
|
+
import { validateNonNumericIdentifierValidator } from "./non-numeric-identifier-validator.js";
|
|
27
|
+
import { validateSerializableNumericIdentifierValidator } from "./serializable-numeric-identifier-validator.js";
|
|
28
|
+
|
|
29
|
+
describe("Validators", () => {
|
|
30
|
+
test("GTIN", () => {
|
|
31
|
+
expect(GTIN_VALIDATORS[PrefixTypes.GS1CompanyPrefix]).toBe(GTIN13_VALIDATOR);
|
|
32
|
+
expect(GTIN_VALIDATORS[PrefixTypes.UPCCompanyPrefix]).toBe(GTIN12_VALIDATOR);
|
|
33
|
+
expect(GTIN_VALIDATORS[PrefixTypes.GS18Prefix]).toBe(GTIN8_VALIDATOR);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("Structure", () => {
|
|
37
|
+
validateGTINValidator(GTIN13_VALIDATOR, false, GTINTypes.GTIN13);
|
|
38
|
+
validateGTINValidator(GTIN12_VALIDATOR, false, GTINTypes.GTIN12);
|
|
39
|
+
validateGTINValidator(GTIN8_VALIDATOR, false, GTINTypes.GTIN8);
|
|
40
|
+
validateNonGTINNumericIdentifierValidator(GLN_VALIDATOR, false, IdentifierTypes.GLN, 13, LeaderTypes.None);
|
|
41
|
+
validateNonGTINNumericIdentifierValidator(SSCC_VALIDATOR, false, IdentifierTypes.SSCC, 18, LeaderTypes.ExtensionDigit);
|
|
42
|
+
validateSerializableNumericIdentifierValidator(GRAI_VALIDATOR, false, IdentifierTypes.GRAI, 13, LeaderTypes.None, 16, ContentCharacterSets.AI82);
|
|
43
|
+
validateNonNumericIdentifierValidator(GIAI_VALIDATOR, false, IdentifierTypes.GIAI, 30, ContentCharacterSets.AI82, false);
|
|
44
|
+
validateNonGTINNumericIdentifierValidator(GSRN_VALIDATOR, false, IdentifierTypes.GSRN, 18, LeaderTypes.None);
|
|
45
|
+
validateSerializableNumericIdentifierValidator(GDTI_VALIDATOR, false, IdentifierTypes.GDTI, 13, LeaderTypes.None, 17, ContentCharacterSets.AI82);
|
|
46
|
+
validateNonNumericIdentifierValidator(GINC_VALIDATOR, false, IdentifierTypes.GINC, 30, ContentCharacterSets.AI82, false);
|
|
47
|
+
validateNonGTINNumericIdentifierValidator(GSIN_VALIDATOR, false, IdentifierTypes.GSIN, 17, LeaderTypes.None);
|
|
48
|
+
validateSerializableNumericIdentifierValidator(GCN_VALIDATOR, false, IdentifierTypes.GCN, 13, LeaderTypes.None, 12, ContentCharacterSets.Numeric);
|
|
49
|
+
validateNonNumericIdentifierValidator(CPID_VALIDATOR, false, IdentifierTypes.CPID, 30, ContentCharacterSets.AI39, false);
|
|
50
|
+
validateNonNumericIdentifierValidator(GMN_VALIDATOR, false, IdentifierTypes.GMN, 25, ContentCharacterSets.AI82, true);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
GTINCreator,
|
|
4
|
+
GTINValidator,
|
|
5
|
+
hasValidCheckDigit,
|
|
6
|
+
isValidPriceOrWeightCheckDigit,
|
|
7
|
+
type RCNReference
|
|
8
|
+
} from "../src";
|
|
9
|
+
|
|
10
|
+
describe("Variable measure RCN", () => {
|
|
11
|
+
test("RCN-12", () => {
|
|
12
|
+
const rcn1 = GTINCreator.createVariableMeasureRCN("2IIIIIVPPPPC", 12345, 4321);
|
|
13
|
+
|
|
14
|
+
expect(rcn1.length).toBe(12);
|
|
15
|
+
expect(rcn1.charAt(0)).toBe("2");
|
|
16
|
+
expect(rcn1.substring(1, 6)).toBe("12345");
|
|
17
|
+
expect(rcn1.substring(7, 11)).toBe("4321");
|
|
18
|
+
expect(isValidPriceOrWeightCheckDigit(rcn1.substring(7, 11), rcn1.charAt(6))).toBe(true);
|
|
19
|
+
expect(hasValidCheckDigit(rcn1)).toBe(true);
|
|
20
|
+
expect(() => {
|
|
21
|
+
GTINValidator.parseVariableMeasureRCN("2IIIIIVPPPPC", rcn1);
|
|
22
|
+
}).not.toThrow(RangeError);
|
|
23
|
+
expect(GTINValidator.parseVariableMeasureRCN("2IIIIIVPPPPC", rcn1)).toEqual({
|
|
24
|
+
itemReference: 12345,
|
|
25
|
+
priceOrWeight: 4321
|
|
26
|
+
} satisfies RCNReference);
|
|
27
|
+
|
|
28
|
+
const rcn2 = GTINCreator.createVariableMeasureRCN("2IIIIPPPPPVC", 1234, 54321);
|
|
29
|
+
|
|
30
|
+
expect(rcn2.length).toBe(12);
|
|
31
|
+
expect(rcn2.charAt(0)).toBe("2");
|
|
32
|
+
expect(rcn2.substring(1, 5)).toBe("1234");
|
|
33
|
+
expect(rcn2.substring(5, 10)).toBe("54321");
|
|
34
|
+
expect(isValidPriceOrWeightCheckDigit(rcn2.substring(5, 10), rcn2.charAt(10))).toBe(true);
|
|
35
|
+
expect(hasValidCheckDigit(rcn2)).toBe(true);
|
|
36
|
+
expect(() => {
|
|
37
|
+
GTINValidator.parseVariableMeasureRCN("2IIIIPPPPPVC", rcn2);
|
|
38
|
+
}).not.toThrow(RangeError);
|
|
39
|
+
expect(GTINValidator.parseVariableMeasureRCN("2IIIIPPPPPVC", rcn2)).toEqual({
|
|
40
|
+
itemReference: 1234,
|
|
41
|
+
priceOrWeight: 54321
|
|
42
|
+
} satisfies RCNReference);
|
|
43
|
+
|
|
44
|
+
const rcn3 = GTINCreator.createVariableMeasureRCN("2PPPPPIIIIIC", 12345, 54321);
|
|
45
|
+
|
|
46
|
+
expect(rcn3.length).toBe(12);
|
|
47
|
+
expect(rcn3.charAt(0)).toBe("2");
|
|
48
|
+
expect(rcn3.substring(1, 6)).toBe("54321");
|
|
49
|
+
expect(rcn3.substring(6, 11)).toBe("12345");
|
|
50
|
+
expect(hasValidCheckDigit(rcn3)).toBe(true);
|
|
51
|
+
expect(() => {
|
|
52
|
+
GTINValidator.parseVariableMeasureRCN("2PPPPPIIIIIC", rcn3);
|
|
53
|
+
}).not.toThrow(RangeError);
|
|
54
|
+
expect(GTINValidator.parseVariableMeasureRCN("2PPPPPIIIIIC", rcn3)).toEqual({
|
|
55
|
+
itemReference: 12345,
|
|
56
|
+
priceOrWeight: 54321
|
|
57
|
+
} satisfies RCNReference);
|
|
58
|
+
|
|
59
|
+
expect(() => GTINCreator.createVariableMeasureRCN("3PPPPPIIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
60
|
+
expect(() => GTINCreator.createVariableMeasureRCN("20PPPPPIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
61
|
+
expect(() => GTINCreator.createVariableMeasureRCN("2PPPPPIIIIII", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
62
|
+
expect(() => GTINCreator.createVariableMeasureRCN("2PPPPPIIIIKC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
63
|
+
expect(() => GTINCreator.createVariableMeasureRCN("2PPPPPIIPIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
64
|
+
expect(() => GTINCreator.createVariableMeasureRCN("2PPIPPIIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
65
|
+
expect(() => GTINCreator.createVariableMeasureRCN("2PPPPPIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
66
|
+
expect(() => GTINCreator.createVariableMeasureRCN("2PPPPPIIIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
67
|
+
expect(() => GTINCreator.createVariableMeasureRCN("2PPPPPPPPPPC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
68
|
+
expect(() => GTINCreator.createVariableMeasureRCN("2IIIIIIIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
69
|
+
|
|
70
|
+
expect(() => {
|
|
71
|
+
GTINCreator.parseVariableMeasureRCN("3PPPPPIIIIIC", "2543211234540");
|
|
72
|
+
}).toThrow("RCN length must match format length");
|
|
73
|
+
expect(() => {
|
|
74
|
+
GTINCreator.parseVariableMeasureRCN("3PPPPPIIIIIC", "25432112345");
|
|
75
|
+
}).toThrow("RCN length must match format length");
|
|
76
|
+
expect(() => {
|
|
77
|
+
GTINCreator.parseVariableMeasureRCN("3PPPPPIIIIIC", "254321123454");
|
|
78
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
79
|
+
expect(() => {
|
|
80
|
+
GTINCreator.parseVariableMeasureRCN("20PPPPPIIIIC", "254321123454");
|
|
81
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
82
|
+
expect(() => {
|
|
83
|
+
GTINCreator.parseVariableMeasureRCN("2PPPPPIIIIII", "254321123454");
|
|
84
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
85
|
+
expect(() => {
|
|
86
|
+
GTINCreator.parseVariableMeasureRCN("2PPPPPIIIIKC", "254321123454");
|
|
87
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
88
|
+
expect(() => {
|
|
89
|
+
GTINCreator.parseVariableMeasureRCN("2PPPPPIIPIIC", "254321123454");
|
|
90
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
91
|
+
expect(() => {
|
|
92
|
+
GTINCreator.parseVariableMeasureRCN("2PPIPPIIIIIC", "254321123454");
|
|
93
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
94
|
+
expect(() => {
|
|
95
|
+
GTINCreator.parseVariableMeasureRCN("2PPPPPIIIIC", "25432112345");
|
|
96
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
97
|
+
expect(() => {
|
|
98
|
+
GTINCreator.parseVariableMeasureRCN("2PPPPPIIIIIIC", "2543211234540");
|
|
99
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
100
|
+
expect(() => {
|
|
101
|
+
GTINCreator.parseVariableMeasureRCN("2PPPPPPPPPPC", "254321123454");
|
|
102
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
103
|
+
expect(() => {
|
|
104
|
+
GTINCreator.parseVariableMeasureRCN("2IIIIIIIIIIC", "254321123454");
|
|
105
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("RCN-13", () => {
|
|
109
|
+
const rcn1 = GTINCreator.createVariableMeasureRCN("24IIIIIVPPPPC", 12345, 4321);
|
|
110
|
+
|
|
111
|
+
expect(rcn1.length).toBe(13);
|
|
112
|
+
expect(rcn1.substring(0, 2)).toBe("24");
|
|
113
|
+
expect(rcn1.substring(2, 7)).toBe("12345");
|
|
114
|
+
expect(rcn1.substring(8, 12)).toBe("4321");
|
|
115
|
+
expect(isValidPriceOrWeightCheckDigit(rcn1.substring(8, 12), rcn1.charAt(7))).toBe(true);
|
|
116
|
+
expect(hasValidCheckDigit(rcn1)).toBe(true);
|
|
117
|
+
expect(() => {
|
|
118
|
+
GTINValidator.parseVariableMeasureRCN("24IIIIIVPPPPC", rcn1);
|
|
119
|
+
}).not.toThrow(RangeError);
|
|
120
|
+
expect(GTINValidator.parseVariableMeasureRCN("24IIIIIVPPPPC", rcn1)).toEqual({
|
|
121
|
+
itemReference: 12345,
|
|
122
|
+
priceOrWeight: 4321
|
|
123
|
+
} satisfies RCNReference);
|
|
124
|
+
|
|
125
|
+
const rcn2 = GTINCreator.createVariableMeasureRCN("21IIIIPPPPPVC", 1234, 54321);
|
|
126
|
+
|
|
127
|
+
expect(rcn2.length).toBe(13);
|
|
128
|
+
expect(rcn2.substring(0, 2)).toBe("21");
|
|
129
|
+
expect(rcn2.substring(2, 6)).toBe("1234");
|
|
130
|
+
expect(rcn2.substring(6, 11)).toBe("54321");
|
|
131
|
+
expect(isValidPriceOrWeightCheckDigit(rcn2.substring(6, 11), rcn2.charAt(11))).toBe(true);
|
|
132
|
+
expect(hasValidCheckDigit(rcn2)).toBe(true);
|
|
133
|
+
expect(() => {
|
|
134
|
+
GTINValidator.parseVariableMeasureRCN("21IIIIPPPPPVC", rcn2);
|
|
135
|
+
}).not.toThrow(RangeError);
|
|
136
|
+
expect(GTINValidator.parseVariableMeasureRCN("21IIIIPPPPPVC", rcn2)).toEqual({
|
|
137
|
+
itemReference: 1234,
|
|
138
|
+
priceOrWeight: 54321
|
|
139
|
+
} satisfies RCNReference);
|
|
140
|
+
|
|
141
|
+
const rcn3 = GTINCreator.createVariableMeasureRCN("27PPPPPIIIIIC", 12345, 54321);
|
|
142
|
+
|
|
143
|
+
expect(rcn3.length).toBe(13);
|
|
144
|
+
expect(rcn3.substring(0, 2)).toBe("27");
|
|
145
|
+
expect(rcn3.substring(2, 7)).toBe("54321");
|
|
146
|
+
expect(rcn3.substring(7, 12)).toBe("12345");
|
|
147
|
+
expect(hasValidCheckDigit(rcn3)).toBe(true);
|
|
148
|
+
expect(() => {
|
|
149
|
+
GTINValidator.parseVariableMeasureRCN("27PPPPPIIIIIC", rcn3);
|
|
150
|
+
}).not.toThrow(RangeError);
|
|
151
|
+
expect(GTINValidator.parseVariableMeasureRCN("27PPPPPIIIIIC", rcn3)).toEqual({
|
|
152
|
+
itemReference: 12345,
|
|
153
|
+
priceOrWeight: 54321
|
|
154
|
+
} satisfies RCNReference);
|
|
155
|
+
|
|
156
|
+
expect(() => GTINCreator.createVariableMeasureRCN("30PPPPPIIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
157
|
+
expect(() => GTINCreator.createVariableMeasureRCN("2PPPPPPIIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
158
|
+
expect(() => GTINCreator.createVariableMeasureRCN("20PPPPPIIIIII", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
159
|
+
expect(() => GTINCreator.createVariableMeasureRCN("21PPPPPIIIIKC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
160
|
+
expect(() => GTINCreator.createVariableMeasureRCN("22PPPPPIIPIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
161
|
+
expect(() => GTINCreator.createVariableMeasureRCN("23PPIPPIIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
162
|
+
expect(() => GTINCreator.createVariableMeasureRCN("24PPPPPIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
163
|
+
expect(() => GTINCreator.createVariableMeasureRCN("25PPPPPIIIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
164
|
+
expect(() => GTINCreator.createVariableMeasureRCN("26PPPPPPPPPPC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
165
|
+
expect(() => GTINCreator.createVariableMeasureRCN("27IIIIIIIIIIC", 12345, 54321)).toThrow("Invalid variable measure RCN format");
|
|
166
|
+
|
|
167
|
+
expect(() => {
|
|
168
|
+
GTINCreator.parseVariableMeasureRCN("30PPPPPIIIIIC", "27543211234570");
|
|
169
|
+
}).toThrow("RCN length must match format length");
|
|
170
|
+
expect(() => {
|
|
171
|
+
GTINCreator.parseVariableMeasureRCN("30PPPPPIIIIIC", "275432112345");
|
|
172
|
+
}).toThrow("RCN length must match format length");
|
|
173
|
+
expect(() => {
|
|
174
|
+
GTINCreator.parseVariableMeasureRCN("30PPPPPIIIIIC", "2754321123457");
|
|
175
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
176
|
+
expect(() => {
|
|
177
|
+
GTINCreator.parseVariableMeasureRCN("20PPPPPIIIIII", "2754321123457");
|
|
178
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
179
|
+
expect(() => {
|
|
180
|
+
GTINCreator.parseVariableMeasureRCN("21PPPPPIIIIKC", "2754321123457");
|
|
181
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
182
|
+
expect(() => {
|
|
183
|
+
GTINCreator.parseVariableMeasureRCN("22PPPPPIIPIIC", "2754321123457");
|
|
184
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
185
|
+
expect(() => {
|
|
186
|
+
GTINCreator.parseVariableMeasureRCN("23PPIPPIIIIIC", "2754321123457");
|
|
187
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
188
|
+
expect(() => {
|
|
189
|
+
GTINCreator.parseVariableMeasureRCN("24PPPPPIIIIC", "275432112345");
|
|
190
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
191
|
+
expect(() => {
|
|
192
|
+
GTINCreator.parseVariableMeasureRCN("25PPPPPIIIIIIC", "27543211234570");
|
|
193
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
194
|
+
expect(() => {
|
|
195
|
+
GTINCreator.parseVariableMeasureRCN("26PPPPPPPPPPC", "2754321123457");
|
|
196
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
197
|
+
expect(() => {
|
|
198
|
+
GTINCreator.parseVariableMeasureRCN("27IIIIIIIIIIC", "2754321123457");
|
|
199
|
+
}).toThrow("Invalid variable measure RCN format");
|
|
200
|
+
});
|
|
201
|
+
});
|