@aidc-toolkit/gs1 1.0.24-beta → 1.0.25-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/index.cjs +562 -373
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +776 -415
- package/dist/index.d.ts +776 -415
- package/dist/index.js +549 -363
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/abstract-identifier-creator.ts +97 -0
- package/src/abstract-identifier-validator.ts +140 -0
- package/src/abstract-numeric-identifier-creator.ts +168 -0
- package/src/abstract-numeric-identifier-validator.ts +69 -0
- package/src/character-set.ts +10 -10
- package/src/check.ts +7 -7
- package/src/content-character-set.ts +29 -0
- package/src/creators.ts +113 -0
- package/src/descriptors.ts +332 -0
- package/src/gtin-creator.ts +7 -6
- package/src/gtin-descriptor.ts +18 -0
- package/src/gtin-type.ts +50 -0
- package/src/gtin-validator.ts +36 -60
- package/src/identifier-creator.ts +11 -75
- package/src/identifier-descriptor.ts +30 -0
- package/src/identifier-type.ts +6 -1
- package/src/identifier-validator.ts +12 -188
- package/src/index.ts +29 -5
- package/src/locale/en/locale-resources.ts +0 -1
- package/src/locale/fr/locale-resources.ts +0 -1
- package/src/non-gtin-numeric-identifier-creator.ts +5 -11
- package/src/non-gtin-numeric-identifier-descriptor.ts +24 -0
- package/src/non-gtin-numeric-identifier-type.ts +7 -0
- package/src/non-gtin-numeric-identifier-validator.ts +8 -42
- package/src/non-numeric-identifier-creator.ts +5 -15
- package/src/non-numeric-identifier-descriptor.ts +29 -0
- package/src/non-numeric-identifier-type.ts +7 -0
- package/src/non-numeric-identifier-validator.ts +15 -53
- package/src/numeric-identifier-creator.ts +20 -163
- package/src/numeric-identifier-descriptor.ts +23 -0
- package/src/numeric-identifier-type.ts +44 -0
- package/src/numeric-identifier-validator.ts +13 -116
- package/src/prefix-manager.ts +84 -142
- package/src/prefix-provider.ts +2 -2
- package/src/prefix-type.ts +6 -1
- package/src/prefix-validator.ts +141 -79
- package/src/serializable-numeric-identifier-creator.ts +4 -14
- package/src/serializable-numeric-identifier-descriptor.ts +29 -0
- package/src/serializable-numeric-identifier-type.ts +9 -0
- package/src/serializable-numeric-identifier-validator.ts +17 -45
- package/src/validators.ts +203 -0
- package/test/creator.test.ts +2 -4
- package/test/gtin-creator.ts +5 -1
- package/test/gtin-validator.test.ts +5 -8
- package/test/identifier-creator.ts +1 -0
- package/test/identifier-validator.ts +2 -2
- package/test/non-gtin-numeric-identifier-creator.ts +8 -92
- package/test/non-gtin-numeric-identifier-validator.ts +1 -1
- package/test/non-numeric-identifier-creator.ts +93 -0
- package/test/numeric-identifier-creator.ts +9 -3
- package/test/numeric-identifier-validator.ts +3 -7
- package/test/serializable-numeric-identifier-creator.ts +10 -2
- package/test/validator.test.ts +59 -35
|
@@ -33,6 +33,7 @@ export function validateIdentifierCreators(prefixManager: PrefixManager): void {
|
|
|
33
33
|
break;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
// Validate creator caching.
|
|
36
37
|
expect(prefixManager.gtinCreator).toBe(prefixManager.gtinCreator);
|
|
37
38
|
|
|
38
39
|
validateGTINValidator(prefixManager.gtinCreator, true, gtinType);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { expect } from "vitest";
|
|
2
|
-
import type { IdentifierType,
|
|
2
|
+
import type { IdentifierType, IdentifierTypeValidator, PrefixType } from "../src";
|
|
3
3
|
|
|
4
|
-
export function validateIdentifierValidator(creator:
|
|
4
|
+
export function validateIdentifierValidator<TIdentifierType extends IdentifierType>(creator: IdentifierTypeValidator<TIdentifierType>, identifierType: IdentifierType, prefixType: PrefixType, length: number): void {
|
|
5
5
|
expect(creator.identifierType).toBe(identifierType);
|
|
6
6
|
expect(creator.prefixType).toBe(prefixType);
|
|
7
7
|
expect(creator.length).toBe(length);
|
|
@@ -1,98 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
hasValidCheckCharacterPair,
|
|
5
|
-
type NonGTINNumericIdentifierCreator,
|
|
6
|
-
type NonNumericIdentifierCreator
|
|
7
|
-
} from "../src";
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { isNonGTINNumericIdentifierCreator, type NonGTINNumericIdentifierCreator } from "../src";
|
|
3
|
+
import { testIdentifierCreatorCallback } from "./identifier-creator";
|
|
8
4
|
import { testNumericIdentifierCreator } from "./numeric-identifier-creator";
|
|
9
5
|
|
|
10
6
|
export function testNonGTINNumericIdentifierCreator(creator: NonGTINNumericIdentifierCreator, preTestCallback?: () => void, postTestCallback?: () => void): void {
|
|
11
|
-
testNumericIdentifierCreator(creator,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const TEST_REFERENCE_LENGTH = 2;
|
|
15
|
-
|
|
16
|
-
export function testNonNumericIdentifierCreator(creator: NonNumericIdentifierCreator): void {
|
|
17
|
-
describe(creator.identifierType, () => {
|
|
18
|
-
const prefix = creator.prefix;
|
|
19
|
-
const prefixLength = prefix.length;
|
|
20
|
-
const referenceLength = creator.length - prefixLength - 2 * Number(creator.requiresCheckCharacterPair);
|
|
21
|
-
const referenceCount = creator.referenceCreator.characterSetSize ** TEST_REFERENCE_LENGTH;
|
|
22
|
-
const referenceSubstringStart = prefixLength;
|
|
23
|
-
const referenceSubstringEnd = prefixLength + TEST_REFERENCE_LENGTH;
|
|
24
|
-
|
|
25
|
-
test("Straight", () => {
|
|
26
|
-
expect(creator.referenceLength).toBe(referenceLength);
|
|
27
|
-
|
|
28
|
-
let index = 0;
|
|
29
|
-
|
|
30
|
-
for (const identifier of creator.create(creator.referenceCreator.create(TEST_REFERENCE_LENGTH, new Sequence(0, referenceCount)))) {
|
|
31
|
-
expect(() => {
|
|
32
|
-
creator.validate(identifier);
|
|
33
|
-
}).not.toThrow(RangeError);
|
|
34
|
-
|
|
35
|
-
expect(Number(creator.referenceCreator.valueFor(identifier.substring(referenceSubstringStart, referenceSubstringEnd)))).toBe(index);
|
|
36
|
-
|
|
37
|
-
expect(identifier.length).toBeLessThanOrEqual(creator.length);
|
|
38
|
-
expect(identifier.substring(0, prefixLength)).toBe(prefix);
|
|
39
|
-
expect(!creator.requiresCheckCharacterPair || hasValidCheckCharacterPair(identifier)).toBe(true);
|
|
40
|
-
|
|
41
|
-
expect(identifier).toBe(creator.referenceCreator.create(TEST_REFERENCE_LENGTH, index, Exclusions.None, undefined, reference => creator.create(reference)));
|
|
42
|
-
|
|
43
|
-
index++;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
expect(index).toBe(referenceCount);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test("Sparse", () => {
|
|
50
|
-
let sequential = true;
|
|
51
|
-
|
|
52
|
-
let index = 0;
|
|
53
|
-
|
|
54
|
-
for (const identifier of creator.create(creator.referenceCreator.create(TEST_REFERENCE_LENGTH, new Sequence(0, referenceCount), Exclusions.None, 123456n))) {
|
|
55
|
-
expect(() => {
|
|
56
|
-
creator.validate(identifier);
|
|
57
|
-
}).not.toThrow(RangeError);
|
|
58
|
-
|
|
59
|
-
expect(Number(creator.referenceCreator.valueFor(identifier.substring(referenceSubstringStart, referenceSubstringEnd), Exclusions.None, 123456n))).toBe(index);
|
|
60
|
-
|
|
61
|
-
sequential &&= Number(creator.referenceCreator.valueFor(identifier.substring(referenceSubstringStart, referenceSubstringEnd))) === index;
|
|
62
|
-
|
|
63
|
-
expect(identifier.length).toBeLessThanOrEqual(creator.length);
|
|
64
|
-
expect(identifier.substring(0, prefixLength)).toBe(prefix);
|
|
65
|
-
expect(!creator.requiresCheckCharacterPair || hasValidCheckCharacterPair(identifier)).toBe(true);
|
|
66
|
-
|
|
67
|
-
expect(identifier).toBe(creator.referenceCreator.create(TEST_REFERENCE_LENGTH, index, Exclusions.None, 123456n, reference => creator.create(reference)));
|
|
68
|
-
|
|
69
|
-
index++;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
expect(sequential).toBe(false);
|
|
73
|
-
expect(index).toBe(referenceCount);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test("Position offset", () => {
|
|
77
|
-
expect(() => {
|
|
78
|
-
creator.validate(creator.create("ABC123"), {
|
|
79
|
-
positionOffset: 4
|
|
80
|
-
});
|
|
81
|
-
}).not.toThrow(RangeError);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test("Not all numeric", () => {
|
|
85
|
-
expect(() => {
|
|
86
|
-
creator.validate(creator.create("01234"), {
|
|
87
|
-
exclusion: Exclusions.AllNumeric
|
|
88
|
-
});
|
|
89
|
-
}).toThrow("Reference can't be all-numeric");
|
|
7
|
+
testNumericIdentifierCreator(creator, () => {
|
|
8
|
+
testIdentifierCreatorCallback(preTestCallback);
|
|
90
9
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
exclusion: Exclusions.AllNumeric
|
|
94
|
-
});
|
|
95
|
-
}).not.toThrow(RangeError);
|
|
10
|
+
test("Mapping", () => {
|
|
11
|
+
expect(isNonGTINNumericIdentifierCreator(creator)).toBe(true);
|
|
96
12
|
});
|
|
97
|
-
});
|
|
13
|
+
}, postTestCallback);
|
|
98
14
|
}
|
|
@@ -2,5 +2,5 @@ import { type IdentifierType, type LeaderType, type NonGTINNumericIdentifierVali
|
|
|
2
2
|
import { validateNumericIdentifierValidator } from "./numeric-identifier-validator";
|
|
3
3
|
|
|
4
4
|
export function validateNonGTINNumericIdentifierValidator(validator: NonGTINNumericIdentifierValidator, isCreator: boolean, identifierType: IdentifierType, length: number, leaderType: LeaderType): void {
|
|
5
|
-
validateNumericIdentifierValidator(validator,
|
|
5
|
+
validateNumericIdentifierValidator(validator, identifierType, PrefixTypes.GS1CompanyPrefix, length, leaderType);
|
|
6
6
|
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Exclusions, Sequence } from "@aidc-toolkit/utility";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
3
|
+
import { hasValidCheckCharacterPair, isNonNumericIdentifierCreator, type NonNumericIdentifierCreator } from "../src";
|
|
4
|
+
|
|
5
|
+
const TEST_REFERENCE_LENGTH = 2;
|
|
6
|
+
|
|
7
|
+
export function testNonNumericIdentifierCreator(creator: NonNumericIdentifierCreator): void {
|
|
8
|
+
describe(creator.identifierType, () => {
|
|
9
|
+
const prefix = creator.prefix;
|
|
10
|
+
const prefixLength = prefix.length;
|
|
11
|
+
const referenceLength = creator.length - prefixLength - 2 * Number(creator.requiresCheckCharacterPair);
|
|
12
|
+
const referenceCount = creator.referenceCreator.characterSetSize ** TEST_REFERENCE_LENGTH;
|
|
13
|
+
const referenceSubstringStart = prefixLength;
|
|
14
|
+
const referenceSubstringEnd = prefixLength + TEST_REFERENCE_LENGTH;
|
|
15
|
+
|
|
16
|
+
test("Mapping", () => {
|
|
17
|
+
expect(isNonNumericIdentifierCreator(creator)).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("Straight", () => {
|
|
21
|
+
expect(creator.referenceLength).toBe(referenceLength);
|
|
22
|
+
|
|
23
|
+
let index = 0;
|
|
24
|
+
|
|
25
|
+
for (const identifier of creator.create(creator.referenceCreator.create(TEST_REFERENCE_LENGTH, new Sequence(0, referenceCount)))) {
|
|
26
|
+
expect(() => {
|
|
27
|
+
creator.validate(identifier);
|
|
28
|
+
}).not.toThrow(RangeError);
|
|
29
|
+
|
|
30
|
+
expect(Number(creator.referenceCreator.valueFor(identifier.substring(referenceSubstringStart, referenceSubstringEnd)))).toBe(index);
|
|
31
|
+
|
|
32
|
+
expect(identifier.length).toBeLessThanOrEqual(creator.length);
|
|
33
|
+
expect(identifier.substring(0, prefixLength)).toBe(prefix);
|
|
34
|
+
expect(!creator.requiresCheckCharacterPair || hasValidCheckCharacterPair(identifier)).toBe(true);
|
|
35
|
+
|
|
36
|
+
expect(identifier).toBe(creator.referenceCreator.create(TEST_REFERENCE_LENGTH, index, Exclusions.None, undefined, reference => creator.create(reference)));
|
|
37
|
+
|
|
38
|
+
index++;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
expect(index).toBe(referenceCount);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("Sparse", () => {
|
|
45
|
+
let sequential = true;
|
|
46
|
+
|
|
47
|
+
let index = 0;
|
|
48
|
+
|
|
49
|
+
for (const identifier of creator.create(creator.referenceCreator.create(TEST_REFERENCE_LENGTH, new Sequence(0, referenceCount), Exclusions.None, 123456n))) {
|
|
50
|
+
expect(() => {
|
|
51
|
+
creator.validate(identifier);
|
|
52
|
+
}).not.toThrow(RangeError);
|
|
53
|
+
|
|
54
|
+
expect(Number(creator.referenceCreator.valueFor(identifier.substring(referenceSubstringStart, referenceSubstringEnd), Exclusions.None, 123456n))).toBe(index);
|
|
55
|
+
|
|
56
|
+
sequential &&= Number(creator.referenceCreator.valueFor(identifier.substring(referenceSubstringStart, referenceSubstringEnd))) === index;
|
|
57
|
+
|
|
58
|
+
expect(identifier.length).toBeLessThanOrEqual(creator.length);
|
|
59
|
+
expect(identifier.substring(0, prefixLength)).toBe(prefix);
|
|
60
|
+
expect(!creator.requiresCheckCharacterPair || hasValidCheckCharacterPair(identifier)).toBe(true);
|
|
61
|
+
|
|
62
|
+
expect(identifier).toBe(creator.referenceCreator.create(TEST_REFERENCE_LENGTH, index, Exclusions.None, 123456n, reference => creator.create(reference)));
|
|
63
|
+
|
|
64
|
+
index++;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
expect(sequential).toBe(false);
|
|
68
|
+
expect(index).toBe(referenceCount);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("Position offset", () => {
|
|
72
|
+
expect(() => {
|
|
73
|
+
creator.validate(creator.create("ABC123"), {
|
|
74
|
+
positionOffset: 4
|
|
75
|
+
});
|
|
76
|
+
}).not.toThrow(RangeError);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("Not all numeric", () => {
|
|
80
|
+
expect(() => {
|
|
81
|
+
creator.validate(creator.create("01234"), {
|
|
82
|
+
exclusion: Exclusions.AllNumeric
|
|
83
|
+
});
|
|
84
|
+
}).toThrow("Reference can't be all-numeric");
|
|
85
|
+
|
|
86
|
+
expect(() => {
|
|
87
|
+
creator.validate(creator.create("O1234"), {
|
|
88
|
+
exclusion: Exclusions.AllNumeric
|
|
89
|
+
});
|
|
90
|
+
}).not.toThrow(RangeError);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { CharacterSetCreator, Sequence } from "@aidc-toolkit/utility";
|
|
2
2
|
import { describe, expect, test } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
hasValidCheckDigit,
|
|
5
|
+
isGTINCreator,
|
|
6
|
+
LeaderTypes,
|
|
7
|
+
type NumericIdentifierCreator,
|
|
8
|
+
type NumericIdentifierDescriptor
|
|
9
|
+
} from "../src";
|
|
4
10
|
import { testIdentifierCreatorCallback } from "./identifier-creator";
|
|
5
11
|
|
|
6
|
-
export function testNumericIdentifierCreator(creator: NumericIdentifierCreator
|
|
7
|
-
describe(creator
|
|
12
|
+
export function testNumericIdentifierCreator<TNumericIdentifierDescriptor extends NumericIdentifierDescriptor>(creator: NumericIdentifierCreator<TNumericIdentifierDescriptor>, preTestCallback?: () => void, postTestCallback?: () => void): void {
|
|
13
|
+
describe(isGTINCreator(creator) ? `${creator.identifierType}-${creator.length}` : creator.identifierType as string, () => {
|
|
8
14
|
testIdentifierCreatorCallback(preTestCallback);
|
|
9
15
|
|
|
10
16
|
const prefix = creator.prefix;
|
|
@@ -3,21 +3,17 @@ import { expect } from "vitest";
|
|
|
3
3
|
import {
|
|
4
4
|
ContentCharacterSets,
|
|
5
5
|
type IdentifierType,
|
|
6
|
+
type IdentifierTypeValidator,
|
|
6
7
|
type LeaderType,
|
|
7
|
-
type
|
|
8
|
-
type NumericIdentifierValidator,
|
|
8
|
+
type NumericIdentifierType,
|
|
9
9
|
type PrefixType
|
|
10
10
|
} from "../src";
|
|
11
11
|
import { validateIdentifierValidator } from "./identifier-validator";
|
|
12
12
|
|
|
13
|
-
export function validateNumericIdentifierValidator(validator:
|
|
13
|
+
export function validateNumericIdentifierValidator<TNumericIdentifierType extends NumericIdentifierType>(validator: IdentifierTypeValidator<TNumericIdentifierType>, identifierType: IdentifierType, prefixType: PrefixType, length: number, leaderType: LeaderType): void {
|
|
14
14
|
validateIdentifierValidator(validator, identifierType, prefixType, length);
|
|
15
15
|
|
|
16
16
|
expect(validator.leaderType).toBe(leaderType);
|
|
17
17
|
expect(validator.referenceCharacterSet).toBe(ContentCharacterSets.Numeric);
|
|
18
18
|
expect(validator.referenceCreator).toBe(NUMERIC_CREATOR);
|
|
19
|
-
|
|
20
|
-
if (isCreator) {
|
|
21
|
-
expect((validator as NumericIdentifierCreator).referenceCreator).toBe(NUMERIC_CREATOR);
|
|
22
|
-
}
|
|
23
19
|
}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { expect, test } from "vitest";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ContentCharacterSets,
|
|
4
|
+
isSerializableNumericIdentifierCreator,
|
|
5
|
+
type SerializableNumericIdentifierCreator
|
|
6
|
+
} from "../src";
|
|
3
7
|
import { testNonGTINNumericIdentifierCreator } from "./non-gtin-numeric-identifier-creator";
|
|
4
8
|
|
|
5
9
|
export function testSerializableNumericIdentifierCreator(creator: SerializableNumericIdentifierCreator): void {
|
|
6
|
-
testNonGTINNumericIdentifierCreator(creator,
|
|
10
|
+
testNonGTINNumericIdentifierCreator(creator, () => {
|
|
11
|
+
test("Mapping", () => {
|
|
12
|
+
expect(isSerializableNumericIdentifierCreator(creator)).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
}, () => {
|
|
7
15
|
test("Serialization", () => {
|
|
8
16
|
const identifier = creator.create(0, true);
|
|
9
17
|
const serial = "12345678";
|
package/test/validator.test.ts
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
import { describe, expect, test } from "vitest";
|
|
2
2
|
import {
|
|
3
3
|
ContentCharacterSets,
|
|
4
|
-
|
|
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,
|
|
4
|
+
type GTINBaseType,
|
|
18
5
|
GTINTypes,
|
|
6
|
+
type GTINValidator,
|
|
7
|
+
type IdentifierType,
|
|
19
8
|
IdentifierTypes,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
type IdentifierValidator,
|
|
10
|
+
IdentifierValidators,
|
|
11
|
+
isGTINValidator,
|
|
12
|
+
isGTINValidators,
|
|
13
|
+
isNonGTINNumericIdentifierValidator,
|
|
14
|
+
isNonNumericIdentifierValidator,
|
|
15
|
+
isNumericIdentifierValidator,
|
|
16
|
+
isSerializableNumericIdentifierValidator,
|
|
17
|
+
LeaderTypes
|
|
23
18
|
} from "../src";
|
|
24
19
|
import { validateGTINValidator } from "./gtin-validator.test";
|
|
25
20
|
import { validateNonGTINNumericIdentifierValidator } from "./non-gtin-numeric-identifier-validator";
|
|
@@ -27,26 +22,55 @@ import { validateNonNumericIdentifierValidator } from "./non-numeric-identifier-
|
|
|
27
22
|
import { validateSerializableNumericIdentifierValidator } from "./serializable-numeric-identifier-validator";
|
|
28
23
|
|
|
29
24
|
describe("Validators", () => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
function validateMapping(identifierType: IdentifierType, expectedIdentifierValidatorsOrValidator: Readonly<Record<GTINBaseType, GTINValidator>> | IdentifierValidator, ...isIdentifierValidatorTypes: Array<(validator: IdentifierValidator) => boolean>): void {
|
|
26
|
+
test(identifierType, () => {
|
|
27
|
+
const validatorsOrValidator = IdentifierValidators[identifierType];
|
|
28
|
+
|
|
29
|
+
expect(validatorsOrValidator).toBe(expectedIdentifierValidatorsOrValidator);
|
|
30
|
+
|
|
31
|
+
if (isGTINValidators(validatorsOrValidator)) {
|
|
32
|
+
for (const validator of Object.values(validatorsOrValidator)) {
|
|
33
|
+
for (const isIdentifierValidatorType of isIdentifierValidatorTypes) {
|
|
34
|
+
expect(isIdentifierValidatorType(validator)).toBe(true);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
for (const isIdentifierValidatorType of isIdentifierValidatorTypes) {
|
|
39
|
+
expect(isIdentifierValidatorType(validatorsOrValidator)).toBe(true);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe("Mapping", () => {
|
|
46
|
+
validateMapping(IdentifierTypes.GTIN, IdentifierValidators.GTIN, isNumericIdentifierValidator, isGTINValidator);
|
|
47
|
+
validateMapping(IdentifierTypes.GLN, IdentifierValidators.GLN, isNumericIdentifierValidator, isNonGTINNumericIdentifierValidator);
|
|
48
|
+
validateMapping(IdentifierTypes.SSCC, IdentifierValidators.SSCC, isNumericIdentifierValidator, isNonGTINNumericIdentifierValidator);
|
|
49
|
+
validateMapping(IdentifierTypes.GRAI, IdentifierValidators.GRAI, isNumericIdentifierValidator, isNonGTINNumericIdentifierValidator, isSerializableNumericIdentifierValidator);
|
|
50
|
+
validateMapping(IdentifierTypes.GIAI, IdentifierValidators.GIAI, isNonNumericIdentifierValidator);
|
|
51
|
+
validateMapping(IdentifierTypes.GSRN, IdentifierValidators.GSRN, isNumericIdentifierValidator, isNonGTINNumericIdentifierValidator);
|
|
52
|
+
validateMapping(IdentifierTypes.GDTI, IdentifierValidators.GDTI, isNumericIdentifierValidator, isNonGTINNumericIdentifierValidator, isSerializableNumericIdentifierValidator);
|
|
53
|
+
validateMapping(IdentifierTypes.GINC, IdentifierValidators.GINC, isNonNumericIdentifierValidator);
|
|
54
|
+
validateMapping(IdentifierTypes.GSIN, IdentifierValidators.GSIN, isNumericIdentifierValidator, isNonGTINNumericIdentifierValidator);
|
|
55
|
+
validateMapping(IdentifierTypes.GCN, IdentifierValidators.GCN, isNumericIdentifierValidator, isNonGTINNumericIdentifierValidator, isSerializableNumericIdentifierValidator);
|
|
56
|
+
validateMapping(IdentifierTypes.CPID, IdentifierValidators.CPID, isNonNumericIdentifierValidator);
|
|
57
|
+
validateMapping(IdentifierTypes.GMN, IdentifierValidators.GMN, isNonNumericIdentifierValidator);
|
|
34
58
|
});
|
|
35
59
|
|
|
36
60
|
test("Structure", () => {
|
|
37
|
-
validateGTINValidator(
|
|
38
|
-
validateGTINValidator(
|
|
39
|
-
validateGTINValidator(
|
|
40
|
-
validateNonGTINNumericIdentifierValidator(
|
|
41
|
-
validateNonGTINNumericIdentifierValidator(
|
|
42
|
-
validateSerializableNumericIdentifierValidator(
|
|
43
|
-
validateNonNumericIdentifierValidator(
|
|
44
|
-
validateNonGTINNumericIdentifierValidator(
|
|
45
|
-
validateSerializableNumericIdentifierValidator(
|
|
46
|
-
validateNonNumericIdentifierValidator(
|
|
47
|
-
validateNonGTINNumericIdentifierValidator(
|
|
48
|
-
validateSerializableNumericIdentifierValidator(
|
|
49
|
-
validateNonNumericIdentifierValidator(
|
|
50
|
-
validateNonNumericIdentifierValidator(
|
|
61
|
+
validateGTINValidator(IdentifierValidators.GTIN[GTINTypes.GTIN13], false, GTINTypes.GTIN13);
|
|
62
|
+
validateGTINValidator(IdentifierValidators.GTIN[GTINTypes.GTIN12], false, GTINTypes.GTIN12);
|
|
63
|
+
validateGTINValidator(IdentifierValidators.GTIN[GTINTypes.GTIN8], false, GTINTypes.GTIN8);
|
|
64
|
+
validateNonGTINNumericIdentifierValidator(IdentifierValidators.GLN, false, IdentifierTypes.GLN, 13, LeaderTypes.None);
|
|
65
|
+
validateNonGTINNumericIdentifierValidator(IdentifierValidators.SSCC, false, IdentifierTypes.SSCC, 18, LeaderTypes.ExtensionDigit);
|
|
66
|
+
validateSerializableNumericIdentifierValidator(IdentifierValidators.GRAI, false, IdentifierTypes.GRAI, 13, LeaderTypes.None, 16, ContentCharacterSets.AI82);
|
|
67
|
+
validateNonNumericIdentifierValidator(IdentifierValidators.GIAI, false, IdentifierTypes.GIAI, 30, ContentCharacterSets.AI82, false);
|
|
68
|
+
validateNonGTINNumericIdentifierValidator(IdentifierValidators.GSRN, false, IdentifierTypes.GSRN, 18, LeaderTypes.None);
|
|
69
|
+
validateSerializableNumericIdentifierValidator(IdentifierValidators.GDTI, false, IdentifierTypes.GDTI, 13, LeaderTypes.None, 17, ContentCharacterSets.AI82);
|
|
70
|
+
validateNonNumericIdentifierValidator(IdentifierValidators.GINC, false, IdentifierTypes.GINC, 30, ContentCharacterSets.AI82, false);
|
|
71
|
+
validateNonGTINNumericIdentifierValidator(IdentifierValidators.GSIN, false, IdentifierTypes.GSIN, 17, LeaderTypes.None);
|
|
72
|
+
validateSerializableNumericIdentifierValidator(IdentifierValidators.GCN, false, IdentifierTypes.GCN, 13, LeaderTypes.None, 12, ContentCharacterSets.Numeric);
|
|
73
|
+
validateNonNumericIdentifierValidator(IdentifierValidators.CPID, false, IdentifierTypes.CPID, 30, ContentCharacterSets.AI39, false);
|
|
74
|
+
validateNonNumericIdentifierValidator(IdentifierValidators.GMN, false, IdentifierTypes.GMN, 25, ContentCharacterSets.AI82, true);
|
|
51
75
|
});
|
|
52
76
|
});
|