@aidc-toolkit/gs1 1.0.26-beta → 1.0.27-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 +66 -66
- package/dist/abstract-identifier-creator.d.ts.map +1 -1
- package/dist/abstract-identifier-creator.js +68 -45
- package/dist/abstract-identifier-creator.js.map +1 -1
- package/dist/abstract-non-gtin-numeric-identifier-creator.d.ts +42 -0
- package/dist/abstract-non-gtin-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/abstract-non-gtin-numeric-identifier-creator.js +40 -0
- package/dist/abstract-non-gtin-numeric-identifier-creator.js.map +1 -0
- package/dist/abstract-numeric-identifier-creator.d.ts +37 -86
- package/dist/abstract-numeric-identifier-creator.d.ts.map +1 -1
- package/dist/abstract-numeric-identifier-creator.js +144 -121
- package/dist/abstract-numeric-identifier-creator.js.map +1 -1
- package/dist/content-character-set-creators.d.ts +4 -0
- package/dist/content-character-set-creators.d.ts.map +1 -0
- package/dist/content-character-set-creators.js +9 -0
- package/dist/content-character-set-creators.js.map +1 -0
- package/dist/gtin-creator.d.ts +7 -12
- package/dist/gtin-creator.d.ts.map +1 -1
- package/dist/gtin-creator.js +11 -14
- package/dist/gtin-creator.js.map +1 -1
- package/dist/gtin-descriptor.d.ts +8 -3
- package/dist/gtin-descriptor.d.ts.map +1 -1
- package/dist/gtin-length.d.ts +64 -0
- package/dist/gtin-length.d.ts.map +1 -0
- package/dist/gtin-length.js +36 -0
- package/dist/gtin-length.js.map +1 -0
- package/dist/gtin-type.d.ts +15 -28
- package/dist/gtin-type.d.ts.map +1 -1
- package/dist/gtin-type.js +4 -28
- package/dist/gtin-type.js.map +1 -1
- package/dist/gtin-validator.d.ts +9 -23
- package/dist/gtin-validator.d.ts.map +1 -1
- package/dist/gtin-validator.js +32 -39
- package/dist/gtin-validator.js.map +1 -1
- package/dist/identifier-creator.d.ts +4 -4
- package/dist/identifier-creator.d.ts.map +1 -1
- package/dist/{creators.d.ts → identifier-creators.d.ts} +16 -7
- package/dist/identifier-creators.d.ts.map +1 -0
- package/dist/{creators.js → identifier-creators.js} +19 -7
- package/dist/identifier-creators.js.map +1 -0
- package/dist/{descriptors.d.ts → identifier-descriptors.d.ts} +20 -10
- package/dist/identifier-descriptors.d.ts.map +1 -0
- package/dist/{descriptors.js → identifier-descriptors.js} +27 -31
- package/dist/identifier-descriptors.js.map +1 -0
- package/dist/identifier-extension.d.ts +82 -0
- package/dist/identifier-extension.d.ts.map +1 -0
- package/dist/identifier-extension.js +79 -0
- package/dist/identifier-extension.js.map +1 -0
- package/dist/identifier-validator.d.ts +44 -9
- package/dist/identifier-validator.d.ts.map +1 -1
- package/dist/identifier-validator.js +109 -1
- package/dist/identifier-validator.js.map +1 -1
- package/dist/{validators.d.ts → identifier-validators.d.ts} +21 -11
- package/dist/identifier-validators.d.ts.map +1 -0
- package/dist/{validators.js → identifier-validators.js} +25 -12
- package/dist/identifier-validators.js.map +1 -0
- package/dist/index.d.ts +15 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/dist/leader-type.d.ts +26 -0
- package/dist/leader-type.d.ts.map +1 -0
- package/dist/leader-type.js +18 -0
- package/dist/leader-type.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-creator.d.ts +7 -19
- package/dist/non-gtin-numeric-identifier-creator.d.ts.map +1 -1
- package/dist/non-gtin-numeric-identifier-creator.js +1 -22
- package/dist/non-gtin-numeric-identifier-creator.js.map +1 -1
- package/dist/non-gtin-numeric-identifier-descriptor.d.ts +1 -1
- package/dist/non-gtin-numeric-identifier-descriptor.d.ts.map +1 -1
- package/dist/non-gtin-numeric-identifier-type.d.ts +22 -3
- package/dist/non-gtin-numeric-identifier-type.d.ts.map +1 -1
- package/dist/non-gtin-numeric-identifier-type.js +7 -1
- package/dist/non-gtin-numeric-identifier-type.js.map +1 -1
- package/dist/non-gtin-numeric-identifier-validator.d.ts +5 -10
- package/dist/non-gtin-numeric-identifier-validator.d.ts.map +1 -1
- package/dist/non-gtin-numeric-identifier-validator.js +5 -12
- package/dist/non-gtin-numeric-identifier-validator.js.map +1 -1
- package/dist/non-numeric-identifier-creator.d.ts +4 -9
- package/dist/non-numeric-identifier-creator.d.ts.map +1 -1
- package/dist/non-numeric-identifier-creator.js +8 -10
- package/dist/non-numeric-identifier-creator.js.map +1 -1
- package/dist/non-numeric-identifier-type.d.ts +22 -3
- package/dist/non-numeric-identifier-type.d.ts.map +1 -1
- package/dist/non-numeric-identifier-type.js +7 -1
- package/dist/non-numeric-identifier-type.js.map +1 -1
- package/dist/non-numeric-identifier-validator.d.ts +3 -11
- package/dist/non-numeric-identifier-validator.d.ts.map +1 -1
- package/dist/non-numeric-identifier-validator.js +8 -8
- package/dist/non-numeric-identifier-validator.js.map +1 -1
- package/dist/non-serializable-numeric-identifier-creator.d.ts +10 -0
- package/dist/non-serializable-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/non-serializable-numeric-identifier-creator.js +8 -0
- package/dist/non-serializable-numeric-identifier-creator.js.map +1 -0
- package/dist/non-serializable-numeric-identifier-descriptor.d.ts +7 -0
- package/dist/non-serializable-numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/non-serializable-numeric-identifier-descriptor.js +2 -0
- package/dist/non-serializable-numeric-identifier-descriptor.js.map +1 -0
- package/dist/non-serializable-numeric-identifier-type.d.ts +26 -0
- package/dist/non-serializable-numeric-identifier-type.d.ts.map +1 -0
- package/dist/non-serializable-numeric-identifier-type.js +7 -0
- package/dist/non-serializable-numeric-identifier-type.js.map +1 -0
- package/dist/non-serializable-numeric-identifier-validator.d.ts +16 -0
- package/dist/non-serializable-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/non-serializable-numeric-identifier-validator.js +17 -0
- package/dist/non-serializable-numeric-identifier-validator.js.map +1 -0
- package/dist/numeric-identifier-creator.d.ts +6 -6
- package/dist/numeric-identifier-creator.d.ts.map +1 -1
- package/dist/numeric-identifier-descriptor.d.ts +2 -1
- package/dist/numeric-identifier-descriptor.d.ts.map +1 -1
- package/dist/numeric-identifier-type.d.ts +19 -24
- package/dist/numeric-identifier-type.d.ts.map +1 -1
- package/dist/numeric-identifier-type.js +4 -15
- package/dist/numeric-identifier-type.js.map +1 -1
- package/dist/numeric-identifier-validator.d.ts +20 -6
- package/dist/numeric-identifier-validator.d.ts.map +1 -1
- package/dist/numeric-identifier-validator.js +60 -1
- package/dist/numeric-identifier-validator.js.map +1 -1
- package/dist/prefix-manager.d.ts +6 -102
- package/dist/prefix-manager.d.ts.map +1 -1
- package/dist/prefix-manager.js +65 -60
- package/dist/prefix-manager.js.map +1 -1
- package/dist/serializable-numeric-identifier-creator.d.ts +3 -31
- package/dist/serializable-numeric-identifier-creator.d.ts.map +1 -1
- package/dist/serializable-numeric-identifier-creator.js +7 -21
- package/dist/serializable-numeric-identifier-creator.js.map +1 -1
- package/dist/serializable-numeric-identifier-descriptor.d.ts +1 -1
- package/dist/serializable-numeric-identifier-descriptor.d.ts.map +1 -1
- package/dist/serializable-numeric-identifier-type.d.ts +22 -2
- package/dist/serializable-numeric-identifier-type.d.ts.map +1 -1
- package/dist/serializable-numeric-identifier-type.js +7 -1
- package/dist/serializable-numeric-identifier-type.js.map +1 -1
- package/dist/serializable-numeric-identifier-validator.d.ts +3 -18
- package/dist/serializable-numeric-identifier-validator.d.ts.map +1 -1
- package/dist/serializable-numeric-identifier-validator.js +17 -16
- package/dist/serializable-numeric-identifier-validator.js.map +1 -1
- package/package.json +4 -5
- package/src/abstract-identifier-creator.ts +155 -74
- package/src/abstract-non-gtin-numeric-identifier-creator.ts +86 -0
- package/src/abstract-numeric-identifier-creator.ts +202 -133
- package/src/content-character-set-creators.ts +9 -0
- package/src/gtin-creator.ts +16 -15
- package/src/gtin-descriptor.ts +9 -3
- package/src/gtin-length.ts +61 -0
- package/src/gtin-type.ts +6 -37
- package/src/gtin-validator.ts +34 -41
- package/src/identifier-creator.ts +4 -4
- package/src/{creators.ts → identifier-creators.ts} +40 -26
- package/src/{descriptors.ts → identifier-descriptors.ts} +56 -54
- package/src/identifier-extension.ts +155 -0
- package/src/identifier-validator.ts +93 -10
- package/src/{validators.ts → identifier-validators.ts} +51 -36
- package/src/index.ts +15 -9
- package/src/leader-type.ts +29 -0
- package/src/non-gtin-numeric-identifier-creator.ts +7 -22
- package/src/non-gtin-numeric-identifier-descriptor.ts +1 -1
- package/src/non-gtin-numeric-identifier-type.ts +14 -3
- package/src/non-gtin-numeric-identifier-validator.ts +5 -13
- package/src/non-numeric-identifier-creator.ts +17 -12
- package/src/non-numeric-identifier-type.ts +14 -3
- package/src/non-numeric-identifier-validator.ts +8 -9
- package/src/non-serializable-numeric-identifier-creator.ts +12 -0
- package/src/non-serializable-numeric-identifier-descriptor.ts +7 -0
- package/src/non-serializable-numeric-identifier-type.ts +22 -0
- package/src/non-serializable-numeric-identifier-validator.ts +19 -0
- package/src/numeric-identifier-creator.ts +7 -6
- package/src/numeric-identifier-descriptor.ts +2 -1
- package/src/numeric-identifier-type.ts +17 -35
- package/src/numeric-identifier-validator.ts +61 -6
- package/src/prefix-manager.ts +67 -64
- package/src/serializable-numeric-identifier-creator.ts +11 -25
- package/src/serializable-numeric-identifier-descriptor.ts +1 -1
- package/src/serializable-numeric-identifier-type.ts +14 -5
- package/src/serializable-numeric-identifier-validator.ts +17 -16
- package/test/gtin-creator.ts +9 -2
- package/test/gtin-validator.test.ts +8 -10
- package/test/identifier-creator.ts +7 -7
- package/test/non-gtin-numeric-identifier-validator.ts +7 -2
- package/test/non-serializable-numeric-identifier-creator.ts +64 -0
- package/test/non-serializable-numeric-identifier-validator.ts +6 -0
- package/test/numeric-identifier-creator.ts +7 -2
- package/test/validator.test.ts +11 -10
- package/test/variable-measure-rcn.test.ts +23 -23
- package/dist/abstract-identifier-validator.d.ts +0 -95
- package/dist/abstract-identifier-validator.d.ts.map +0 -1
- package/dist/abstract-identifier-validator.js +0 -123
- package/dist/abstract-identifier-validator.js.map +0 -1
- package/dist/abstract-numeric-identifier-validator.d.ts +0 -35
- package/dist/abstract-numeric-identifier-validator.d.ts.map +0 -1
- package/dist/abstract-numeric-identifier-validator.js +0 -61
- package/dist/abstract-numeric-identifier-validator.js.map +0 -1
- package/dist/creators.d.ts.map +0 -1
- package/dist/creators.js.map +0 -1
- package/dist/descriptors.d.ts.map +0 -1
- package/dist/descriptors.js.map +0 -1
- package/dist/validators.d.ts.map +0 -1
- package/dist/validators.js.map +0 -1
- package/src/abstract-identifier-validator.ts +0 -140
- package/src/abstract-numeric-identifier-validator.ts +0 -69
|
@@ -5,164 +5,233 @@ import {
|
|
|
5
5
|
type TransformerInput,
|
|
6
6
|
type TransformerOutput
|
|
7
7
|
} from "@aidc-toolkit/utility";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
type IdentifierCreatorConstructor,
|
|
10
|
+
type IdentifierExtensionConstructor,
|
|
11
|
+
type IdentifierValidatorConstructor,
|
|
12
|
+
MixinAbstractIdentifierCreator
|
|
13
|
+
} from "./abstract-identifier-creator.js";
|
|
9
14
|
import { checkDigit, checkDigitSum } from "./check.js";
|
|
15
|
+
import type { IdentifierTypeValidator } from "./identifier-validators.js";
|
|
16
|
+
import { LeaderTypes } from "./leader-type.js";
|
|
10
17
|
import type { NumericIdentifierCreator } from "./numeric-identifier-creator.js";
|
|
11
|
-
import type {
|
|
12
|
-
import {
|
|
13
|
-
import type { NumericIdentifierValidation } from "./numeric-identifier-validator.js";
|
|
18
|
+
import type { NumericIdentifierType } from "./numeric-identifier-type.js";
|
|
19
|
+
import type { NumericIdentifierValidation, NumericIdentifierValidator } from "./numeric-identifier-validator.js";
|
|
14
20
|
import type { PrefixProvider } from "./prefix-provider.js";
|
|
15
21
|
|
|
16
22
|
/**
|
|
17
|
-
*
|
|
23
|
+
* Numeric identifier creator constructor type, which delegates to a numeric identifier validator constructor.
|
|
24
|
+
*
|
|
25
|
+
* @template TConstructorArguments
|
|
26
|
+
* Constructor arguments types.
|
|
18
27
|
*
|
|
19
|
-
* @template
|
|
20
|
-
* Numeric identifier
|
|
28
|
+
* @template TNumericIdentifierType
|
|
29
|
+
* Numeric identifier type type.
|
|
30
|
+
*
|
|
31
|
+
* @template TNumericIdentifierValidator
|
|
32
|
+
* Numeric identifier validator type.
|
|
21
33
|
*/
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
*/
|
|
31
|
-
private _tweak = 0n;
|
|
34
|
+
export type NumericIdentifierCreatorConstructor<
|
|
35
|
+
TConstructorArguments extends unknown[],
|
|
36
|
+
TNumericIdentifierType extends NumericIdentifierType,
|
|
37
|
+
TNumericIdentifierValidator extends NumericIdentifierValidator<TNumericIdentifierType>
|
|
38
|
+
> = IdentifierExtensionConstructor<
|
|
39
|
+
[prefixProvider: PrefixProvider, prefix: string, ...args: TConstructorArguments],
|
|
40
|
+
TNumericIdentifierValidator & NumericIdentifierCreator<TNumericIdentifierType>
|
|
41
|
+
>;
|
|
32
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Mixin implementation of {@linkcode NumericIdentifierCreator} with an appropriate numeric identifier validator base.
|
|
45
|
+
*
|
|
46
|
+
* @template TConstructorArguments
|
|
47
|
+
* Constructor arguments types.
|
|
48
|
+
*
|
|
49
|
+
* @template TNumericIdentifierType
|
|
50
|
+
* Numeric identifier type type.
|
|
51
|
+
*
|
|
52
|
+
* @template TNumericIdentifierValidatorConstructor
|
|
53
|
+
* Numeric identifier validator constructor type.
|
|
54
|
+
*
|
|
55
|
+
* @param NumericIdentifierValidatorBase
|
|
56
|
+
* Numeric identifier validator base.
|
|
57
|
+
*
|
|
58
|
+
* @returns
|
|
59
|
+
* Numeric identifier creator class.
|
|
60
|
+
*/
|
|
61
|
+
export function MixinAbstractNumericIdentifierCreator<
|
|
62
|
+
TConstructorArguments extends unknown[],
|
|
63
|
+
TNumericIdentifierType extends NumericIdentifierType,
|
|
64
|
+
TNumericIdentifierValidatorConstructor extends IdentifierValidatorConstructor<
|
|
65
|
+
TConstructorArguments,
|
|
66
|
+
TNumericIdentifierType,
|
|
67
|
+
NumericIdentifierValidation
|
|
68
|
+
>
|
|
69
|
+
>(NumericIdentifierValidatorBase: TNumericIdentifierValidatorConstructor): NumericIdentifierCreatorConstructor<
|
|
70
|
+
TConstructorArguments,
|
|
71
|
+
TNumericIdentifierType,
|
|
72
|
+
IdentifierTypeValidator<TNumericIdentifierType>
|
|
73
|
+
> {
|
|
33
74
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* @param prefixProvider
|
|
37
|
-
* Prefix provider.
|
|
38
|
-
*
|
|
39
|
-
* @param prefix
|
|
40
|
-
* Prefix within prefix manager to use to calculate reference length.
|
|
75
|
+
* Abstract numeric identifier creator. Implements common functionality for a numeric identifier creator, mixed in
|
|
76
|
+
* with a matching numeric identifier validator.
|
|
41
77
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
78
|
+
abstract class AbstractNumericIdentifierCreator extends (MixinAbstractIdentifierCreator(NumericIdentifierValidatorBase) as IdentifierCreatorConstructor<
|
|
79
|
+
TConstructorArguments,
|
|
80
|
+
TNumericIdentifierType,
|
|
81
|
+
NumericIdentifierValidation,
|
|
82
|
+
NumericIdentifierValidator<TNumericIdentifierType>
|
|
83
|
+
>) implements NumericIdentifierCreator<TNumericIdentifierType> {
|
|
84
|
+
/**
|
|
85
|
+
* Capacity.
|
|
86
|
+
*/
|
|
87
|
+
readonly #capacity: number;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Tweak for sparse creation.
|
|
91
|
+
*/
|
|
92
|
+
#tweak = 0n;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Constructor.
|
|
96
|
+
*
|
|
97
|
+
* @param prefixProvider
|
|
98
|
+
* Prefix provider.
|
|
99
|
+
*
|
|
100
|
+
* @param prefix
|
|
101
|
+
* Prefix within prefix provider to use to calculate reference length.
|
|
102
|
+
*
|
|
103
|
+
* @param args
|
|
104
|
+
* Originating constructor arguments.
|
|
105
|
+
*/
|
|
106
|
+
constructor(prefixProvider: PrefixProvider, prefix: string, ...args: TConstructorArguments) {
|
|
107
|
+
super(prefixProvider, prefix, 1, ...args);
|
|
108
|
+
|
|
109
|
+
// Capacity is always in number range.
|
|
110
|
+
this.#capacity = Number(CharacterSetCreator.powerOf10(this.referenceLength));
|
|
111
|
+
}
|
|
48
112
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
113
|
+
/**
|
|
114
|
+
* @inheritDoc
|
|
115
|
+
*/
|
|
116
|
+
get capacity(): number {
|
|
117
|
+
return this.#capacity;
|
|
118
|
+
}
|
|
53
119
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
120
|
+
/**
|
|
121
|
+
* @inheritDoc
|
|
122
|
+
*/
|
|
123
|
+
get tweak(): bigint {
|
|
124
|
+
return this.#tweak;
|
|
125
|
+
}
|
|
60
126
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
127
|
+
/**
|
|
128
|
+
* @inheritDoc
|
|
129
|
+
*/
|
|
130
|
+
set tweak(value: bigint) {
|
|
131
|
+
this.#tweak = value;
|
|
132
|
+
}
|
|
67
133
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
134
|
+
/**
|
|
135
|
+
* Build an identifier from a reference by merging it with the prefix and adding the check digit.
|
|
136
|
+
*
|
|
137
|
+
* @param reference
|
|
138
|
+
* Identifier reference.
|
|
139
|
+
*
|
|
140
|
+
* @returns
|
|
141
|
+
* Identifier.
|
|
142
|
+
*/
|
|
143
|
+
#buildIdentifier(reference: string): string {
|
|
144
|
+
const partialIdentifier = this.leaderType === LeaderTypes.ExtensionDigit ? reference.substring(0, 1) + this.prefix + reference.substring(1) : this.prefix + reference;
|
|
145
|
+
|
|
146
|
+
return partialIdentifier + checkDigit(partialIdentifier);
|
|
147
|
+
}
|
|
74
148
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
* @returns
|
|
82
|
-
* Identifier.
|
|
83
|
-
*/
|
|
84
|
-
private buildIdentifier(reference: string): string {
|
|
85
|
-
const partialIdentifier = this.leaderType === LeaderTypes.ExtensionDigit ? reference.substring(0, 1) + this.prefix + reference.substring(1) : this.prefix + reference;
|
|
149
|
+
/**
|
|
150
|
+
* @inheritDoc
|
|
151
|
+
*/
|
|
152
|
+
create<TTransformerInput extends TransformerInput<number | bigint>>(valueOrValues: TTransformerInput, sparse = false): TransformerOutput<TTransformerInput, string> {
|
|
153
|
+
return NUMERIC_CREATOR.create(this.referenceLength, valueOrValues, Exclusions.None, sparse ? this.tweak : undefined, reference => this.#buildIdentifier(reference));
|
|
154
|
+
}
|
|
86
155
|
|
|
87
|
-
|
|
88
|
-
|
|
156
|
+
/**
|
|
157
|
+
* Create all identifiers from a partial identifier. Call is recursive until remaining reference
|
|
158
|
+
* length is 0.
|
|
159
|
+
*
|
|
160
|
+
* @param partialIdentifier
|
|
161
|
+
* Partial identifier. Initial value is `this.prefix`.
|
|
162
|
+
*
|
|
163
|
+
* @param remainingReferenceLength
|
|
164
|
+
* Remaining reference length. Initial value is `this.referenceLength`.
|
|
165
|
+
*
|
|
166
|
+
* @param extensionWeight
|
|
167
|
+
* If this value is not zero, the identifier has an extension digit, this call is setting it, and this value is
|
|
168
|
+
* applied to the calculation of the check digit.
|
|
169
|
+
*
|
|
170
|
+
* @param weight
|
|
171
|
+
* If the extension weight is zero, this value is applied to the calculation of the check digit.
|
|
172
|
+
*
|
|
173
|
+
* @param partialCheckDigitSum
|
|
174
|
+
* Partial check digit sum for the partial identifier.
|
|
175
|
+
*
|
|
176
|
+
* @yields
|
|
177
|
+
* Identifier.
|
|
178
|
+
*/
|
|
179
|
+
static * createAllPartial(partialIdentifier: string, remainingReferenceLength: number, extensionWeight: number, weight: number, partialCheckDigitSum: number): Generator<string> {
|
|
180
|
+
if (remainingReferenceLength === 0) {
|
|
181
|
+
// Finalize check digit calculation and append.
|
|
182
|
+
yield partialIdentifier + NUMERIC_CREATOR.character(9 - (partialCheckDigitSum + 9) % 10);
|
|
183
|
+
} else {
|
|
184
|
+
const nextRemainingReferenceLength = remainingReferenceLength - 1;
|
|
89
185
|
|
|
90
|
-
|
|
91
|
-
* @inheritDoc
|
|
92
|
-
*/
|
|
93
|
-
create<TTransformerInput extends TransformerInput<number | bigint>>(valueOrValues: TTransformerInput, sparse = false): TransformerOutput<TTransformerInput, string> {
|
|
94
|
-
return NUMERIC_CREATOR.create(this.referenceLength, valueOrValues, Exclusions.None, sparse ? this.tweak : undefined, reference => this.buildIdentifier(reference));
|
|
95
|
-
}
|
|
186
|
+
let nextPartialCheckDigitSum = partialCheckDigitSum;
|
|
96
187
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
* @param partialIdentifier
|
|
102
|
-
* Partial identifier. Initial value is `this.prefix`.
|
|
103
|
-
*
|
|
104
|
-
* @param remainingReferenceLength
|
|
105
|
-
* Remaining reference length. Initial value is `this.referenceLength`.
|
|
106
|
-
*
|
|
107
|
-
* @param extensionWeight
|
|
108
|
-
* If this value is not zero, the identifier has an extension digit, this call is setting it, and this value is
|
|
109
|
-
* applied to the calculation of the check digit.
|
|
110
|
-
*
|
|
111
|
-
* @param weight
|
|
112
|
-
* If the extension weight is zero, this value is applied to the calculation of the check digit.
|
|
113
|
-
*
|
|
114
|
-
* @param partialCheckDigitSum
|
|
115
|
-
* Partial check digit sum for the partial identifier.
|
|
116
|
-
*
|
|
117
|
-
* @yields
|
|
118
|
-
* Identifier.
|
|
119
|
-
*/
|
|
120
|
-
private static * createAllPartial(partialIdentifier: string, remainingReferenceLength: number, extensionWeight: number, weight: number, partialCheckDigitSum: number): Generator<string> {
|
|
121
|
-
if (remainingReferenceLength === 0) {
|
|
122
|
-
// Finalize check digit calculation and append.
|
|
123
|
-
yield partialIdentifier + NUMERIC_CREATOR.character(9 - (partialCheckDigitSum + 9) % 10);
|
|
124
|
-
} else {
|
|
125
|
-
const nextRemainingReferenceLength = remainingReferenceLength - 1;
|
|
188
|
+
if (extensionWeight !== 0) {
|
|
189
|
+
// Apply every digit to the extension digit.
|
|
190
|
+
for (const c of NUMERIC_CREATOR.characterSet) {
|
|
191
|
+
yield * AbstractNumericIdentifierCreator.createAllPartial(c + partialIdentifier, nextRemainingReferenceLength, 0, weight, nextPartialCheckDigitSum);
|
|
126
192
|
|
|
127
|
-
|
|
193
|
+
nextPartialCheckDigitSum += extensionWeight;
|
|
194
|
+
}
|
|
195
|
+
} else {
|
|
196
|
+
const nextWeight = 4 - weight;
|
|
128
197
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
yield * AbstractNumericIdentifierCreator.createAllPartial(c + partialIdentifier, nextRemainingReferenceLength, 0, weight, nextPartialCheckDigitSum);
|
|
198
|
+
// Apply every digit to the current character in the identifier.
|
|
199
|
+
for (const c of NUMERIC_CREATOR.characterSet) {
|
|
200
|
+
yield * AbstractNumericIdentifierCreator.createAllPartial(partialIdentifier + c, nextRemainingReferenceLength, 0, nextWeight, nextPartialCheckDigitSum);
|
|
133
201
|
|
|
134
|
-
|
|
202
|
+
nextPartialCheckDigitSum += weight;
|
|
203
|
+
}
|
|
135
204
|
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
// Apply every digit to the current character in the identifier.
|
|
140
|
-
for (const c of NUMERIC_CREATOR.characterSet) {
|
|
141
|
-
yield * AbstractNumericIdentifierCreator.createAllPartial(partialIdentifier + c, nextRemainingReferenceLength, 0, nextWeight, nextPartialCheckDigitSum);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
142
207
|
|
|
143
|
-
|
|
208
|
+
/**
|
|
209
|
+
* @inheritDoc
|
|
210
|
+
*/
|
|
211
|
+
createAll(): Iterable<string> {
|
|
212
|
+
const hasExtensionDigit = this.leaderType === LeaderTypes.ExtensionDigit;
|
|
213
|
+
const prefix = this.prefix;
|
|
214
|
+
const length = this.length;
|
|
215
|
+
const referenceLength = this.referenceLength;
|
|
216
|
+
|
|
217
|
+
// Start weight is for reference excluding extension digit, which has its weight calculated separately.
|
|
218
|
+
const startWeight = 3 - 2 * ((referenceLength + 1 - Number(hasExtensionDigit)) % 2);
|
|
219
|
+
|
|
220
|
+
// Returning separate Iterable object makes iteration repeatable.
|
|
221
|
+
return {
|
|
222
|
+
[Symbol.iterator]() {
|
|
223
|
+
return AbstractNumericIdentifierCreator.createAllPartial(prefix, referenceLength, hasExtensionDigit ? 3 - 2 * length % 2 : 0, startWeight, checkDigitSum(startWeight === 3, prefix));
|
|
144
224
|
}
|
|
145
|
-
}
|
|
225
|
+
};
|
|
146
226
|
}
|
|
147
227
|
}
|
|
148
228
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
// Start weight is for reference excluding extension digit, which has its weight calculated separately.
|
|
159
|
-
const startWeight = 3 - 2 * ((referenceLength + 1 - Number(hasExtensionDigit)) % 2);
|
|
160
|
-
|
|
161
|
-
// Returning separate Iterable object makes iteration repeatable.
|
|
162
|
-
return {
|
|
163
|
-
[Symbol.iterator]() {
|
|
164
|
-
return AbstractNumericIdentifierCreator.createAllPartial(prefix, referenceLength, hasExtensionDigit ? 3 - 2 * length % 2 : 0, startWeight, checkDigitSum(startWeight === 3, prefix));
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
}
|
|
229
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Base class was upcast to type with statically known members for mixin, downcast result.
|
|
230
|
+
return AbstractNumericIdentifierCreator as IdentifierExtensionConstructor<
|
|
231
|
+
ConstructorParameters<typeof AbstractNumericIdentifierCreator>,
|
|
232
|
+
unknown
|
|
233
|
+
> as IdentifierExtensionConstructor<
|
|
234
|
+
ConstructorParameters<typeof AbstractNumericIdentifierCreator>,
|
|
235
|
+
IdentifierTypeValidator<TNumericIdentifierType> & AbstractNumericIdentifierCreator
|
|
236
|
+
>;
|
|
168
237
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type CharacterSetCreator, NUMERIC_CREATOR } from "@aidc-toolkit/utility";
|
|
2
|
+
import { AI39_CREATOR, AI82_CREATOR } from "./character-set.js";
|
|
3
|
+
import { type ContentCharacterSet, ContentCharacterSets } from "./content-character-set.js";
|
|
4
|
+
|
|
5
|
+
export const CONTENT_CHARACTER_SET_CREATORS: Record<ContentCharacterSet, CharacterSetCreator> = {
|
|
6
|
+
[ContentCharacterSets.Numeric]: NUMERIC_CREATOR,
|
|
7
|
+
[ContentCharacterSets.AI82]: AI82_CREATOR,
|
|
8
|
+
[ContentCharacterSets.AI39]: AI39_CREATOR
|
|
9
|
+
};
|
package/src/gtin-creator.ts
CHANGED
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
type TransformerInput,
|
|
6
6
|
type TransformerOutput
|
|
7
7
|
} from "@aidc-toolkit/utility";
|
|
8
|
-
import {
|
|
9
|
-
import { AbstractNumericIdentifierCreator } from "./abstract-numeric-identifier-creator.js";
|
|
8
|
+
import { MixinAbstractNumericIdentifierCreator } from "./abstract-numeric-identifier-creator.js";
|
|
10
9
|
import { checkDigit, priceOrWeightCheckDigit } from "./check.js";
|
|
11
|
-
import { type
|
|
10
|
+
import { type GTINBaseLength, GTINLengths } from "./gtin-length.js";
|
|
11
|
+
import type { GTINType } from "./gtin-type.js";
|
|
12
12
|
import { GTINValidator } from "./gtin-validator.js";
|
|
13
13
|
import { i18nextGS1 } from "./locale/i18n.js";
|
|
14
14
|
import type { PrefixProvider } from "./prefix-provider.js";
|
|
@@ -16,30 +16,31 @@ import type { PrefixProvider } from "./prefix-provider.js";
|
|
|
16
16
|
/**
|
|
17
17
|
* GTIN creator. Applicable to GTIN-13, GTIN-12, and GTIN-8 types; no applicable to GTIN-14 type.
|
|
18
18
|
*/
|
|
19
|
-
export class GTINCreator extends
|
|
19
|
+
export class GTINCreator extends MixinAbstractNumericIdentifierCreator<
|
|
20
|
+
[GTINBaseLength],
|
|
21
|
+
GTINType,
|
|
22
|
+
typeof GTINValidator
|
|
23
|
+
>(GTINValidator) {
|
|
20
24
|
/**
|
|
21
25
|
* Validation parameters for required indicator digit.
|
|
22
26
|
*/
|
|
23
|
-
|
|
27
|
+
static readonly #REQUIRED_INDICATOR_DIGIT_VALIDATION: CharacterSetValidation = {
|
|
24
28
|
minimumLength: 1,
|
|
25
29
|
maximumLength: 1,
|
|
26
30
|
component: () => i18nextGS1.t("Identifier.indicatorDigit")
|
|
27
31
|
};
|
|
28
32
|
|
|
29
33
|
/**
|
|
30
|
-
* Constructor.
|
|
31
|
-
* provider type.
|
|
34
|
+
* Constructor.
|
|
32
35
|
*
|
|
33
36
|
* @param prefixProvider
|
|
34
37
|
* Prefix provider.
|
|
35
38
|
*
|
|
36
|
-
* @param
|
|
37
|
-
* GTIN base
|
|
39
|
+
* @param gtinBaseLength
|
|
40
|
+
* GTIN base length (all except GTIN-14).
|
|
38
41
|
*/
|
|
39
|
-
constructor(prefixProvider: PrefixProvider,
|
|
40
|
-
super(
|
|
41
|
-
|
|
42
|
-
this.init(prefixProvider, prefixProvider.prefix);
|
|
42
|
+
constructor(prefixProvider: PrefixProvider, gtinBaseLength: GTINBaseLength) {
|
|
43
|
+
super(prefixProvider, prefixProvider.prefix, gtinBaseLength);
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
/**
|
|
@@ -69,9 +70,9 @@ export class GTINCreator extends Mixin(GTINValidator, AbstractNumericIdentifierC
|
|
|
69
70
|
* GTIN-14(s).
|
|
70
71
|
*/
|
|
71
72
|
createGTIN14<TTransformerInput extends TransformerInput<number | bigint>>(indicatorDigit: string, valueOrValues: TTransformerInput, sparse = false): TransformerOutput<TTransformerInput, string> {
|
|
72
|
-
NUMERIC_CREATOR.validate(indicatorDigit, GTINCreator
|
|
73
|
+
NUMERIC_CREATOR.validate(indicatorDigit, GTINCreator.#REQUIRED_INDICATOR_DIGIT_VALIDATION);
|
|
73
74
|
|
|
74
|
-
return NUMERIC_CREATOR.create(
|
|
75
|
+
return NUMERIC_CREATOR.create(GTINLengths.GTIN13 - this.prefixProvider.gs1CompanyPrefix.length - 1, valueOrValues, Exclusions.None, sparse ? this.tweak : undefined, (reference) => {
|
|
75
76
|
const partialIdentifier = indicatorDigit + this.prefixProvider.gs1CompanyPrefix + reference;
|
|
76
77
|
|
|
77
78
|
return partialIdentifier + checkDigit(partialIdentifier);
|
package/src/gtin-descriptor.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GTINBaseLength } from "./gtin-length.js";
|
|
2
|
+
import type { GTINType } from "./gtin-type.js";
|
|
3
|
+
import type { LeaderTypes } from "./leader-type.js";
|
|
2
4
|
import type { NumericIdentifierDescriptor } from "./numeric-identifier-descriptor.js";
|
|
3
|
-
import type { LeaderTypes } from "./numeric-identifier-type.js";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* GTIN descriptor.
|
|
@@ -9,7 +10,12 @@ export interface GTINDescriptor extends NumericIdentifierDescriptor {
|
|
|
9
10
|
/**
|
|
10
11
|
* @inheritDoc
|
|
11
12
|
*/
|
|
12
|
-
readonly identifierType:
|
|
13
|
+
readonly identifierType: GTINType;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @inheritDoc
|
|
17
|
+
*/
|
|
18
|
+
readonly length: GTINBaseLength;
|
|
13
19
|
|
|
14
20
|
/**
|
|
15
21
|
* @inheritDoc
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { omit } from "@aidc-toolkit/core";
|
|
2
|
+
import { type PrefixType, PrefixTypes } from "./prefix-type.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* GTIN lengths. The numeric values are equal to the lengths of the GTINs.
|
|
6
|
+
*/
|
|
7
|
+
export const GTINLengths = {
|
|
8
|
+
/**
|
|
9
|
+
* GTIN-13.
|
|
10
|
+
*/
|
|
11
|
+
GTIN13: 13,
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* GTIN-12.
|
|
15
|
+
*/
|
|
16
|
+
GTIN12: 12,
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* GTIN-8.
|
|
20
|
+
*/
|
|
21
|
+
GTIN8: 8,
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* GTIN-14.
|
|
25
|
+
*/
|
|
26
|
+
GTIN14: 14
|
|
27
|
+
} as const;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* GTIN length key.
|
|
31
|
+
*/
|
|
32
|
+
export type GTINLengthKey = keyof typeof GTINLengths;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* GTIN length.
|
|
36
|
+
*/
|
|
37
|
+
export type GTINLength = typeof GTINLengths[GTINLengthKey];
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* GTIN base lengths (all except GTIN-14).
|
|
41
|
+
*/
|
|
42
|
+
export const GTINBaseLengths = omit(GTINLengths, "GTIN14");
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* GTIN base length key.
|
|
46
|
+
*/
|
|
47
|
+
export type GTINBaseLengthKey = keyof typeof GTINBaseLengths;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* GTIN length.
|
|
51
|
+
*/
|
|
52
|
+
export type GTINBaseLength = typeof GTINBaseLengths[GTINBaseLengthKey];
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* GTIN base lengths by prefix type. Used to determine the GTIN length supported by a prefix type.
|
|
56
|
+
*/
|
|
57
|
+
export const GTIN_BASE_TYPES: Readonly<Record<PrefixType, GTINBaseLength>> = {
|
|
58
|
+
[PrefixTypes.GS1CompanyPrefix]: GTINLengths.GTIN13,
|
|
59
|
+
[PrefixTypes.UPCCompanyPrefix]: GTINLengths.GTIN12,
|
|
60
|
+
[PrefixTypes.GS18Prefix]: GTINLengths.GTIN8
|
|
61
|
+
};
|
package/src/gtin-type.ts
CHANGED
|
@@ -1,29 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { pick } from "@aidc-toolkit/core";
|
|
2
|
+
import { NumericIdentifierTypes } from "./numeric-identifier-type.js";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
* GTIN types.
|
|
5
|
+
* GTIN types.
|
|
5
6
|
*/
|
|
6
|
-
export const GTINTypes =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*/
|
|
10
|
-
GTIN13: 13,
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* GTIN-12.
|
|
14
|
-
*/
|
|
15
|
-
GTIN12: 12,
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* GTIN-8.
|
|
19
|
-
*/
|
|
20
|
-
GTIN8: 8,
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* GTIN-14.
|
|
24
|
-
*/
|
|
25
|
-
GTIN14: 14
|
|
26
|
-
} as const;
|
|
7
|
+
export const GTINTypes = pick(NumericIdentifierTypes,
|
|
8
|
+
NumericIdentifierTypes.GTIN
|
|
9
|
+
);
|
|
27
10
|
|
|
28
11
|
/**
|
|
29
12
|
* GTIN type key.
|
|
@@ -34,17 +17,3 @@ export type GTINTypeKey = keyof typeof GTINTypes;
|
|
|
34
17
|
* GTIN type.
|
|
35
18
|
*/
|
|
36
19
|
export type GTINType = typeof GTINTypes[GTINTypeKey];
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* GTIN base type (all except GTIN-14).
|
|
40
|
-
*/
|
|
41
|
-
export type GTINBaseType = Exclude<GTINType, typeof GTINTypes.GTIN14>;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* GTIN base types by prefix type. Used to determine the GTIN type supported by a prefix type.
|
|
45
|
-
*/
|
|
46
|
-
export const GTIN_BASE_TYPES: Readonly<Record<PrefixType, GTINBaseType>> = {
|
|
47
|
-
[PrefixTypes.GS1CompanyPrefix]: GTINTypes.GTIN13,
|
|
48
|
-
[PrefixTypes.UPCCompanyPrefix]: GTINTypes.GTIN12,
|
|
49
|
-
[PrefixTypes.GS18Prefix]: GTINTypes.GTIN8
|
|
50
|
-
};
|