@aidc-toolkit/gs1 1.0.24-beta → 1.0.26-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/abstract-identifier-creator.d.ts +75 -0
- package/dist/abstract-identifier-creator.d.ts.map +1 -0
- package/dist/abstract-identifier-creator.js +56 -0
- package/dist/abstract-identifier-creator.js.map +1 -0
- package/dist/abstract-identifier-validator.d.ts +95 -0
- package/dist/abstract-identifier-validator.d.ts.map +1 -0
- package/dist/abstract-identifier-validator.js +123 -0
- package/dist/abstract-identifier-validator.js.map +1 -0
- package/dist/abstract-numeric-identifier-creator.d.ts +92 -0
- package/dist/abstract-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/abstract-numeric-identifier-creator.js +137 -0
- package/dist/abstract-numeric-identifier-creator.js.map +1 -0
- package/dist/abstract-numeric-identifier-validator.d.ts +35 -0
- package/dist/abstract-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/abstract-numeric-identifier-validator.js +61 -0
- package/dist/abstract-numeric-identifier-validator.js.map +1 -0
- package/dist/character-set.d.ts +27 -0
- package/dist/character-set.d.ts.map +1 -0
- package/dist/character-set.js +50 -0
- package/dist/character-set.js.map +1 -0
- package/dist/check.d.ts +81 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +218 -0
- package/dist/check.js.map +1 -0
- package/dist/content-character-set.d.ts +26 -0
- package/dist/content-character-set.d.ts.map +1 -0
- package/dist/content-character-set.js +18 -0
- package/dist/content-character-set.js.map +1 -0
- package/dist/creators.d.ts +81 -0
- package/dist/creators.d.ts.map +1 -0
- package/dist/creators.js +62 -0
- package/dist/creators.js.map +1 -0
- package/dist/descriptors.d.ts +96 -0
- package/dist/descriptors.d.ts.map +1 -0
- package/dist/descriptors.js +266 -0
- package/dist/descriptors.js.map +1 -0
- package/dist/gtin-creator.d.ts +69 -0
- package/dist/gtin-creator.d.ts.map +1 -0
- package/dist/gtin-creator.js +159 -0
- package/dist/gtin-creator.js.map +1 -0
- package/dist/gtin-descriptor.d.ts +17 -0
- package/dist/gtin-descriptor.d.ts.map +1 -0
- package/dist/gtin-descriptor.js +2 -0
- package/dist/gtin-descriptor.js.map +1 -0
- package/dist/gtin-type.d.ts +39 -0
- package/dist/gtin-type.d.ts.map +1 -0
- package/dist/gtin-type.js +31 -0
- package/dist/gtin-type.js.map +1 -0
- package/dist/gtin-validator.d.ts +191 -0
- package/dist/gtin-validator.d.ts.map +1 -0
- package/dist/gtin-validator.js +450 -0
- package/dist/gtin-validator.js.map +1 -0
- package/dist/identifier-creator.d.ts +31 -0
- package/dist/identifier-creator.d.ts.map +1 -0
- package/dist/identifier-creator.js +2 -0
- package/dist/identifier-creator.js.map +1 -0
- package/dist/identifier-descriptor.d.ts +27 -0
- package/dist/identifier-descriptor.d.ts.map +1 -0
- package/dist/identifier-descriptor.js +2 -0
- package/dist/identifier-descriptor.js.map +1 -0
- package/dist/identifier-type.d.ts +62 -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 +53 -0
- package/dist/identifier-validator.d.ts.map +1 -0
- package/dist/identifier-validator.js +2 -0
- package/dist/identifier-validator.js.map +1 -0
- package/dist/index.d.ts +52 -1588
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -4541
- package/dist/index.js.map +1 -1
- package/dist/locale/en/locale-resources.d.ts +42 -0
- package/dist/locale/en/locale-resources.d.ts.map +1 -0
- package/dist/locale/en/locale-resources.js +41 -0
- package/dist/locale/en/locale-resources.js.map +1 -0
- package/dist/locale/fr/locale-resources.d.ts +42 -0
- package/dist/locale/fr/locale-resources.d.ts.map +1 -0
- package/dist/locale/fr/locale-resources.js +41 -0
- package/dist/locale/fr/locale-resources.js.map +1 -0
- package/dist/locale/i18n.d.ts +27 -0
- package/dist/locale/i18n.d.ts.map +1 -0
- package/dist/locale/i18n.js +36 -0
- package/dist/locale/i18n.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-creator.d.ts +24 -0
- package/dist/non-gtin-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-creator.js +23 -0
- package/dist/non-gtin-numeric-identifier-creator.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-descriptor.d.ts +22 -0
- package/dist/non-gtin-numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-descriptor.js +2 -0
- package/dist/non-gtin-numeric-identifier-descriptor.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-type.d.ts +7 -0
- package/dist/non-gtin-numeric-identifier-type.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-type.js +2 -0
- package/dist/non-gtin-numeric-identifier-type.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-validator.d.ts +17 -0
- package/dist/non-gtin-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-validator.js +17 -0
- package/dist/non-gtin-numeric-identifier-validator.js.map +1 -0
- package/dist/non-numeric-identifier-creator.d.ts +45 -0
- package/dist/non-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/non-numeric-identifier-creator.js +84 -0
- package/dist/non-numeric-identifier-creator.js.map +1 -0
- package/dist/non-numeric-identifier-descriptor.d.ts +26 -0
- package/dist/non-numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/non-numeric-identifier-descriptor.js +2 -0
- package/dist/non-numeric-identifier-descriptor.js.map +1 -0
- package/dist/non-numeric-identifier-type.d.ts +7 -0
- package/dist/non-numeric-identifier-type.d.ts.map +1 -0
- package/dist/non-numeric-identifier-type.js +2 -0
- package/dist/non-numeric-identifier-type.js.map +1 -0
- package/dist/non-numeric-identifier-validator.d.ts +49 -0
- package/dist/non-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/non-numeric-identifier-validator.js +69 -0
- package/dist/non-numeric-identifier-validator.js.map +1 -0
- package/dist/numeric-identifier-creator.d.ts +53 -0
- package/dist/numeric-identifier-creator.d.ts.map +1 -0
- package/dist/numeric-identifier-creator.js +2 -0
- package/dist/numeric-identifier-creator.js.map +1 -0
- package/dist/numeric-identifier-descriptor.d.ts +21 -0
- package/dist/numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/numeric-identifier-descriptor.js +2 -0
- package/dist/numeric-identifier-descriptor.js.map +1 -0
- package/dist/numeric-identifier-type.d.ts +31 -0
- package/dist/numeric-identifier-type.d.ts.map +1 -0
- package/dist/numeric-identifier-type.js +18 -0
- package/dist/numeric-identifier-type.js.map +1 -0
- package/dist/numeric-identifier-validator.d.ts +24 -0
- package/dist/numeric-identifier-validator.d.ts.map +1 -0
- package/dist/numeric-identifier-validator.js +2 -0
- package/dist/numeric-identifier-validator.js.map +1 -0
- package/dist/prefix-manager.d.ts +232 -0
- package/dist/prefix-manager.d.ts.map +1 -0
- package/dist/prefix-manager.js +334 -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 +26 -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 +70 -0
- package/dist/prefix-validator.d.ts.map +1 -0
- package/dist/prefix-validator.js +208 -0
- package/dist/prefix-validator.js.map +1 -0
- package/dist/serializable-numeric-identifier-creator.d.ts +76 -0
- package/dist/serializable-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-creator.js +107 -0
- package/dist/serializable-numeric-identifier-creator.js.map +1 -0
- package/dist/serializable-numeric-identifier-descriptor.d.ts +26 -0
- package/dist/serializable-numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-descriptor.js +2 -0
- package/dist/serializable-numeric-identifier-descriptor.js.map +1 -0
- package/dist/serializable-numeric-identifier-type.d.ts +6 -0
- package/dist/serializable-numeric-identifier-type.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-type.js +2 -0
- package/dist/serializable-numeric-identifier-type.js.map +1 -0
- package/dist/serializable-numeric-identifier-validator.d.ts +56 -0
- package/dist/serializable-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-validator.js +77 -0
- package/dist/serializable-numeric-identifier-validator.js.map +1 -0
- package/dist/validators.d.ts +96 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +140 -0
- package/dist/validators.js.map +1 -0
- package/package.json +12 -8
- 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 +9 -9
- 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 +10 -9
- package/src/gtin-descriptor.ts +18 -0
- package/src/gtin-type.ts +50 -0
- package/src/gtin-validator.ts +40 -64
- package/src/identifier-creator.ts +12 -76
- 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 +44 -19
- package/src/locale/en/locale-resources.ts +0 -1
- package/src/locale/fr/locale-resources.ts +0 -1
- package/src/locale/i18n.ts +3 -3
- package/src/locale/i18next.d.ts +1 -1
- package/src/non-gtin-numeric-identifier-creator.ts +7 -13
- 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 +9 -19
- 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 +17 -55
- 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 +94 -152
- package/src/prefix-provider.ts +3 -3
- package/src/prefix-type.ts +6 -1
- package/src/prefix-validator.ts +143 -81
- package/src/serializable-numeric-identifier-creator.ts +6 -16
- 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 +18 -46
- package/src/validators.ts +203 -0
- package/test/check.test.ts +1 -1
- package/test/creator.test.ts +5 -7
- package/test/gtin-creator.ts +6 -2
- package/test/gtin-validator.test.ts +7 -10
- package/test/identifier-creator.ts +6 -5
- package/test/identifier-validator.ts +2 -2
- package/test/non-gtin-numeric-identifier-creator.ts +9 -93
- package/test/non-gtin-numeric-identifier-validator.ts +3 -3
- package/test/non-numeric-identifier-creator.ts +93 -0
- package/test/non-numeric-identifier-validator.ts +3 -3
- package/test/numeric-identifier-creator.ts +11 -5
- package/test/numeric-identifier-validator.ts +5 -9
- package/test/prefix-manager.test.ts +2 -2
- package/test/serializable-numeric-identifier-creator.ts +11 -3
- package/test/serializable-numeric-identifier-validator.ts +3 -3
- package/test/setup.ts +1 -1
- package/test/sparse.test.ts +1 -1
- package/test/utility.ts +1 -1
- package/test/validator.test.ts +64 -40
- package/test/variable-measure-rcn.test.ts +1 -1
- package/tsconfig-config.json +4 -0
- package/tsconfig-src.json +8 -0
- package/tsconfig-test.json +9 -0
- package/tsconfig.json +12 -1
- package/tsup.config.ts +3 -2
- package/dist/index.cjs +0 -4624
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -1588
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ContentCharacterSet } from "./content-character-set.js";
|
|
2
|
+
import type { IdentifierType } from "./identifier-type.js";
|
|
3
|
+
import type { PrefixType } from "./prefix-type.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Identifier descriptor. Instantiations of this type are used to parameterize validators and creators.
|
|
7
|
+
*/
|
|
8
|
+
export interface IdentifierDescriptor {
|
|
9
|
+
/**
|
|
10
|
+
* Identifier type. Per the GS1 General Specifications, the identifier type determines the remaining properties.
|
|
11
|
+
*/
|
|
12
|
+
readonly identifierType: IdentifierType;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Prefix type supported by the identifier type. For all identifier types except the GTIN, this is a GS1 Company
|
|
16
|
+
* Prefix. For the GTIN, the prefix type determines the length.
|
|
17
|
+
*/
|
|
18
|
+
readonly prefixType: PrefixType;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Length. For numeric identifier types, the length is fixed; for non-numeric identifier types, the length is the
|
|
22
|
+
* maximum.
|
|
23
|
+
*/
|
|
24
|
+
readonly length: number;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Reference character set.
|
|
28
|
+
*/
|
|
29
|
+
readonly referenceCharacterSet: ContentCharacterSet;
|
|
30
|
+
}
|
package/src/identifier-type.ts
CHANGED
|
@@ -63,7 +63,12 @@ export const IdentifierTypes = {
|
|
|
63
63
|
GMN: "GMN"
|
|
64
64
|
} as const;
|
|
65
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Identifier type key.
|
|
68
|
+
*/
|
|
69
|
+
export type IdentifierTypeKey = keyof typeof IdentifierTypes;
|
|
70
|
+
|
|
66
71
|
/**
|
|
67
72
|
* Identifier type.
|
|
68
73
|
*/
|
|
69
|
-
export type IdentifierType = typeof IdentifierTypes[
|
|
74
|
+
export type IdentifierType = typeof IdentifierTypes[IdentifierTypeKey];
|
|
@@ -1,69 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
NUMERIC_CREATOR,
|
|
4
|
-
type StringValidation,
|
|
5
|
-
type StringValidator
|
|
6
|
-
} from "@aidc-toolkit/utility";
|
|
7
|
-
import { AI39_CREATOR, AI82_CREATOR } from "./character-set";
|
|
8
|
-
import type { IdentifierType } from "./identifier-type";
|
|
9
|
-
import type { PrefixType } from "./prefix-type";
|
|
10
|
-
import { PrefixValidator } from "./prefix-validator";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Character sets supported by the reference portion of an identifier or the serial component of a numeric identifier.
|
|
14
|
-
*/
|
|
15
|
-
export const ContentCharacterSets = {
|
|
16
|
-
/**
|
|
17
|
-
* Numeric.
|
|
18
|
-
*/
|
|
19
|
-
Numeric: "Numeric",
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* GS1 AI encodable character set 82.
|
|
23
|
-
*/
|
|
24
|
-
AI82: "AI82",
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* GS1 AI encodable character set 39.
|
|
28
|
-
*/
|
|
29
|
-
AI39: "AI39"
|
|
30
|
-
} as const;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Content character set.
|
|
34
|
-
*/
|
|
35
|
-
export type ContentCharacterSet = typeof ContentCharacterSets[keyof typeof ContentCharacterSets];
|
|
1
|
+
import type { CharacterSetCreator, StringValidation, StringValidator } from "@aidc-toolkit/utility";
|
|
2
|
+
import type { IdentifierDescriptor } from "./identifier-descriptor.js";
|
|
36
3
|
|
|
37
4
|
/**
|
|
38
5
|
* Identifier validation parameters.
|
|
39
6
|
*/
|
|
40
7
|
export interface IdentifierValidation extends StringValidation {
|
|
41
|
-
/**
|
|
42
|
-
* Position offset within a larger string. Strings are sometimes composed of multiple substrings; this parameter
|
|
43
|
-
* ensures that the error notes the proper position in the string.
|
|
44
|
-
*/
|
|
45
|
-
positionOffset?: number | undefined;
|
|
46
8
|
}
|
|
47
9
|
|
|
48
10
|
/**
|
|
49
11
|
* Identifier validator. Validates an identifier against its definition in section 3 of the {@link
|
|
50
|
-
* https://
|
|
12
|
+
* https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}.
|
|
13
|
+
*
|
|
14
|
+
* @template TIdentifierDescriptor
|
|
15
|
+
* Identifier descriptor type.
|
|
51
16
|
*
|
|
52
17
|
* @template TIdentifierValidation
|
|
53
18
|
* Identifier validation type.
|
|
54
19
|
*/
|
|
55
|
-
export interface IdentifierValidator<TIdentifierValidation extends IdentifierValidation = IdentifierValidation> extends StringValidator<TIdentifierValidation> {
|
|
20
|
+
export interface IdentifierValidator<TIdentifierDescriptor extends IdentifierDescriptor = IdentifierDescriptor, TIdentifierValidation extends IdentifierValidation = IdentifierValidation> extends StringValidator<TIdentifierValidation> {
|
|
56
21
|
/**
|
|
57
22
|
* Get the identifier type. Per the GS1 General Specifications, the identifier type determines the remaining
|
|
58
23
|
* properties.
|
|
59
24
|
*/
|
|
60
|
-
get identifierType():
|
|
25
|
+
get identifierType(): TIdentifierDescriptor["identifierType"];
|
|
61
26
|
|
|
62
27
|
/**
|
|
63
|
-
* Get the prefix type supported by the identifier type. For all identifier types except the GTIN, this is
|
|
64
|
-
*
|
|
28
|
+
* Get the prefix type supported by the identifier type. For all identifier types except the GTIN, this is a GS1
|
|
29
|
+
* Company Prefix. For the GTIN, the prefix type determines the length.
|
|
65
30
|
*/
|
|
66
|
-
get prefixType():
|
|
31
|
+
get prefixType(): TIdentifierDescriptor["prefixType"];
|
|
67
32
|
|
|
68
33
|
/**
|
|
69
34
|
* Get the length. For numeric identifier types, the length is fixed; for alphanumeric identifier types, the length
|
|
@@ -74,7 +39,7 @@ export interface IdentifierValidator<TIdentifierValidation extends IdentifierVal
|
|
|
74
39
|
/**
|
|
75
40
|
* Get the reference character set.
|
|
76
41
|
*/
|
|
77
|
-
get referenceCharacterSet():
|
|
42
|
+
get referenceCharacterSet(): TIdentifierDescriptor["referenceCharacterSet"];
|
|
78
43
|
|
|
79
44
|
/**
|
|
80
45
|
* Get the reference creator.
|
|
@@ -92,144 +57,3 @@ export interface IdentifierValidator<TIdentifierValidation extends IdentifierVal
|
|
|
92
57
|
*/
|
|
93
58
|
validate: (identifier: string, validation?: TIdentifierValidation) => void;
|
|
94
59
|
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Abstract identifier validator. Implements common functionality for an identifier validator.
|
|
98
|
-
*/
|
|
99
|
-
export abstract class AbstractIdentifierValidator<TIdentifierValidation extends IdentifierValidation = IdentifierValidation> implements IdentifierValidator<TIdentifierValidation> {
|
|
100
|
-
private static readonly CHARACTER_SET_CREATORS: Record<ContentCharacterSet, CharacterSetCreator> = {
|
|
101
|
-
[ContentCharacterSets.Numeric]: NUMERIC_CREATOR,
|
|
102
|
-
[ContentCharacterSets.AI82]: AI82_CREATOR,
|
|
103
|
-
[ContentCharacterSets.AI39]: AI39_CREATOR
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Identifier type.
|
|
108
|
-
*/
|
|
109
|
-
private readonly _identifierType: IdentifierType;
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Prefix type.
|
|
113
|
-
*/
|
|
114
|
-
private readonly _prefixType: PrefixType;
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Length.
|
|
118
|
-
*/
|
|
119
|
-
private readonly _length: number;
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Reference character set.
|
|
123
|
-
*/
|
|
124
|
-
private readonly _referenceCharacterSet: ContentCharacterSet;
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Reference creator.
|
|
128
|
-
*/
|
|
129
|
-
private readonly _referenceCreator: CharacterSetCreator;
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Get the character set creator for a character set.
|
|
133
|
-
*
|
|
134
|
-
* @param characterSet
|
|
135
|
-
* Character set.
|
|
136
|
-
*
|
|
137
|
-
* @returns
|
|
138
|
-
* Character set creator.
|
|
139
|
-
*/
|
|
140
|
-
protected static creatorFor(characterSet: ContentCharacterSet): CharacterSetCreator {
|
|
141
|
-
return AbstractIdentifierValidator.CHARACTER_SET_CREATORS[characterSet];
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Constructor.
|
|
146
|
-
*
|
|
147
|
-
* @param identifierType
|
|
148
|
-
* Identifier type.
|
|
149
|
-
*
|
|
150
|
-
* @param prefixType
|
|
151
|
-
* Prefix type.
|
|
152
|
-
*
|
|
153
|
-
* @param length
|
|
154
|
-
* Length.
|
|
155
|
-
*
|
|
156
|
-
* @param referenceCharacterSet
|
|
157
|
-
* Reference character set.
|
|
158
|
-
*/
|
|
159
|
-
protected constructor(identifierType: IdentifierType, prefixType: PrefixType, length: number, referenceCharacterSet: ContentCharacterSet) {
|
|
160
|
-
this._identifierType = identifierType;
|
|
161
|
-
this._prefixType = prefixType;
|
|
162
|
-
this._length = length;
|
|
163
|
-
this._referenceCharacterSet = referenceCharacterSet;
|
|
164
|
-
this._referenceCreator = AbstractIdentifierValidator.creatorFor(referenceCharacterSet);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* @inheritDoc
|
|
169
|
-
*/
|
|
170
|
-
get identifierType(): IdentifierType {
|
|
171
|
-
return this._identifierType;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* @inheritDoc
|
|
176
|
-
*/
|
|
177
|
-
get prefixType(): PrefixType {
|
|
178
|
-
return this._prefixType;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* @inheritDoc
|
|
183
|
-
*/
|
|
184
|
-
get length(): number {
|
|
185
|
-
return this._length;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* @inheritDoc
|
|
190
|
-
*/
|
|
191
|
-
get referenceCharacterSet(): ContentCharacterSet {
|
|
192
|
-
return this._referenceCharacterSet;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* @inheritDoc
|
|
197
|
-
*/
|
|
198
|
-
get referenceCreator(): CharacterSetCreator {
|
|
199
|
-
return this._referenceCreator;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Pad an identifier on the left with zero-value character for validation purposes. This is done to align an
|
|
204
|
-
* identifier with a position offset for any error message that may be thrown by the reference validator.
|
|
205
|
-
*
|
|
206
|
-
* @param identifier
|
|
207
|
-
* Identifier.
|
|
208
|
-
*
|
|
209
|
-
* @param validation
|
|
210
|
-
* Identifier validation parameters.
|
|
211
|
-
*
|
|
212
|
-
* @returns
|
|
213
|
-
* Padded identifier.
|
|
214
|
-
*/
|
|
215
|
-
protected padIdentifier(identifier: string, validation: IdentifierValidation | undefined): string {
|
|
216
|
-
// Identifier is returned as is if position offset is undefined.
|
|
217
|
-
return validation?.positionOffset === undefined ? identifier : this.referenceCreator.character(0).repeat(validation.positionOffset).concat(identifier);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Validate the prefix within an identifier.
|
|
222
|
-
*
|
|
223
|
-
* @param partialIdentifier
|
|
224
|
-
* Partial identifier.
|
|
225
|
-
*
|
|
226
|
-
* @param positionOffset
|
|
227
|
-
* Position offset within a larger string.
|
|
228
|
-
*/
|
|
229
|
-
protected validatePrefix(partialIdentifier: string, positionOffset?: number): void {
|
|
230
|
-
// Delegate to prefix validator with support for U.P.C. Company Prefix but not GS1-8 Prefix.
|
|
231
|
-
PrefixValidator.validate(this.prefixType, true, false, partialIdentifier, true, this.referenceCharacterSet === ContentCharacterSets.Numeric, positionOffset);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
abstract validate(identifier: string, validation?: TIdentifierValidation): void;
|
|
235
|
-
}
|
package/src/index.ts
CHANGED
|
@@ -14,22 +14,47 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
export * from "./locale/i18n";
|
|
18
|
-
|
|
19
|
-
export * from "./
|
|
20
|
-
|
|
21
|
-
export * from "./
|
|
22
|
-
|
|
23
|
-
export * from "./
|
|
24
|
-
export * from "./
|
|
25
|
-
export * from "./
|
|
26
|
-
|
|
27
|
-
export * from "./
|
|
28
|
-
|
|
29
|
-
export * from "./identifier-
|
|
30
|
-
export * from "./numeric-identifier-
|
|
31
|
-
export * from "./gtin-
|
|
32
|
-
export * from "./non-gtin-numeric-identifier-
|
|
33
|
-
export * from "./serializable-numeric-identifier-
|
|
34
|
-
export * from "./non-numeric-identifier-
|
|
35
|
-
|
|
17
|
+
export * from "./locale/i18n.js";
|
|
18
|
+
|
|
19
|
+
export * from "./character-set.js";
|
|
20
|
+
|
|
21
|
+
export * from "./check.js";
|
|
22
|
+
|
|
23
|
+
export * from "./prefix-type.js";
|
|
24
|
+
export type * from "./prefix-provider.js";
|
|
25
|
+
export * from "./prefix-validator.js";
|
|
26
|
+
|
|
27
|
+
export * from "./content-character-set.js";
|
|
28
|
+
|
|
29
|
+
export * from "./identifier-type.js";
|
|
30
|
+
export * from "./numeric-identifier-type.js";
|
|
31
|
+
export * from "./gtin-type.js";
|
|
32
|
+
export type * from "./non-gtin-numeric-identifier-type.js";
|
|
33
|
+
export type * from "./serializable-numeric-identifier-type.js";
|
|
34
|
+
export type * from "./non-numeric-identifier-type.js";
|
|
35
|
+
|
|
36
|
+
export type * from "./identifier-descriptor.js";
|
|
37
|
+
export type * from "./numeric-identifier-descriptor.js";
|
|
38
|
+
export type * from "./gtin-descriptor.js";
|
|
39
|
+
export type * from "./non-gtin-numeric-identifier-descriptor.js";
|
|
40
|
+
export type * from "./serializable-numeric-identifier-descriptor.js";
|
|
41
|
+
export type * from "./non-numeric-identifier-descriptor.js";
|
|
42
|
+
export * from "./descriptors.js";
|
|
43
|
+
|
|
44
|
+
export type * from "./identifier-validator.js";
|
|
45
|
+
export type * from "./numeric-identifier-validator.js";
|
|
46
|
+
export { GTINLevels, type GTINLevelKey, type GTINLevel, type RCNReference, GTINValidator } from "./gtin-validator.js";
|
|
47
|
+
export * from "./non-gtin-numeric-identifier-validator.js";
|
|
48
|
+
export * from "./serializable-numeric-identifier-validator.js";
|
|
49
|
+
export * from "./non-numeric-identifier-validator.js";
|
|
50
|
+
export * from "./validators.js";
|
|
51
|
+
|
|
52
|
+
export type * from "./identifier-creator.js";
|
|
53
|
+
export type * from "./numeric-identifier-creator.js";
|
|
54
|
+
export * from "./gtin-creator.js";
|
|
55
|
+
export * from "./non-gtin-numeric-identifier-creator.js";
|
|
56
|
+
export * from "./serializable-numeric-identifier-creator.js";
|
|
57
|
+
export * from "./non-numeric-identifier-creator.js";
|
|
58
|
+
export * from "./creators.js";
|
|
59
|
+
|
|
60
|
+
export * from "./prefix-manager.js";
|
|
@@ -30,7 +30,6 @@ export default {
|
|
|
30
30
|
gs1CompanyPrefix: "GS1 Company Prefix",
|
|
31
31
|
upcCompanyPrefix: "U.P.C. Company Prefix",
|
|
32
32
|
gs18Prefix: "GS1-8 Prefix",
|
|
33
|
-
invalidPrefixType: "Invalid prefix type",
|
|
34
33
|
gs1CompanyPrefixCantStartWith0: "GS1 Company Prefix can't start with \"0\"",
|
|
35
34
|
gs1CompanyPrefixCantStartWith00000: "GS1 Company Prefix can't start with \"00000\"",
|
|
36
35
|
gs1CompanyPrefixCantStartWith000000: "GS1 Company Prefix can't start with \"000000\"",
|
|
@@ -30,7 +30,6 @@ export default {
|
|
|
30
30
|
gs1CompanyPrefix: "Préfixe de l'entreprise GS1",
|
|
31
31
|
upcCompanyPrefix: "Préfixe de l'entreprise U.P.C.",
|
|
32
32
|
gs18Prefix: "Préfixe GS1-8",
|
|
33
|
-
invalidPrefixType: "Type de préfixe invalide",
|
|
34
33
|
gs1CompanyPrefixCantStartWith0: "Le préfixe de l'entreprise GS1 ne peut pas commencer par \"0\"",
|
|
35
34
|
gs1CompanyPrefixCantStartWith00000: "Le préfixe de l'entreprise GS1 ne peut pas commencer par \"00000\"",
|
|
36
35
|
gs1CompanyPrefixCantStartWith000000: "Le préfixe de l'entreprise GS1 ne peut pas commencer par \"000000\"",
|
package/src/locale/i18n.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { i18nCoreInit, type I18nEnvironment } from "@aidc-toolkit/core";
|
|
2
2
|
import { i18nUtilityInit, utilityResources } from "@aidc-toolkit/utility";
|
|
3
3
|
import i18next, { type i18n, type Resource } from "i18next";
|
|
4
|
-
import enLocaleResources from "./en/locale-resources";
|
|
5
|
-
import frLocaleResources from "./fr/locale-resources";
|
|
4
|
+
import enLocaleResources from "./en/locale-resources.js";
|
|
5
|
+
import frLocaleResources from "./fr/locale-resources.js";
|
|
6
6
|
|
|
7
7
|
export const gs1NS = "aidct_gs1";
|
|
8
8
|
|
|
@@ -23,7 +23,7 @@ export const gs1Resources: Resource = {
|
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
// Explicit type is necessary
|
|
26
|
+
// Explicit type is necessary because type can't be inferred without additional references.
|
|
27
27
|
export const i18nextGS1: i18n = i18next.createInstance();
|
|
28
28
|
|
|
29
29
|
/**
|
package/src/locale/i18next.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Mixin } from "ts-mixer";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import type {
|
|
2
|
+
import { AbstractNumericIdentifierCreator } from "./abstract-numeric-identifier-creator.js";
|
|
3
|
+
import type { NonGTINNumericIdentifierType } from "./non-gtin-numeric-identifier-type.js";
|
|
4
|
+
import { NonGTINNumericIdentifierValidator } from "./non-gtin-numeric-identifier-validator.js";
|
|
5
|
+
import type { PrefixProvider } from "./prefix-provider.js";
|
|
6
|
+
import type { SerializableNumericIdentifierType } from "./serializable-numeric-identifier-type.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Non-GTIN numeric identifier creator.
|
|
@@ -18,15 +18,9 @@ export class NonGTINNumericIdentifierCreator extends Mixin(NonGTINNumericIdentif
|
|
|
18
18
|
*
|
|
19
19
|
* @param identifierType
|
|
20
20
|
* Identifier type.
|
|
21
|
-
*
|
|
22
|
-
* @param length
|
|
23
|
-
* Length.
|
|
24
|
-
*
|
|
25
|
-
* @param leaderType
|
|
26
|
-
* Leader type.
|
|
27
21
|
*/
|
|
28
|
-
constructor(prefixProvider: PrefixProvider, identifierType:
|
|
29
|
-
super(identifierType
|
|
22
|
+
constructor(prefixProvider: PrefixProvider, identifierType: Exclude<NonGTINNumericIdentifierType, SerializableNumericIdentifierType>) {
|
|
23
|
+
super(identifierType);
|
|
30
24
|
|
|
31
25
|
this.init(prefixProvider, prefixProvider.gs1CompanyPrefix);
|
|
32
26
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { NonGTINNumericIdentifierType } from "./non-gtin-numeric-identifier-type.js";
|
|
2
|
+
import type { NumericIdentifierDescriptor } from "./numeric-identifier-descriptor.js";
|
|
3
|
+
import type { LeaderType, LeaderTypes } from "./numeric-identifier-type.js";
|
|
4
|
+
import type { PrefixTypes } from "./prefix-type.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Non-GTIN numeric identifier descriptor.
|
|
8
|
+
*/
|
|
9
|
+
export interface NonGTINNumericIdentifierDescriptor extends NumericIdentifierDescriptor {
|
|
10
|
+
/**
|
|
11
|
+
* @inheritDoc
|
|
12
|
+
*/
|
|
13
|
+
readonly identifierType: NonGTINNumericIdentifierType;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @inheritDoc
|
|
17
|
+
*/
|
|
18
|
+
readonly prefixType: typeof PrefixTypes.GS1CompanyPrefix;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @inheritDoc
|
|
22
|
+
*/
|
|
23
|
+
readonly leaderType: Exclude<LeaderType, typeof LeaderTypes.IndicatorDigit>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { IdentifierTypes } from "./identifier-type.js";
|
|
2
|
+
import type { NumericIdentifierType } from "./numeric-identifier-type.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Non-GTIN numeric identifier type.
|
|
6
|
+
*/
|
|
7
|
+
export type NonGTINNumericIdentifierType = Exclude<NumericIdentifierType, typeof IdentifierTypes.GTIN>;
|
|
@@ -1,54 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type NumericIdentifierType
|
|
7
|
-
} from "./numeric-identifier-validator";
|
|
8
|
-
import { PrefixTypes } from "./prefix-type";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Non-GTIN numeric identifier type.
|
|
12
|
-
*/
|
|
13
|
-
export type NonGTINNumericIdentifierType = Exclude<NumericIdentifierType, typeof IdentifierTypes.GTIN>;
|
|
1
|
+
import { AbstractNumericIdentifierValidator } from "./abstract-numeric-identifier-validator.js";
|
|
2
|
+
import { IdentifierDescriptors } from "./descriptors.js";
|
|
3
|
+
import type { NonGTINNumericIdentifierDescriptor } from "./non-gtin-numeric-identifier-descriptor.js";
|
|
4
|
+
import type { NonGTINNumericIdentifierType } from "./non-gtin-numeric-identifier-type.js";
|
|
5
|
+
import type { SerializableNumericIdentifierType } from "./serializable-numeric-identifier-type.js";
|
|
14
6
|
|
|
15
7
|
/**
|
|
16
8
|
* Non-GTIN numeric identifier validator.
|
|
17
9
|
*/
|
|
18
|
-
export class NonGTINNumericIdentifierValidator extends AbstractNumericIdentifierValidator {
|
|
10
|
+
export class NonGTINNumericIdentifierValidator extends AbstractNumericIdentifierValidator<NonGTINNumericIdentifierDescriptor> {
|
|
19
11
|
/**
|
|
20
12
|
* Constructor.
|
|
21
13
|
*
|
|
22
14
|
* @param identifierType
|
|
23
15
|
* Identifier type.
|
|
24
|
-
*
|
|
25
|
-
* @param length
|
|
26
|
-
* Length.
|
|
27
|
-
*
|
|
28
|
-
* @param leaderType
|
|
29
|
-
* Leader type.
|
|
30
16
|
*/
|
|
31
|
-
constructor(identifierType:
|
|
32
|
-
super(identifierType
|
|
17
|
+
constructor(identifierType: Exclude<NonGTINNumericIdentifierType, SerializableNumericIdentifierType>) {
|
|
18
|
+
super(IdentifierDescriptors[identifierType]);
|
|
33
19
|
}
|
|
34
20
|
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* GLN validator.
|
|
38
|
-
*/
|
|
39
|
-
export const GLN_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.GLN, 13);
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* SSCC validator.
|
|
43
|
-
*/
|
|
44
|
-
export const SSCC_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.SSCC, 18, LeaderTypes.ExtensionDigit);
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* GSRN validator.
|
|
48
|
-
*/
|
|
49
|
-
export const GSRN_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.GSRN, 18);
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* GSIN validator.
|
|
53
|
-
*/
|
|
54
|
-
export const GSIN_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.GSIN, 17);
|
|
@@ -5,13 +5,12 @@ import {
|
|
|
5
5
|
type TransformerOutput
|
|
6
6
|
} from "@aidc-toolkit/utility";
|
|
7
7
|
import { Mixin } from "ts-mixer";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import type {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import type { PrefixProvider } from "./prefix-provider";
|
|
8
|
+
import { AbstractIdentifierCreator } from "./abstract-identifier-creator.js";
|
|
9
|
+
import { checkCharacterPair } from "./check.js";
|
|
10
|
+
import { i18nextGS1 } from "./locale/i18n.js";
|
|
11
|
+
import type { NonNumericIdentifierType } from "./non-numeric-identifier-type.js";
|
|
12
|
+
import { NonNumericIdentifierValidator } from "./non-numeric-identifier-validator.js";
|
|
13
|
+
import type { PrefixProvider } from "./prefix-provider.js";
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* Non-numeric identifier creator.
|
|
@@ -31,20 +30,11 @@ export class NonNumericIdentifierCreator extends Mixin(NonNumericIdentifierValid
|
|
|
31
30
|
*
|
|
32
31
|
* @param identifierType
|
|
33
32
|
* Identifier type.
|
|
34
|
-
*
|
|
35
|
-
* @param length
|
|
36
|
-
* Length.
|
|
37
|
-
*
|
|
38
|
-
* @param referenceCharacterSet
|
|
39
|
-
* Reference character set.
|
|
40
|
-
*
|
|
41
|
-
* @param requiresCheckCharacterPair
|
|
42
|
-
* True if the identifier requires a check character pair.
|
|
43
33
|
*/
|
|
44
|
-
constructor(prefixProvider: PrefixProvider, identifierType:
|
|
45
|
-
super(identifierType
|
|
34
|
+
constructor(prefixProvider: PrefixProvider, identifierType: NonNumericIdentifierType) {
|
|
35
|
+
super(identifierType);
|
|
46
36
|
|
|
47
|
-
this.init(prefixProvider, prefixProvider.gs1CompanyPrefix, 2 * Number(requiresCheckCharacterPair));
|
|
37
|
+
this.init(prefixProvider, prefixProvider.gs1CompanyPrefix, 2 * Number(this.requiresCheckCharacterPair));
|
|
48
38
|
|
|
49
39
|
this._referenceValidation = {
|
|
50
40
|
minimumLength: 1,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ContentCharacterSet, ContentCharacterSets } from "./content-character-set.js";
|
|
2
|
+
import type { IdentifierDescriptor } from "./identifier-descriptor.js";
|
|
3
|
+
import type { NonNumericIdentifierType } from "./non-numeric-identifier-type.js";
|
|
4
|
+
import type { PrefixTypes } from "./prefix-type.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Non-numeric identifier descriptor.
|
|
8
|
+
*/
|
|
9
|
+
export interface NonNumericIdentifierDescriptor extends IdentifierDescriptor {
|
|
10
|
+
/**
|
|
11
|
+
* @inheritDoc
|
|
12
|
+
*/
|
|
13
|
+
readonly identifierType: NonNumericIdentifierType;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @inheritDoc
|
|
17
|
+
*/
|
|
18
|
+
readonly prefixType: typeof PrefixTypes.GS1CompanyPrefix;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @inheritDoc
|
|
22
|
+
*/
|
|
23
|
+
readonly referenceCharacterSet: Exclude<ContentCharacterSet, typeof ContentCharacterSets.Numeric>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* True if identifier requires a check character pair.
|
|
27
|
+
*/
|
|
28
|
+
readonly requiresCheckCharacterPair: boolean;
|
|
29
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { IdentifierType } from "./identifier-type.js";
|
|
2
|
+
import type { NumericIdentifierType } from "./numeric-identifier-type.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Non-numeric identifier type.
|
|
6
|
+
*/
|
|
7
|
+
export type NonNumericIdentifierType = Exclude<IdentifierType, NumericIdentifierType>;
|