@aidc-toolkit/gs1 1.0.23-beta → 1.0.25-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +4813 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1949 -0
- package/dist/index.d.ts +1949 -36
- package/dist/index.js +4727 -19
- package/dist/index.js.map +1 -1
- package/package.json +8 -12
- package/src/abstract-identifier-creator.ts +97 -0
- package/src/abstract-identifier-validator.ts +140 -0
- package/{dist/numeric-identifier-creator.js → src/abstract-numeric-identifier-creator.ts} +61 -28
- package/src/abstract-numeric-identifier-validator.ts +69 -0
- package/src/character-set.ts +24 -9
- package/src/check.ts +9 -9
- package/src/content-character-set.ts +29 -0
- package/src/creators.ts +113 -0
- package/src/descriptors.ts +332 -0
- package/src/gtin-creator.ts +9 -8
- package/src/gtin-descriptor.ts +18 -0
- package/src/gtin-type.ts +50 -0
- package/src/gtin-validator.ts +40 -64
- package/src/identifier-creator.ts +11 -75
- package/src/identifier-descriptor.ts +30 -0
- package/src/identifier-type.ts +6 -1
- package/src/identifier-validator.ts +12 -188
- package/src/index.ts +43 -19
- package/src/locale/en/locale-resources.ts +0 -1
- package/src/locale/fr/locale-resources.ts +0 -1
- package/src/locale/i18n.ts +3 -5
- package/src/locale/i18next.d.ts +1 -1
- package/src/non-gtin-numeric-identifier-creator.ts +6 -12
- package/src/non-gtin-numeric-identifier-descriptor.ts +24 -0
- package/src/non-gtin-numeric-identifier-type.ts +7 -0
- package/src/non-gtin-numeric-identifier-validator.ts +8 -42
- package/src/non-numeric-identifier-creator.ts +8 -18
- package/src/non-numeric-identifier-descriptor.ts +29 -0
- package/src/non-numeric-identifier-type.ts +7 -0
- package/src/non-numeric-identifier-validator.ts +17 -55
- package/src/numeric-identifier-creator.ts +20 -163
- package/src/numeric-identifier-descriptor.ts +23 -0
- package/src/numeric-identifier-type.ts +44 -0
- package/src/numeric-identifier-validator.ts +13 -116
- package/src/prefix-manager.ts +94 -152
- package/src/prefix-provider.ts +3 -3
- package/src/prefix-type.ts +6 -1
- package/src/prefix-validator.ts +143 -81
- package/src/serializable-numeric-identifier-creator.ts +5 -15
- package/src/serializable-numeric-identifier-descriptor.ts +29 -0
- package/src/serializable-numeric-identifier-type.ts +9 -0
- package/src/serializable-numeric-identifier-validator.ts +18 -46
- package/src/validators.ts +203 -0
- package/test/creator.test.ts +4 -6
- package/test/gtin-creator.ts +6 -2
- package/test/gtin-validator.test.ts +6 -9
- package/test/identifier-creator.ts +5 -4
- package/test/identifier-validator.ts +2 -2
- package/test/non-gtin-numeric-identifier-creator.ts +9 -93
- package/test/non-gtin-numeric-identifier-validator.ts +2 -2
- package/test/non-numeric-identifier-creator.ts +93 -0
- package/test/non-numeric-identifier-validator.ts +2 -2
- package/test/numeric-identifier-creator.ts +11 -5
- package/test/numeric-identifier-validator.ts +4 -8
- package/test/prefix-manager.test.ts +1 -1
- package/test/serializable-numeric-identifier-creator.ts +11 -3
- package/test/serializable-numeric-identifier-validator.ts +2 -2
- package/test/validator.test.ts +63 -39
- 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.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,UAAU,CAAC,CAAC,CAAC,sCAAsC,CAAC,CAAC;QAChE,CAAC;KACJ,CAAC,IAAI,CAAC,CAAC;IAER;;OAEG;IACc,2BAA2B,CAAU;IAEtD;;;;;;;;;;;;;;OAcG;IACH,YAAY,cAA8B,EAAE,MAAc,EAAE,qBAA0C,EAAE,0BAA0B,GAAG,KAAK;QACtI,KAAK,CAAC,cAAc,EAAE,WAAW,CAAC,gBAAgB,EAAE,MAAM,EAAE,qBAAqB,CAAC,CAAC;QAEnF,IAAI,CAAC,2BAA2B,GAAG,0BAA0B,CAAC;IAClE,CAAC;IAED;;OAEG;IACH,IAAI,0BAA0B;QAC1B,OAAO,IAAI,CAAC,2BAA2B,CAAC;IAC5C,CAAC;IAED;;;;;;;;OAQG;IACH,QAAQ,CAAC,UAAkB,EAAE,UAA2C;QACpE,MAAM,iBAAiB,GAAG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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,O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
|
|
|
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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;QACvE,CAAC;IACL,CAAC;CACJ"}
|
package/dist/prefix-manager.d.ts
DELETED
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import { GTINCreator } from "./gtin-creator.js";
|
|
2
|
-
import { NonGTINNumericIdentifierCreator } from "./non-gtin-numeric-identifier-creator.js";
|
|
3
|
-
import { NonNumericIdentifierCreator } from "./non-numeric-identifier-creator.js";
|
|
4
|
-
import type { PrefixProvider } from "./prefix-provider.js";
|
|
5
|
-
import { type PrefixType } from "./prefix-type.js";
|
|
6
|
-
import { SerializableNumericIdentifierCreator } from "./serializable-numeric-identifier-creator.js";
|
|
7
|
-
/**
|
|
8
|
-
* Prefix manager. This is the core class for identifier creation.
|
|
9
|
-
*
|
|
10
|
-
* A prefix manager may be created for any {@link PrefixType | prefix type}. As most applications work with a limited
|
|
11
|
-
* number of prefixes for creating identifiers, prefix managers are cached in memory and may be reused.
|
|
12
|
-
*
|
|
13
|
-
* Prefix managers are keyed by GS1 Company Prefix, so the prefix type that is requested may not match the prefix type
|
|
14
|
-
* of the returned prefix manager. For example, the prefix manager for GS1 Company Prefix 0614141 is identical to the
|
|
15
|
-
* one for U.P.C. Company Prefix 614141, with the prefix type equal to {@link PrefixTypes.UPCCompanyPrefix} and the
|
|
16
|
-
* prefix equal to "614141".
|
|
17
|
-
*
|
|
18
|
-
* To support the creation of sparse identifiers, a prefix manager maintains a {@link tweakFactor | tweak
|
|
19
|
-
* factor} which is used, along with a type-specific multiplier, as the tweak when creating numeric identifiers.
|
|
20
|
-
* The default tweak factor is the numeric value of the GS1 Company Prefix representation of the prefix preceded by '1'
|
|
21
|
-
* to ensure uniqueness (i.e., so that prefixes 0 N1 N2 N3... and N1 N2 N3... produce different tweak factors). This is
|
|
22
|
-
* usually sufficient for obfuscation, but as the sparse creation algorithm is reversible and as the GS1 Company Prefix
|
|
23
|
-
* is discoverable via {@link https://www.gs1.org/services/verified-by-gs1 | Verified by GS1}, a user-defined tweak
|
|
24
|
-
* factor should be used if a higher degree of obfuscation is required. When using a tweak factor other than the
|
|
25
|
-
* default, care should be taken to restore it when resuming the application. A tweak factor of 0 creates a straight
|
|
26
|
-
* sequence.
|
|
27
|
-
*/
|
|
28
|
-
export declare class PrefixManager implements PrefixProvider {
|
|
29
|
-
/**
|
|
30
|
-
* Cached prefix managers, keyed by GS1 Company Prefix.
|
|
31
|
-
*/
|
|
32
|
-
private static readonly PREFIX_MANAGERS_MAP;
|
|
33
|
-
/**
|
|
34
|
-
* Creator tweak factors. Different numeric identifier types have different tweak factors so that sparse creation
|
|
35
|
-
* generates different sequences for each.
|
|
36
|
-
*/
|
|
37
|
-
private static readonly CREATOR_TWEAK_FACTORS;
|
|
38
|
-
/**
|
|
39
|
-
* Normalized prefix type.
|
|
40
|
-
*/
|
|
41
|
-
private readonly _prefixType;
|
|
42
|
-
/**
|
|
43
|
-
* Normalized prefix.
|
|
44
|
-
*/
|
|
45
|
-
private readonly _prefix;
|
|
46
|
-
/**
|
|
47
|
-
* Prefix as GS1 Company Prefix.
|
|
48
|
-
*/
|
|
49
|
-
private readonly _gs1CompanyPrefix;
|
|
50
|
-
/**
|
|
51
|
-
* U.P.C. Company Prefix if prefix type is {@link PrefixTypes.UPCCompanyPrefix}.
|
|
52
|
-
*/
|
|
53
|
-
private readonly _upcCompanyPrefix;
|
|
54
|
-
/**
|
|
55
|
-
* GS1-8 Prefix if prefix type is {@link PrefixTypes.GS18Prefix}.
|
|
56
|
-
*/
|
|
57
|
-
private readonly _gs18Prefix;
|
|
58
|
-
/**
|
|
59
|
-
* Default tweak factor.
|
|
60
|
-
*/
|
|
61
|
-
private readonly _defaultTweakFactor;
|
|
62
|
-
/**
|
|
63
|
-
* Tweak factor.
|
|
64
|
-
*/
|
|
65
|
-
private _tweakFactor;
|
|
66
|
-
/**
|
|
67
|
-
* Cached identifier creators.
|
|
68
|
-
*/
|
|
69
|
-
private readonly _identifierCreators;
|
|
70
|
-
/**
|
|
71
|
-
* Constructor.
|
|
72
|
-
*
|
|
73
|
-
* @param gs1CompanyPrefix
|
|
74
|
-
* GS1 Company Prefix.
|
|
75
|
-
*/
|
|
76
|
-
private constructor();
|
|
77
|
-
/**
|
|
78
|
-
* Get the prefix type.
|
|
79
|
-
*/
|
|
80
|
-
get prefixType(): PrefixType;
|
|
81
|
-
/**
|
|
82
|
-
* Get the prefix.
|
|
83
|
-
*/
|
|
84
|
-
get prefix(): string;
|
|
85
|
-
/**
|
|
86
|
-
* Get the GS1 Company Prefix.
|
|
87
|
-
*/
|
|
88
|
-
get gs1CompanyPrefix(): string;
|
|
89
|
-
/**
|
|
90
|
-
* Get the U.P.C. Company Prefix if prefix type is {@link PrefixTypes.UPCCompanyPrefix} or undefined if not.
|
|
91
|
-
*/
|
|
92
|
-
get upcCompanyPrefix(): string | undefined;
|
|
93
|
-
/**
|
|
94
|
-
* Get the GS1-8 Prefix if prefix type is {@link PrefixTypes.GS18Prefix} or undefined if not.
|
|
95
|
-
*/
|
|
96
|
-
get gs18Prefix(): string | undefined;
|
|
97
|
-
/**
|
|
98
|
-
* Set the tweak for an identifier creator if it's a numeric identifier creator.
|
|
99
|
-
*
|
|
100
|
-
* @param creator
|
|
101
|
-
* Identifier creator.
|
|
102
|
-
*/
|
|
103
|
-
private setCreatorTweak;
|
|
104
|
-
/**
|
|
105
|
-
* Get the tweak factor.
|
|
106
|
-
*/
|
|
107
|
-
get tweakFactor(): bigint;
|
|
108
|
-
/**
|
|
109
|
-
* Set the tweak factor.
|
|
110
|
-
*
|
|
111
|
-
* @param value
|
|
112
|
-
* Tweak factor.
|
|
113
|
-
*/
|
|
114
|
-
set tweakFactor(value: number | bigint);
|
|
115
|
-
/**
|
|
116
|
-
* Reset the tweak factor to its default (numeric value of the GS1 Company Prefix preceded by '1').
|
|
117
|
-
*/
|
|
118
|
-
resetTweakFactor(): void;
|
|
119
|
-
/**
|
|
120
|
-
* Get a prefix manager.
|
|
121
|
-
*
|
|
122
|
-
* @param prefixType
|
|
123
|
-
* Prefix type.
|
|
124
|
-
*
|
|
125
|
-
* @param prefix
|
|
126
|
-
* Prefix.
|
|
127
|
-
*
|
|
128
|
-
* @returns
|
|
129
|
-
* Prefix manager with normalized prefix type and prefix.
|
|
130
|
-
*/
|
|
131
|
-
static get(prefixType: PrefixType, prefix: string): PrefixManager;
|
|
132
|
-
/**
|
|
133
|
-
* Get an identifier creator.
|
|
134
|
-
*
|
|
135
|
-
* @param identifierType
|
|
136
|
-
* Identifier type.
|
|
137
|
-
*
|
|
138
|
-
* @param constructorCallback
|
|
139
|
-
* Constructor callback.
|
|
140
|
-
*
|
|
141
|
-
* @returns
|
|
142
|
-
* Identifier creator.
|
|
143
|
-
*/
|
|
144
|
-
private getIdentifierCreator;
|
|
145
|
-
/**
|
|
146
|
-
* Get non-GTIN numeric identifier creator.
|
|
147
|
-
*
|
|
148
|
-
* @param validator
|
|
149
|
-
* Validator on which identifier creator is based.
|
|
150
|
-
*
|
|
151
|
-
* @returns
|
|
152
|
-
* Identifier creator.
|
|
153
|
-
*/
|
|
154
|
-
private getNonGTINNumericIdentifierCreator;
|
|
155
|
-
/**
|
|
156
|
-
* Get serialized numeric identifier creator.
|
|
157
|
-
*
|
|
158
|
-
* @param validator
|
|
159
|
-
* Validator on which identifier creator is based.
|
|
160
|
-
*
|
|
161
|
-
* @returns
|
|
162
|
-
* Identifier creator.
|
|
163
|
-
*/
|
|
164
|
-
private getSerializableNumericIdentifierCreator;
|
|
165
|
-
/**
|
|
166
|
-
* Get non-numeric identifier creator.
|
|
167
|
-
*
|
|
168
|
-
* @param validator
|
|
169
|
-
* Validator on which identifier creator is based.
|
|
170
|
-
*
|
|
171
|
-
* @returns
|
|
172
|
-
* Identifier creator.
|
|
173
|
-
*/
|
|
174
|
-
private getNonNumericIdentifierCreator;
|
|
175
|
-
/**
|
|
176
|
-
* Get GTIN creator.
|
|
177
|
-
*/
|
|
178
|
-
get gtinCreator(): GTINCreator;
|
|
179
|
-
/**
|
|
180
|
-
* Get GLN creator.
|
|
181
|
-
*/
|
|
182
|
-
get glnCreator(): NonGTINNumericIdentifierCreator;
|
|
183
|
-
/**
|
|
184
|
-
* Get SSCC creator.
|
|
185
|
-
*/
|
|
186
|
-
get ssccCreator(): NonGTINNumericIdentifierCreator;
|
|
187
|
-
/**
|
|
188
|
-
* Get GRAI creator.
|
|
189
|
-
*/
|
|
190
|
-
get graiCreator(): SerializableNumericIdentifierCreator;
|
|
191
|
-
/**
|
|
192
|
-
* Get GIAI creator.
|
|
193
|
-
*/
|
|
194
|
-
get giaiCreator(): NonNumericIdentifierCreator;
|
|
195
|
-
/**
|
|
196
|
-
* Get GSRN creator.
|
|
197
|
-
*/
|
|
198
|
-
get gsrnCreator(): NonGTINNumericIdentifierCreator;
|
|
199
|
-
/**
|
|
200
|
-
* Get GDTI creator.
|
|
201
|
-
*/
|
|
202
|
-
get gdtiCreator(): SerializableNumericIdentifierCreator;
|
|
203
|
-
/**
|
|
204
|
-
* Get GINC creator.
|
|
205
|
-
*/
|
|
206
|
-
get gincCreator(): NonNumericIdentifierCreator;
|
|
207
|
-
/**
|
|
208
|
-
* Get GSIN creator.
|
|
209
|
-
*/
|
|
210
|
-
get gsinCreator(): NonGTINNumericIdentifierCreator;
|
|
211
|
-
/**
|
|
212
|
-
* Get GCN creator.
|
|
213
|
-
*/
|
|
214
|
-
get gcnCreator(): SerializableNumericIdentifierCreator;
|
|
215
|
-
/**
|
|
216
|
-
* Get CPID creator.
|
|
217
|
-
*/
|
|
218
|
-
get cpidCreator(): NonNumericIdentifierCreator;
|
|
219
|
-
/**
|
|
220
|
-
* Get GMN creator.
|
|
221
|
-
*/
|
|
222
|
-
get gmnCreator(): NonNumericIdentifierCreator;
|
|
223
|
-
}
|
|
224
|
-
//# sourceMappingURL=prefix-manager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prefix-manager.d.ts","sourceRoot":"","sources":["../src/prefix-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,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