@aidc-toolkit/gs1 1.0.23-beta → 1.0.24-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 +4624 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1588 -0
- package/dist/index.d.ts +1588 -36
- package/dist/index.js +4541 -19
- package/dist/index.js.map +1 -1
- package/package.json +4 -8
- package/src/character-set.ts +16 -1
- package/src/check.ts +2 -2
- package/src/gtin-creator.ts +4 -4
- package/src/gtin-validator.ts +6 -6
- package/src/identifier-creator.ts +3 -3
- package/src/identifier-validator.ts +4 -4
- package/src/index.ts +19 -19
- package/src/locale/i18n.ts +3 -5
- package/src/locale/i18next.d.ts +1 -1
- package/src/non-gtin-numeric-identifier-creator.ts +4 -4
- package/src/non-gtin-numeric-identifier-validator.ts +3 -3
- package/src/non-numeric-identifier-creator.ts +6 -6
- package/src/non-numeric-identifier-validator.ts +6 -6
- package/src/numeric-identifier-creator.ts +3 -3
- package/src/numeric-identifier-validator.ts +5 -5
- package/src/prefix-manager.ts +16 -16
- package/src/prefix-provider.ts +1 -1
- package/src/prefix-validator.ts +2 -2
- package/src/serializable-numeric-identifier-creator.ts +4 -4
- package/src/serializable-numeric-identifier-validator.ts +5 -5
- package/test/creator.test.ts +3 -3
- package/test/gtin-creator.ts +1 -1
- package/test/gtin-validator.test.ts +1 -1
- package/test/identifier-creator.ts +4 -4
- package/test/non-gtin-numeric-identifier-creator.ts +1 -1
- package/test/non-gtin-numeric-identifier-validator.ts +1 -1
- package/test/non-numeric-identifier-validator.ts +2 -2
- package/test/numeric-identifier-creator.ts +1 -1
- package/test/numeric-identifier-validator.ts +1 -1
- package/test/prefix-manager.test.ts +1 -1
- package/test/serializable-numeric-identifier-creator.ts +1 -1
- package/test/serializable-numeric-identifier-validator.ts +2 -2
- package/test/validator.test.ts +4 -4
- package/tsup.config.ts +3 -0
- package/typedoc.json +1 -3
- package/dist/character-set.d.ts +0 -22
- package/dist/character-set.d.ts.map +0 -1
- package/dist/character-set.js +0 -36
- package/dist/character-set.js.map +0 -1
- package/dist/check.d.ts +0 -81
- package/dist/check.d.ts.map +0 -1
- package/dist/check.js +0 -218
- package/dist/check.js.map +0 -1
- package/dist/gtin-creator.d.ts +0 -68
- package/dist/gtin-creator.d.ts.map +0 -1
- package/dist/gtin-creator.js +0 -158
- package/dist/gtin-creator.js.map +0 -1
- package/dist/gtin-validator.d.ts +0 -202
- package/dist/gtin-validator.d.ts.map +0 -1
- package/dist/gtin-validator.js +0 -470
- package/dist/gtin-validator.js.map +0 -1
- package/dist/identifier-creator.d.ts +0 -72
- package/dist/identifier-creator.d.ts.map +0 -1
- package/dist/identifier-creator.js +0 -50
- package/dist/identifier-creator.js.map +0 -1
- package/dist/identifier-type.d.ts +0 -58
- package/dist/identifier-type.d.ts.map +0 -1
- package/dist/identifier-type.js +0 -54
- package/dist/identifier-type.js.map +0 -1
- package/dist/identifier-validator.d.ts +0 -174
- package/dist/identifier-validator.d.ts.map +0 -1
- package/dist/identifier-validator.js +0 -145
- package/dist/identifier-validator.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/locale/en/locale-resources.d.ts +0 -43
- package/dist/locale/en/locale-resources.d.ts.map +0 -1
- package/dist/locale/en/locale-resources.js +0 -42
- package/dist/locale/en/locale-resources.js.map +0 -1
- package/dist/locale/fr/locale-resources.d.ts +0 -43
- package/dist/locale/fr/locale-resources.d.ts.map +0 -1
- package/dist/locale/fr/locale-resources.js +0 -42
- package/dist/locale/fr/locale-resources.js.map +0 -1
- package/dist/locale/i18n.d.ts +0 -27
- package/dist/locale/i18n.d.ts.map +0 -1
- package/dist/locale/i18n.js +0 -37
- package/dist/locale/i18n.js.map +0 -1
- package/dist/non-gtin-numeric-identifier-creator.d.ts +0 -30
- package/dist/non-gtin-numeric-identifier-creator.d.ts.map +0 -1
- package/dist/non-gtin-numeric-identifier-creator.js +0 -30
- package/dist/non-gtin-numeric-identifier-creator.js.map +0 -1
- package/dist/non-gtin-numeric-identifier-validator.d.ts +0 -41
- package/dist/non-gtin-numeric-identifier-validator.d.ts.map +0 -1
- package/dist/non-gtin-numeric-identifier-validator.js +0 -40
- package/dist/non-gtin-numeric-identifier-validator.js.map +0 -1
- package/dist/non-numeric-identifier-creator.d.ts +0 -55
- package/dist/non-numeric-identifier-creator.d.ts.map +0 -1
- package/dist/non-numeric-identifier-creator.js +0 -93
- package/dist/non-numeric-identifier-creator.js.map +0 -1
- package/dist/non-numeric-identifier-validator.d.ts +0 -78
- package/dist/non-numeric-identifier-validator.d.ts.map +0 -1
- package/dist/non-numeric-identifier-validator.js +0 -95
- package/dist/non-numeric-identifier-validator.js.map +0 -1
- package/dist/numeric-identifier-creator.d.ts +0 -121
- package/dist/numeric-identifier-creator.d.ts.map +0 -1
- package/dist/numeric-identifier-creator.js +0 -135
- package/dist/numeric-identifier-creator.js.map +0 -1
- package/dist/numeric-identifier-validator.d.ts +0 -76
- package/dist/numeric-identifier-validator.d.ts.map +0 -1
- package/dist/numeric-identifier-validator.js +0 -84
- package/dist/numeric-identifier-validator.js.map +0 -1
- package/dist/prefix-manager.d.ts +0 -224
- package/dist/prefix-manager.d.ts.map +0 -1
- package/dist/prefix-manager.js +0 -369
- package/dist/prefix-manager.js.map +0 -1
- package/dist/prefix-provider.d.ts +0 -27
- package/dist/prefix-provider.d.ts.map +0 -1
- package/dist/prefix-provider.js +0 -2
- package/dist/prefix-provider.js.map +0 -1
- package/dist/prefix-type.d.ts +0 -22
- package/dist/prefix-type.d.ts.map +0 -1
- package/dist/prefix-type.js +0 -18
- package/dist/prefix-type.js.map +0 -1
- package/dist/prefix-validator.d.ts +0 -58
- package/dist/prefix-validator.d.ts.map +0 -1
- package/dist/prefix-validator.js +0 -154
- package/dist/prefix-validator.js.map +0 -1
- package/dist/serializable-numeric-identifier-creator.d.ts +0 -86
- package/dist/serializable-numeric-identifier-creator.d.ts.map +0 -1
- package/dist/serializable-numeric-identifier-creator.js +0 -116
- package/dist/serializable-numeric-identifier-creator.js.map +0 -1
- package/dist/serializable-numeric-identifier-validator.d.ts +0 -79
- package/dist/serializable-numeric-identifier-validator.d.ts.map +0 -1
- package/dist/serializable-numeric-identifier-validator.js +0 -99
- package/dist/serializable-numeric-identifier-validator.js.map +0 -1
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { Exclusions, RegExpValidator } from "@aidc-toolkit/utility";
|
|
2
|
-
import { hasValidCheckCharacterPair } from "./check.js";
|
|
3
|
-
import { IdentifierTypes } from "./identifier-type.js";
|
|
4
|
-
import { AbstractIdentifierValidator, ContentCharacterSets } from "./identifier-validator.js";
|
|
5
|
-
import { i18nextGS1 } from "./locale/i18n.js";
|
|
6
|
-
import { PrefixTypes } from "./prefix-type.js";
|
|
7
|
-
/**
|
|
8
|
-
* Non-numeric identifier validator.
|
|
9
|
-
*/
|
|
10
|
-
export class NonNumericIdentifierValidator extends AbstractIdentifierValidator {
|
|
11
|
-
/**
|
|
12
|
-
* Validator to ensure that an identifier (minus check character pair) is not all numeric.
|
|
13
|
-
*/
|
|
14
|
-
static NOT_ALL_NUMERIC_VALIDATOR = new class extends RegExpValidator {
|
|
15
|
-
/**
|
|
16
|
-
* @inheritDoc
|
|
17
|
-
*/
|
|
18
|
-
createErrorMessage(_s) {
|
|
19
|
-
return i18nextGS1.t("Identifier.referenceCantBeAllNumeric");
|
|
20
|
-
}
|
|
21
|
-
}(/\D/);
|
|
22
|
-
/**
|
|
23
|
-
* True if the identifier requires a check character pair.
|
|
24
|
-
*/
|
|
25
|
-
_requiresCheckCharacterPair;
|
|
26
|
-
/**
|
|
27
|
-
* Constructor.
|
|
28
|
-
*
|
|
29
|
-
* @param identifierType
|
|
30
|
-
* Identifier type.
|
|
31
|
-
*
|
|
32
|
-
* @param length
|
|
33
|
-
* Length.
|
|
34
|
-
*
|
|
35
|
-
* @param referenceCharacterSet
|
|
36
|
-
* Reference character set.
|
|
37
|
-
*
|
|
38
|
-
* @param requiresCheckCharacterPair
|
|
39
|
-
* True if the identifier requires a check character pair.
|
|
40
|
-
*/
|
|
41
|
-
constructor(identifierType, length, referenceCharacterSet, requiresCheckCharacterPair = false) {
|
|
42
|
-
super(identifierType, PrefixTypes.GS1CompanyPrefix, length, referenceCharacterSet);
|
|
43
|
-
this._requiresCheckCharacterPair = requiresCheckCharacterPair;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Determine if the identifier requires a check character pair.
|
|
47
|
-
*/
|
|
48
|
-
get requiresCheckCharacterPair() {
|
|
49
|
-
return this._requiresCheckCharacterPair;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Validate a non-numeric identifier and throw an error if validation fails.
|
|
53
|
-
*
|
|
54
|
-
* @param identifier
|
|
55
|
-
* Identifier.
|
|
56
|
-
*
|
|
57
|
-
* @param validation
|
|
58
|
-
* Validation parameters.
|
|
59
|
-
*/
|
|
60
|
-
validate(identifier, validation) {
|
|
61
|
-
const partialIdentifier = this.requiresCheckCharacterPair ? identifier.substring(0, identifier.length - 2) : identifier;
|
|
62
|
-
super.validatePrefix(partialIdentifier, validation?.positionOffset);
|
|
63
|
-
if (!this.requiresCheckCharacterPair) {
|
|
64
|
-
this.referenceCreator.validate(identifier, {
|
|
65
|
-
maximumLength: this.length,
|
|
66
|
-
positionOffset: validation?.positionOffset
|
|
67
|
-
});
|
|
68
|
-
// Validating the check character pair will also validate the characters.
|
|
69
|
-
}
|
|
70
|
-
else if (!hasValidCheckCharacterPair(this.padIdentifier(identifier, validation))) {
|
|
71
|
-
throw new RangeError(i18nextGS1.t("Identifier.invalidCheckCharacterPair"));
|
|
72
|
-
}
|
|
73
|
-
// Check for all-numeric identifier (minus check character pair) if excluded.
|
|
74
|
-
if (validation?.exclusion === Exclusions.AllNumeric) {
|
|
75
|
-
NonNumericIdentifierValidator.NOT_ALL_NUMERIC_VALIDATOR.validate(partialIdentifier);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* GIAI validator.
|
|
81
|
-
*/
|
|
82
|
-
export const GIAI_VALIDATOR = new NonNumericIdentifierValidator(IdentifierTypes.GIAI, 30, ContentCharacterSets.AI82);
|
|
83
|
-
/**
|
|
84
|
-
* GINC validator.
|
|
85
|
-
*/
|
|
86
|
-
export const GINC_VALIDATOR = new NonNumericIdentifierValidator(IdentifierTypes.GINC, 30, ContentCharacterSets.AI82);
|
|
87
|
-
/**
|
|
88
|
-
* CPID validator.
|
|
89
|
-
*/
|
|
90
|
-
export const CPID_VALIDATOR = new NonNumericIdentifierValidator(IdentifierTypes.CPID, 30, ContentCharacterSets.AI39);
|
|
91
|
-
/**
|
|
92
|
-
* GMN validator.
|
|
93
|
-
*/
|
|
94
|
-
export const GMN_VALIDATOR = new NonNumericIdentifierValidator(IdentifierTypes.GMN, 25, ContentCharacterSets.AI82, true);
|
|
95
|
-
//# sourceMappingURL=non-numeric-identifier-validator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"non-numeric-identifier-validator.js","sourceRoot":"","sources":["../src/non-numeric-identifier-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAuB,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EACH,2BAA2B,EAE3B,oBAAoB,EAEvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAkB/C;;GAEG;AACH,MAAM,OAAO,6BAA8B,SAAQ,2BAA2D;IAC1G;;OAEG;IACK,MAAM,CAAU,yBAAyB,GAAG,IAAI,KAAM,SAAQ,eAAe;QACjF;;WAEG;QACgB,kBAAkB,CAAC,EAAU;YAC5C,OAAO,UAA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,UAAU,EAAE,CAAC;YAClD,6BAA6B,CAAC,yBAAyB,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;QACxF,CAAC;IACL,CAAC;;AAGL;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,6BAA6B,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,EAAE,oBAAoB,CAAC,IAAI,CAAC,CAAC;AAErH;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,6BAA6B,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,EAAE,oBAAoB,CAAC,IAAI,CAAC,CAAC;AAErH;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,6BAA6B,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,EAAE,oBAAoB,CAAC,IAAI,CAAC,CAAC;AAErH;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,6BAA6B,CAAC,eAAe,CAAC,GAAG,EAAE,EAAE,EAAE,oBAAoB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC"}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { type TransformerInput, type TransformerOutput } from "@aidc-toolkit/utility";
|
|
2
|
-
import { AbstractIdentifierCreator, type IdentifierCreator } from "./identifier-creator.js";
|
|
3
|
-
import { type LeaderType, type NumericIdentifierValidator } from "./numeric-identifier-validator.js";
|
|
4
|
-
import type { PrefixProvider } from "./prefix-provider";
|
|
5
|
-
/**
|
|
6
|
-
* Numeric identifier creator. Creates one or many numeric identifiers.
|
|
7
|
-
*/
|
|
8
|
-
export interface NumericIdentifierCreator extends NumericIdentifierValidator, IdentifierCreator {
|
|
9
|
-
/**
|
|
10
|
-
* Get the capacity (`10**referenceLength`).
|
|
11
|
-
*/
|
|
12
|
-
get capacity(): number;
|
|
13
|
-
/**
|
|
14
|
-
* Create identifier(s) with reference(s) based on numeric value(s). The value(s) is/are converted to
|
|
15
|
-
* references of the appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
16
|
-
*
|
|
17
|
-
* @template TTransformerInput
|
|
18
|
-
* Transformer input type.
|
|
19
|
-
*
|
|
20
|
-
* @param valueOrValues
|
|
21
|
-
* Numeric value(s).
|
|
22
|
-
*
|
|
23
|
-
* @param sparse
|
|
24
|
-
* If true, the value(s) are mapped to a sparse sequence resistant to discovery. Default is false.
|
|
25
|
-
*
|
|
26
|
-
* @returns
|
|
27
|
-
* Identifier(s).
|
|
28
|
-
*/
|
|
29
|
-
create: <TTransformerInput extends TransformerInput<number | bigint>>(valueOrValues: TTransformerInput, sparse?: boolean) => TransformerOutput<TTransformerInput, string>;
|
|
30
|
-
/**
|
|
31
|
-
* Create all identifiers for the prefix from `0` to `capacity - 1`.
|
|
32
|
-
*
|
|
33
|
-
* The implementation creates the strings only as needed using an internal generator function. Although the result
|
|
34
|
-
* is equivalent to calling `creator.create(new Sequence(0, creator.capacity))`, this method is significantly
|
|
35
|
-
* faster.
|
|
36
|
-
*
|
|
37
|
-
* @returns
|
|
38
|
-
* All identifiers for the prefix.
|
|
39
|
-
*/
|
|
40
|
-
createAll: () => Iterable<string>;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Abstract numeric identifier creator. Implements common functionality for a numeric identifier
|
|
44
|
-
* creator.
|
|
45
|
-
*/
|
|
46
|
-
export declare abstract class AbstractNumericIdentifierCreator extends AbstractIdentifierCreator implements NumericIdentifierCreator {
|
|
47
|
-
/**
|
|
48
|
-
* Capacity.
|
|
49
|
-
*/
|
|
50
|
-
private _capacity;
|
|
51
|
-
/**
|
|
52
|
-
* Tweak for sparse creation.
|
|
53
|
-
*/
|
|
54
|
-
private _tweak;
|
|
55
|
-
/**
|
|
56
|
-
* Initialize the prefix provider. This method is in lieu of a constructor due to the mixin architecture.
|
|
57
|
-
*
|
|
58
|
-
* @param prefixProvider
|
|
59
|
-
* Prefix provider.
|
|
60
|
-
*
|
|
61
|
-
* @param prefix
|
|
62
|
-
* Prefix within prefix manager to use to calculate reference length.
|
|
63
|
-
*/
|
|
64
|
-
protected init(prefixProvider: PrefixProvider, prefix: string): void;
|
|
65
|
-
abstract get leaderType(): LeaderType;
|
|
66
|
-
/**
|
|
67
|
-
* @inheritDoc
|
|
68
|
-
*/
|
|
69
|
-
get capacity(): number;
|
|
70
|
-
/**
|
|
71
|
-
* Get the tweak for sparse creation.
|
|
72
|
-
*/
|
|
73
|
-
get tweak(): bigint;
|
|
74
|
-
/**
|
|
75
|
-
* Set the tweak for sparse creation.
|
|
76
|
-
*/
|
|
77
|
-
set tweak(value: bigint);
|
|
78
|
-
/**
|
|
79
|
-
* Build an identifier from a reference by merging it with the prefix and adding the check digit.
|
|
80
|
-
*
|
|
81
|
-
* @param reference
|
|
82
|
-
* Identifier reference.
|
|
83
|
-
*
|
|
84
|
-
* @returns
|
|
85
|
-
* Identifier.
|
|
86
|
-
*/
|
|
87
|
-
private buildIdentifier;
|
|
88
|
-
/**
|
|
89
|
-
* @inheritDoc
|
|
90
|
-
*/
|
|
91
|
-
create<TTransformerInput extends TransformerInput<number | bigint>>(valueOrValues: TTransformerInput, sparse?: boolean): TransformerOutput<TTransformerInput, string>;
|
|
92
|
-
/**
|
|
93
|
-
* Create all identifiers from a partial identifier. Call is recursive until remaining reference
|
|
94
|
-
* length is 0.
|
|
95
|
-
*
|
|
96
|
-
* @param partialIdentifier
|
|
97
|
-
* Partial identifier. Initial value is `this.prefix`.
|
|
98
|
-
*
|
|
99
|
-
* @param remainingReferenceLength
|
|
100
|
-
* Remaining reference length. Initial value is `this.referenceLength`.
|
|
101
|
-
*
|
|
102
|
-
* @param extensionWeight
|
|
103
|
-
* If this value is not zero, the identifier has an extension digit, this call is setting it, and this value
|
|
104
|
-
* is applied to the calculation of the check digit.
|
|
105
|
-
*
|
|
106
|
-
* @param weight
|
|
107
|
-
* If the extension weight is zero, this value is applied to the calculation of the check digit.
|
|
108
|
-
*
|
|
109
|
-
* @param partialCheckDigitSum
|
|
110
|
-
* Partial check digit sum for the partial identifier.
|
|
111
|
-
*
|
|
112
|
-
* @yields
|
|
113
|
-
* Identifier.
|
|
114
|
-
*/
|
|
115
|
-
private static createAllPartial;
|
|
116
|
-
/**
|
|
117
|
-
* @inheritDoc
|
|
118
|
-
*/
|
|
119
|
-
createAll(): Iterable<string>;
|
|
120
|
-
}
|
|
121
|
-
//# sourceMappingURL=numeric-identifier-creator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"numeric-identifier-creator.d.ts","sourceRoot":"","sources":["../src/numeric-identifier-creator.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACzB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,yBAAyB,EAAE,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5F,OAAO,EAAE,KAAK,UAAU,EAAe,KAAK,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAClH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,wBAAyB,SAAQ,0BAA0B,EAAE,iBAAiB;IAC3F;;OAEG;IACH,IAAI,QAAQ,IAAI,MAAM,CAAC;IAEvB;;;;;;;;;;;;;;;OAeG;IACH,MAAM,EAAE,CAAC,iBAAiB,SAAS,gBAAgB,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,iBAAiB,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;IAE1K;;;;;;;;;OASG;IACH,SAAS,EAAE,MAAM,QAAQ,CAAC,MAAM,CAAC,CAAC;CACrC;AAED;;;GAGG;AACH,8BAAsB,gCAAiC,SAAQ,yBAA0B,YAAW,wBAAwB;IACxH;;OAEG;IACH,OAAO,CAAC,SAAS,CAAU;IAE3B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAM;IAEpB;;;;;;;;OAQG;cACgB,IAAI,CAAC,cAAc,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAO7E,QAAQ,KAAK,UAAU,IAAI,UAAU,CAAC;IAEtC;;OAEG;IACH,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;OAEG;IACH,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAEtB;IAED;;;;;;;;OAQG;IACH,OAAO,CAAC,eAAe;IAMvB;;OAEG;IACH,MAAM,CAAC,iBAAiB,SAAS,gBAAgB,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,UAAQ,GAAG,iBAAiB,CAAC,iBAAiB,EAAE,MAAM,CAAC;IAInK;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,OAAO,CAAC,MAAM,CAAG,gBAAgB;IA6BjC;;OAEG;IACH,SAAS,IAAI,QAAQ,CAAC,MAAM,CAAC;CAgBhC"}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { CharacterSetCreator, Exclusions, NUMERIC_CREATOR } from "@aidc-toolkit/utility";
|
|
2
|
-
import { checkDigit, checkDigitSum } from "./check.js";
|
|
3
|
-
import { AbstractIdentifierCreator } from "./identifier-creator.js";
|
|
4
|
-
import { LeaderTypes } from "./numeric-identifier-validator.js";
|
|
5
|
-
/**
|
|
6
|
-
* Abstract numeric identifier creator. Implements common functionality for a numeric identifier
|
|
7
|
-
* creator.
|
|
8
|
-
*/
|
|
9
|
-
export class AbstractNumericIdentifierCreator extends AbstractIdentifierCreator {
|
|
10
|
-
/**
|
|
11
|
-
* Capacity.
|
|
12
|
-
*/
|
|
13
|
-
_capacity;
|
|
14
|
-
/**
|
|
15
|
-
* Tweak for sparse creation.
|
|
16
|
-
*/
|
|
17
|
-
_tweak = 0n;
|
|
18
|
-
/**
|
|
19
|
-
* Initialize the prefix provider. This method is in lieu of a constructor due to the mixin architecture.
|
|
20
|
-
*
|
|
21
|
-
* @param prefixProvider
|
|
22
|
-
* Prefix provider.
|
|
23
|
-
*
|
|
24
|
-
* @param prefix
|
|
25
|
-
* Prefix within prefix manager to use to calculate reference length.
|
|
26
|
-
*/
|
|
27
|
-
init(prefixProvider, prefix) {
|
|
28
|
-
super.init(prefixProvider, prefix, 1);
|
|
29
|
-
// Capacity is always in number range.
|
|
30
|
-
this._capacity = Number(CharacterSetCreator.powerOf10(this.referenceLength));
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* @inheritDoc
|
|
34
|
-
*/
|
|
35
|
-
get capacity() {
|
|
36
|
-
return this._capacity;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Get the tweak for sparse creation.
|
|
40
|
-
*/
|
|
41
|
-
get tweak() {
|
|
42
|
-
return this._tweak;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Set the tweak for sparse creation.
|
|
46
|
-
*/
|
|
47
|
-
set tweak(value) {
|
|
48
|
-
this._tweak = value;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Build an identifier from a reference by merging it with the prefix and adding the check digit.
|
|
52
|
-
*
|
|
53
|
-
* @param reference
|
|
54
|
-
* Identifier reference.
|
|
55
|
-
*
|
|
56
|
-
* @returns
|
|
57
|
-
* Identifier.
|
|
58
|
-
*/
|
|
59
|
-
buildIdentifier(reference) {
|
|
60
|
-
const partialIdentifier = this.leaderType === LeaderTypes.ExtensionDigit ? reference.substring(0, 1) + this.prefix + reference.substring(1) : this.prefix + reference;
|
|
61
|
-
return partialIdentifier + checkDigit(partialIdentifier);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* @inheritDoc
|
|
65
|
-
*/
|
|
66
|
-
create(valueOrValues, sparse = false) {
|
|
67
|
-
return NUMERIC_CREATOR.create(this.referenceLength, valueOrValues, Exclusions.None, sparse ? this.tweak : undefined, reference => this.buildIdentifier(reference));
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Create all identifiers from a partial identifier. Call is recursive until remaining reference
|
|
71
|
-
* length is 0.
|
|
72
|
-
*
|
|
73
|
-
* @param partialIdentifier
|
|
74
|
-
* Partial identifier. Initial value is `this.prefix`.
|
|
75
|
-
*
|
|
76
|
-
* @param remainingReferenceLength
|
|
77
|
-
* Remaining reference length. Initial value is `this.referenceLength`.
|
|
78
|
-
*
|
|
79
|
-
* @param extensionWeight
|
|
80
|
-
* If this value is not zero, the identifier has an extension digit, this call is setting it, and this value
|
|
81
|
-
* is applied to the calculation of the check digit.
|
|
82
|
-
*
|
|
83
|
-
* @param weight
|
|
84
|
-
* If the extension weight is zero, this value is applied to the calculation of the check digit.
|
|
85
|
-
*
|
|
86
|
-
* @param partialCheckDigitSum
|
|
87
|
-
* Partial check digit sum for the partial identifier.
|
|
88
|
-
*
|
|
89
|
-
* @yields
|
|
90
|
-
* Identifier.
|
|
91
|
-
*/
|
|
92
|
-
static *createAllPartial(partialIdentifier, remainingReferenceLength, extensionWeight, weight, partialCheckDigitSum) {
|
|
93
|
-
if (remainingReferenceLength === 0) {
|
|
94
|
-
// Finalize check digit calculation and append.
|
|
95
|
-
yield partialIdentifier + NUMERIC_CREATOR.character(9 - (partialCheckDigitSum + 9) % 10);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
const nextRemainingReferenceLength = remainingReferenceLength - 1;
|
|
99
|
-
let nextPartialCheckDigitSum = partialCheckDigitSum;
|
|
100
|
-
if (extensionWeight !== 0) {
|
|
101
|
-
// Apply every digit to the extension digit.
|
|
102
|
-
for (const c of NUMERIC_CREATOR.characterSet) {
|
|
103
|
-
yield* AbstractNumericIdentifierCreator.createAllPartial(c + partialIdentifier, nextRemainingReferenceLength, 0, weight, nextPartialCheckDigitSum);
|
|
104
|
-
nextPartialCheckDigitSum += extensionWeight;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
const nextWeight = 4 - weight;
|
|
109
|
-
// Apply every digit to the current character in the identifier.
|
|
110
|
-
for (const c of NUMERIC_CREATOR.characterSet) {
|
|
111
|
-
yield* AbstractNumericIdentifierCreator.createAllPartial(partialIdentifier + c, nextRemainingReferenceLength, 0, nextWeight, nextPartialCheckDigitSum);
|
|
112
|
-
nextPartialCheckDigitSum += weight;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* @inheritDoc
|
|
119
|
-
*/
|
|
120
|
-
createAll() {
|
|
121
|
-
const hasExtensionDigit = this.leaderType === LeaderTypes.ExtensionDigit;
|
|
122
|
-
const prefix = this.prefix;
|
|
123
|
-
const length = this.length;
|
|
124
|
-
const referenceLength = this.referenceLength;
|
|
125
|
-
// Start weight is for reference excluding extension digit, which has its weight calculated separately.
|
|
126
|
-
const startWeight = 3 - 2 * ((referenceLength + 1 - Number(hasExtensionDigit)) % 2);
|
|
127
|
-
// Returning separate Iterable object makes iteration repeatable.
|
|
128
|
-
return {
|
|
129
|
-
[Symbol.iterator]() {
|
|
130
|
-
return AbstractNumericIdentifierCreator.createAllPartial(prefix, referenceLength, hasExtensionDigit ? 3 - 2 * length % 2 : 0, startWeight, checkDigitSum(startWeight === 3, prefix));
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
//# sourceMappingURL=numeric-identifier-creator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"numeric-identifier-creator.js","sourceRoot":"","sources":["../src/numeric-identifier-creator.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,mBAAmB,EACnB,UAAU,EACV,eAAe,EAGlB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,yBAAyB,EAA0B,MAAM,yBAAyB,CAAC;AAC5F,OAAO,EAAmB,WAAW,EAAm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ACL,CAAC;IAED;;OAEG;IACH,SAAS;QACL,MAAM,iBAAiB,GAAG,IAAI,CAAC,UAAU,KAAK,WAAW,CAAC,cAAc,CAAC;QACzE,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAE7C,uGAAuG;QACvG,MAAM,WAAW,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,eAAe,GAAG,CAAC,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAEpF,iEAAiE;QACjE,OAAO;YACH,CAAC,MAAM,CAAC,QAAQ,CAAC;gBACb,OAAO,gCAAgC,CAAC,gBAAgB,CAAC,MAAM,EAAE,eAAe,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,aAAa,CAAC,WAAW,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;YACzL,CAAC;SACJ,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { IdentifierType, IdentifierTypes } from "./identifier-type.js";
|
|
2
|
-
import { AbstractIdentifierValidator, type IdentifierValidation, type IdentifierValidator } from "./identifier-validator.js";
|
|
3
|
-
import type { PrefixType } from "./prefix-type.js";
|
|
4
|
-
/**
|
|
5
|
-
* Numeric identifier type.
|
|
6
|
-
*/
|
|
7
|
-
export type NumericIdentifierType = typeof IdentifierTypes.GTIN | typeof IdentifierTypes.GLN | typeof IdentifierTypes.SSCC | typeof IdentifierTypes.GRAI | typeof IdentifierTypes.GSRN | typeof IdentifierTypes.GDTI | typeof IdentifierTypes.GSIN | typeof IdentifierTypes.GCN;
|
|
8
|
-
/**
|
|
9
|
-
* Leader type.
|
|
10
|
-
*/
|
|
11
|
-
export declare const LeaderTypes: {
|
|
12
|
-
/**
|
|
13
|
-
* No leader.
|
|
14
|
-
*/
|
|
15
|
-
None: string;
|
|
16
|
-
/**
|
|
17
|
-
* Indicator digit (GTIN only).
|
|
18
|
-
*/
|
|
19
|
-
IndicatorDigit: string;
|
|
20
|
-
/**
|
|
21
|
-
* Extension digit (SSCC only).
|
|
22
|
-
*/
|
|
23
|
-
ExtensionDigit: string;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Leader type.
|
|
27
|
-
*/
|
|
28
|
-
export type LeaderType = typeof LeaderTypes[keyof typeof LeaderTypes];
|
|
29
|
-
/**
|
|
30
|
-
* Numeric identifier validator. Validates a numeric identifier.
|
|
31
|
-
*/
|
|
32
|
-
export interface NumericIdentifierValidator extends IdentifierValidator {
|
|
33
|
-
/**
|
|
34
|
-
* Get the leader type.
|
|
35
|
-
*/
|
|
36
|
-
get leaderType(): LeaderType;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Abstract numeric identifier validator. Implements common functionality for a numeric identifier
|
|
40
|
-
* validator.
|
|
41
|
-
*/
|
|
42
|
-
export declare abstract class AbstractNumericIdentifierValidator extends AbstractIdentifierValidator implements NumericIdentifierValidator {
|
|
43
|
-
/**
|
|
44
|
-
* Leader type.
|
|
45
|
-
*/
|
|
46
|
-
private readonly _leaderType;
|
|
47
|
-
/**
|
|
48
|
-
* Prefix position, determined by the leader type.
|
|
49
|
-
*/
|
|
50
|
-
private readonly _prefixPosition;
|
|
51
|
-
/**
|
|
52
|
-
* Constructor.
|
|
53
|
-
*
|
|
54
|
-
* @param identifierType
|
|
55
|
-
* Identifier type.
|
|
56
|
-
*
|
|
57
|
-
* @param prefixType
|
|
58
|
-
* Prefix type.
|
|
59
|
-
*
|
|
60
|
-
* @param length
|
|
61
|
-
* Length.
|
|
62
|
-
*
|
|
63
|
-
* @param leaderType
|
|
64
|
-
* Leader type.
|
|
65
|
-
*/
|
|
66
|
-
protected constructor(identifierType: IdentifierType, prefixType: PrefixType, length: number, leaderType: LeaderType);
|
|
67
|
-
/**
|
|
68
|
-
* @inheritDoc
|
|
69
|
-
*/
|
|
70
|
-
get leaderType(): LeaderType;
|
|
71
|
-
/**
|
|
72
|
-
* @inheritDoc
|
|
73
|
-
*/
|
|
74
|
-
validate(identifier: string, validation?: IdentifierValidation): void;
|
|
75
|
-
}
|
|
76
|
-
//# sourceMappingURL=numeric-identifier-validator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"numeric-identifier-validator.d.ts","sourceRoot":"","sources":["../src/numeric-identifier-validator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EACH,2BAA2B,EAE3B,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EAC3B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAC7B,OAAO,eAAe,CAAC,IAAI,GAC3B,OAAO,eAAe,CAAC,GAAG,GAC1B,OAAO,eAAe,CAAC,IAAI,GAC3B,OAAO,eAAe,CAAC,IAAI,GAC3B,OAAO,eAAe,CAAC,IAAI,GAC3B,OAAO,eAAe,CAAC,IAAI,GAC3B,OAAO,eAAe,CAAC,IAAI,GAC3B,OAAO,eAAe,CAAC,GAAG,CAAC;AAE/B;;GAEG;AACH,eAAO,MAAM,WAAW;IACpB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;CAEN,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,WAAW,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,0BAA2B,SAAQ,mBAAmB;IACnE;;OAEG;IACH,IAAI,UAAU,IAAI,UAAU,CAAC;CAChC;AAED;;;GAGG;AACH,8BAAsB,kCAAmC,SAAQ,2BAA4B,YAAW,0BAA0B;IAC9H;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAa;IAEzC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IAEzC;;;;;;;;;;;;;;OAcG;IACH,SAAS,aAAa,cAAc,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU;IAOpH;;OAEG;IACH,IAAI,UAAU,IAAI,UAAU,CAE3B;IAED;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,oBAAoB,GAAG,IAAI;CAqBxE"}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { hasValidCheckDigit } from "./check.js";
|
|
2
|
-
import { AbstractIdentifierValidator, ContentCharacterSets } from "./identifier-validator.js";
|
|
3
|
-
import { i18nextGS1 } from "./locale/i18n.js";
|
|
4
|
-
/**
|
|
5
|
-
* Leader type.
|
|
6
|
-
*/
|
|
7
|
-
export const LeaderTypes = {
|
|
8
|
-
/**
|
|
9
|
-
* No leader.
|
|
10
|
-
*/
|
|
11
|
-
None: "None",
|
|
12
|
-
/**
|
|
13
|
-
* Indicator digit (GTIN only).
|
|
14
|
-
*/
|
|
15
|
-
IndicatorDigit: "Indicator digit",
|
|
16
|
-
/**
|
|
17
|
-
* Extension digit (SSCC only).
|
|
18
|
-
*/
|
|
19
|
-
ExtensionDigit: "Extension digit"
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Abstract numeric identifier validator. Implements common functionality for a numeric identifier
|
|
23
|
-
* validator.
|
|
24
|
-
*/
|
|
25
|
-
export class AbstractNumericIdentifierValidator extends AbstractIdentifierValidator {
|
|
26
|
-
/**
|
|
27
|
-
* Leader type.
|
|
28
|
-
*/
|
|
29
|
-
_leaderType;
|
|
30
|
-
/**
|
|
31
|
-
* Prefix position, determined by the leader type.
|
|
32
|
-
*/
|
|
33
|
-
_prefixPosition;
|
|
34
|
-
/**
|
|
35
|
-
* Constructor.
|
|
36
|
-
*
|
|
37
|
-
* @param identifierType
|
|
38
|
-
* Identifier type.
|
|
39
|
-
*
|
|
40
|
-
* @param prefixType
|
|
41
|
-
* Prefix type.
|
|
42
|
-
*
|
|
43
|
-
* @param length
|
|
44
|
-
* Length.
|
|
45
|
-
*
|
|
46
|
-
* @param leaderType
|
|
47
|
-
* Leader type.
|
|
48
|
-
*/
|
|
49
|
-
constructor(identifierType, prefixType, length, leaderType) {
|
|
50
|
-
super(identifierType, prefixType, length, ContentCharacterSets.Numeric);
|
|
51
|
-
this._leaderType = leaderType;
|
|
52
|
-
this._prefixPosition = Number(this.leaderType === LeaderTypes.ExtensionDigit);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* @inheritDoc
|
|
56
|
-
*/
|
|
57
|
-
get leaderType() {
|
|
58
|
-
return this._leaderType;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* @inheritDoc
|
|
62
|
-
*/
|
|
63
|
-
validate(identifier, validation) {
|
|
64
|
-
// Validate the prefix, with care taken for its position within the identifier.
|
|
65
|
-
if (this._prefixPosition === 0) {
|
|
66
|
-
super.validatePrefix(identifier, validation?.positionOffset);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
super.validatePrefix(identifier.substring(this._prefixPosition), validation?.positionOffset === undefined ? this._prefixPosition : validation.positionOffset + this._prefixPosition);
|
|
70
|
-
}
|
|
71
|
-
// Validate the length.
|
|
72
|
-
if (identifier.length !== this.length) {
|
|
73
|
-
throw new RangeError(i18nextGS1.t("Identifier.identifierTypeLength", {
|
|
74
|
-
identifierType: this.identifierType,
|
|
75
|
-
length: this.length
|
|
76
|
-
}));
|
|
77
|
-
}
|
|
78
|
-
// Validating the check digit will also validate the characters.
|
|
79
|
-
if (!hasValidCheckDigit(this.padIdentifier(identifier, validation))) {
|
|
80
|
-
throw new RangeError(i18nextGS1.t("Identifier.invalidCheckDigit"));
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
//# sourceMappingURL=numeric-identifier-validator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"numeric-identifier-validator.js","sourceRoot":"","sources":["../src/numeric-identifier-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EACH,2BAA2B,EAC3B,oBAAoB,EAGvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAgB9C;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACvB;;OAEG;IACH,IAAI,EAAE,MAAM;IAEZ;;OAEG;IACH,cAAc,EAAE,iBAAiB;IAEjC;;OAEG;IACH,cAAc,EAAE,iBAAiB;CACpC,CAAC;AAiBF;;;GAGG;AACH,MAAM,OAAgB,kCAAmC,SAAQ,2BAA2B;IACxF;;OAEG;IACc,WAAW,CAAa;IAEzC;;OAEG;IACc,eAAe,CAAS;IAEzC;;;;;;;;;;;;;;OAcG;IACH,YAAsB,cAA8B,EAAE,UAAsB,EAAE,MAAc,EAAE,UAAsB;QAChH,KAAK,CAAC,cAAc,EAAE,UAAU,EAAE,MAAM,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAExE,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,KAAK,WAAW,CAAC,cAAc,CAAC,CAAC;IAClF,CAAC;IAED;;OAEG;IACH,IAAI,UAAU;QACV,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,UAAkB,EAAE,UAAiC;QAC1D,+EAA+E;QAC/E,IAAI,IAAI,CAAC,eAAe,KAAK,CAAC,EAAE,CAAC;YAC7B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