@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
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type { ContentCharacterSet, IdentifierValidation, IdentifierValidator } from "./identifier-validator";
|
|
1
|
+
import type { IdentifierDescriptor } from "./identifier-descriptor";
|
|
2
|
+
import type { IdentifierValidation, IdentifierValidator } from "./identifier-validator";
|
|
4
3
|
import type { PrefixProvider } from "./prefix-provider";
|
|
5
|
-
import type { PrefixType } from "./prefix-type";
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* Identifier creator. Creates an identifier based on its definition in section 3 of the {@link
|
|
9
|
-
* https://
|
|
7
|
+
* https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}.
|
|
10
8
|
*
|
|
11
|
-
* Keys are created based on a prefix defined in a prefix
|
|
9
|
+
* Keys are created based on a prefix defined in a prefix provider to which the identifier creator is bound.
|
|
10
|
+
*
|
|
11
|
+
* @template TIdentifierDescriptor
|
|
12
|
+
* Identifier descriptor type.
|
|
13
|
+
*
|
|
14
|
+
* @template TIdentifierValidation
|
|
15
|
+
* Identifier validation type.
|
|
12
16
|
*/
|
|
13
|
-
export interface IdentifierCreator extends IdentifierValidator {
|
|
17
|
+
export interface IdentifierCreator<TIdentifierDescriptor extends IdentifierDescriptor = IdentifierDescriptor, TIdentifierValidation extends IdentifierValidation = IdentifierValidation> extends IdentifierValidator<TIdentifierDescriptor, TIdentifierValidation> {
|
|
14
18
|
/**
|
|
15
19
|
* Get the prefix provider to which this identifier creator is bound.
|
|
16
20
|
*/
|
|
@@ -27,71 +31,3 @@ export interface IdentifierCreator extends IdentifierValidator {
|
|
|
27
31
|
*/
|
|
28
32
|
get referenceLength(): number;
|
|
29
33
|
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Abstract identifier creator. Implements common functionality for an identifier creator, bound to a
|
|
33
|
-
* {@link PrefixProvider}.
|
|
34
|
-
*/
|
|
35
|
-
export abstract class AbstractIdentifierCreator implements IdentifierCreator {
|
|
36
|
-
/**
|
|
37
|
-
* Prefix provider.
|
|
38
|
-
*/
|
|
39
|
-
private _prefixProvider!: PrefixProvider;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Reference length.
|
|
43
|
-
*/
|
|
44
|
-
private _referenceLength!: number;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Initialize the prefix manager. This method is in lieu of a constructor due to the mixin architecture.
|
|
48
|
-
*
|
|
49
|
-
* @param prefixProvider
|
|
50
|
-
* Prefix provider.
|
|
51
|
-
*
|
|
52
|
-
* @param prefix
|
|
53
|
-
* Prefix within prefix manager to use to calculate reference length.
|
|
54
|
-
*
|
|
55
|
-
* @param checkAllowance
|
|
56
|
-
* Number of characters to allow for check digit or check character pair.
|
|
57
|
-
*/
|
|
58
|
-
protected init(prefixProvider: PrefixProvider, prefix: string, checkAllowance: number): void {
|
|
59
|
-
this._prefixProvider = prefixProvider;
|
|
60
|
-
|
|
61
|
-
// Reference length allows for prefix and optionally check digit or check character pair.
|
|
62
|
-
this._referenceLength = this.length - prefix.length - checkAllowance;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
abstract get identifierType(): IdentifierType;
|
|
66
|
-
|
|
67
|
-
abstract get prefixType(): PrefixType;
|
|
68
|
-
|
|
69
|
-
abstract get length(): number;
|
|
70
|
-
|
|
71
|
-
abstract get referenceCharacterSet(): ContentCharacterSet;
|
|
72
|
-
|
|
73
|
-
abstract get referenceCreator(): CharacterSetCreator;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* @inheritDoc
|
|
77
|
-
*/
|
|
78
|
-
get prefixProvider(): PrefixProvider {
|
|
79
|
-
return this._prefixProvider;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* @inheritDoc
|
|
84
|
-
*/
|
|
85
|
-
get prefix(): string {
|
|
86
|
-
return this.prefixProvider.gs1CompanyPrefix;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* @inheritDoc
|
|
91
|
-
*/
|
|
92
|
-
get referenceLength(): number {
|
|
93
|
-
return this._referenceLength;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
abstract validate(identifier: string, validation?: IdentifierValidation): void;
|
|
97
|
-
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ContentCharacterSet } from "./content-character-set";
|
|
2
|
+
import type { IdentifierType } from "./identifier-type";
|
|
3
|
+
import type { PrefixType } from "./prefix-type";
|
|
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";
|
|
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
|
@@ -15,21 +15,45 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
export * from "./locale/i18n";
|
|
18
|
+
|
|
18
19
|
export * from "./character-set";
|
|
20
|
+
|
|
19
21
|
export * from "./check";
|
|
22
|
+
|
|
20
23
|
export * from "./prefix-type";
|
|
21
24
|
export * from "./prefix-validator";
|
|
25
|
+
|
|
26
|
+
export * from "./content-character-set";
|
|
27
|
+
|
|
22
28
|
export * from "./identifier-type";
|
|
23
|
-
export * from "./identifier-
|
|
24
|
-
export * from "./
|
|
25
|
-
export * from "./gtin-
|
|
29
|
+
export * from "./numeric-identifier-type";
|
|
30
|
+
export * from "./gtin-type";
|
|
31
|
+
export type * from "./non-gtin-numeric-identifier-type";
|
|
32
|
+
export type * from "./serializable-numeric-identifier-type";
|
|
33
|
+
export type * from "./non-numeric-identifier-type";
|
|
34
|
+
|
|
35
|
+
export type * from "./identifier-descriptor";
|
|
36
|
+
export type * from "./numeric-identifier-descriptor";
|
|
37
|
+
export type * from "./gtin-descriptor";
|
|
38
|
+
export type * from "./non-gtin-numeric-identifier-descriptor";
|
|
39
|
+
export type * from "./serializable-numeric-identifier-descriptor";
|
|
40
|
+
export type * from "./non-numeric-identifier-descriptor";
|
|
41
|
+
export * from "./descriptors";
|
|
42
|
+
|
|
43
|
+
export type * from "./identifier-validator";
|
|
44
|
+
export type * from "./numeric-identifier-validator";
|
|
45
|
+
export { GTINLevels, type GTINLevel, type RCNReference, GTINValidator } from "./gtin-validator";
|
|
26
46
|
export * from "./non-gtin-numeric-identifier-validator";
|
|
27
47
|
export * from "./serializable-numeric-identifier-validator";
|
|
28
48
|
export * from "./non-numeric-identifier-validator";
|
|
29
|
-
export * from "./
|
|
30
|
-
|
|
49
|
+
export * from "./validators";
|
|
50
|
+
|
|
51
|
+
export type * from "./identifier-creator";
|
|
52
|
+
export type * from "./numeric-identifier-creator";
|
|
31
53
|
export * from "./gtin-creator";
|
|
32
54
|
export * from "./non-gtin-numeric-identifier-creator";
|
|
33
55
|
export * from "./serializable-numeric-identifier-creator";
|
|
34
56
|
export * from "./non-numeric-identifier-creator";
|
|
57
|
+
export * from "./creators";
|
|
58
|
+
|
|
35
59
|
export * from "./prefix-manager";
|
|
@@ -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\"",
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Mixin } from "ts-mixer";
|
|
2
|
-
import
|
|
2
|
+
import { AbstractNumericIdentifierCreator } from "./abstract-numeric-identifier-creator";
|
|
3
|
+
import type { NonGTINNumericIdentifierType } from "./non-gtin-numeric-identifier-type";
|
|
3
4
|
import { NonGTINNumericIdentifierValidator } from "./non-gtin-numeric-identifier-validator";
|
|
4
|
-
import { AbstractNumericIdentifierCreator } from "./numeric-identifier-creator";
|
|
5
|
-
import { type LeaderType, LeaderTypes } from "./numeric-identifier-validator";
|
|
6
5
|
import type { PrefixProvider } from "./prefix-provider";
|
|
6
|
+
import type { SerializableNumericIdentifierType } from "./serializable-numeric-identifier-type";
|
|
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";
|
|
2
|
+
import type { NumericIdentifierDescriptor } from "./numeric-identifier-descriptor";
|
|
3
|
+
import type { LeaderType, LeaderTypes } from "./numeric-identifier-type";
|
|
4
|
+
import type { PrefixTypes } from "./prefix-type";
|
|
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";
|
|
2
|
+
import type { NumericIdentifierType } from "./numeric-identifier-type";
|
|
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";
|
|
2
|
+
import { IdentifierDescriptors } from "./descriptors";
|
|
3
|
+
import type { NonGTINNumericIdentifierDescriptor } from "./non-gtin-numeric-identifier-descriptor";
|
|
4
|
+
import type { NonGTINNumericIdentifierType } from "./non-gtin-numeric-identifier-type";
|
|
5
|
+
import type { SerializableNumericIdentifierType } from "./serializable-numeric-identifier-type";
|
|
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,11 +5,10 @@ import {
|
|
|
5
5
|
type TransformerOutput
|
|
6
6
|
} from "@aidc-toolkit/utility";
|
|
7
7
|
import { Mixin } from "ts-mixer";
|
|
8
|
+
import { AbstractIdentifierCreator } from "./abstract-identifier-creator";
|
|
8
9
|
import { checkCharacterPair } from "./check";
|
|
9
|
-
import { AbstractIdentifierCreator } from "./identifier-creator";
|
|
10
|
-
import type { IdentifierType } from "./identifier-type";
|
|
11
|
-
import type { ContentCharacterSet } from "./identifier-validator";
|
|
12
10
|
import { i18nextGS1 } from "./locale/i18n";
|
|
11
|
+
import type { NonNumericIdentifierType } from "./non-numeric-identifier-type";
|
|
13
12
|
import { NonNumericIdentifierValidator } from "./non-numeric-identifier-validator";
|
|
14
13
|
import type { PrefixProvider } from "./prefix-provider";
|
|
15
14
|
|
|
@@ -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";
|
|
2
|
+
import type { IdentifierDescriptor } from "./identifier-descriptor";
|
|
3
|
+
import type { NonNumericIdentifierType } from "./non-numeric-identifier-type";
|
|
4
|
+
import type { PrefixTypes } from "./prefix-type";
|
|
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
|
+
}
|