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