@aidc-toolkit/gs1 1.0.43 → 1.0.44-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 +41 -0
- package/dist/abstract-identifier-creator.d.ts.map +1 -0
- package/dist/abstract-identifier-creator.js +73 -0
- package/dist/abstract-identifier-creator.js.map +1 -0
- 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 +34 -0
- package/dist/abstract-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/abstract-numeric-identifier-creator.js +154 -0
- package/dist/abstract-numeric-identifier-creator.js.map +1 -0
- package/dist/character-set.d.ts +27 -0
- package/dist/character-set.d.ts.map +1 -0
- package/dist/character-set.js +83 -0
- package/dist/character-set.js.map +1 -0
- package/dist/check.d.ts +81 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +218 -0
- package/dist/check.js.map +1 -0
- 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/content-character-set.d.ts +26 -0
- package/dist/content-character-set.d.ts.map +1 -0
- package/dist/content-character-set.js +18 -0
- package/dist/content-character-set.js.map +1 -0
- package/dist/gcp-length-cache.d.ts +89 -0
- package/dist/gcp-length-cache.d.ts.map +1 -0
- package/dist/gcp-length-cache.js +240 -0
- package/dist/gcp-length-cache.js.map +1 -0
- package/dist/gcp-length-data.d.ts +108 -0
- package/dist/gcp-length-data.d.ts.map +1 -0
- package/dist/gcp-length-data.js +53 -0
- package/dist/gcp-length-data.js.map +1 -0
- package/dist/gcp-length.d.ts +97 -0
- package/dist/gcp-length.d.ts.map +1 -0
- package/dist/gcp-length.js +368 -0
- package/dist/gcp-length.js.map +1 -0
- package/dist/gtin-creator.d.ts +47 -0
- package/dist/gtin-creator.d.ts.map +1 -0
- package/dist/gtin-creator.js +64 -0
- package/dist/gtin-creator.js.map +1 -0
- package/dist/gtin-descriptor.d.ts +22 -0
- package/dist/gtin-descriptor.d.ts.map +1 -0
- package/dist/gtin-descriptor.js +2 -0
- package/dist/gtin-descriptor.js.map +1 -0
- 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 +26 -0
- package/dist/gtin-type.d.ts.map +1 -0
- package/dist/gtin-type.js +7 -0
- package/dist/gtin-type.js.map +1 -0
- package/dist/gtin-validator.d.ts +132 -0
- package/dist/gtin-validator.d.ts.map +1 -0
- package/dist/gtin-validator.js +349 -0
- package/dist/gtin-validator.js.map +1 -0
- package/dist/identifier-creator.d.ts +31 -0
- package/dist/identifier-creator.d.ts.map +1 -0
- package/dist/identifier-creator.js +2 -0
- package/dist/identifier-creator.js.map +1 -0
- package/dist/identifier-creators.d.ts +118 -0
- 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/identifier-descriptor.d.ts +27 -0
- package/dist/identifier-descriptor.d.ts.map +1 -0
- package/dist/identifier-descriptor.js +2 -0
- package/dist/identifier-descriptor.js.map +1 -0
- package/dist/identifier-descriptors.d.ts +106 -0
- package/dist/identifier-descriptors.d.ts.map +1 -0
- package/dist/identifier-descriptors.js +262 -0
- 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-type.d.ts +62 -0
- package/dist/identifier-type.d.ts.map +1 -0
- package/dist/identifier-type.js +54 -0
- package/dist/identifier-type.js.map +1 -0
- package/dist/identifier-validator.d.ts +85 -0
- package/dist/identifier-validator.d.ts.map +1 -0
- package/dist/identifier-validator.js +107 -0
- package/dist/identifier-validator.js.map +1 -0
- package/dist/identifier-validators.d.ts +131 -0
- package/dist/identifier-validators.d.ts.map +1 -0
- package/dist/identifier-validators.js +167 -0
- package/dist/identifier-validators.js.map +1 -0
- package/dist/index.d.ts +63 -2205
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -3
- package/dist/index.js.map +1 -0
- 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/locale/en/locale-resources.d.ts +48 -0
- package/dist/locale/en/locale-resources.d.ts.map +1 -0
- package/dist/locale/en/locale-resources.js +47 -0
- package/dist/locale/en/locale-resources.js.map +1 -0
- package/dist/locale/fr/locale-resources.d.ts +48 -0
- package/dist/locale/fr/locale-resources.d.ts.map +1 -0
- package/dist/locale/fr/locale-resources.js +47 -0
- package/dist/locale/fr/locale-resources.js.map +1 -0
- package/dist/locale/i18n.d.ts +27 -0
- package/dist/locale/i18n.d.ts.map +1 -0
- package/dist/locale/i18n.js +35 -0
- package/dist/locale/i18n.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-creator.d.ts +12 -0
- package/dist/non-gtin-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-creator.js +2 -0
- package/dist/non-gtin-numeric-identifier-creator.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-descriptor.d.ts +22 -0
- package/dist/non-gtin-numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-descriptor.js +2 -0
- package/dist/non-gtin-numeric-identifier-descriptor.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-type.d.ts +26 -0
- package/dist/non-gtin-numeric-identifier-type.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-type.js +8 -0
- package/dist/non-gtin-numeric-identifier-type.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-validator.d.ts +12 -0
- package/dist/non-gtin-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-validator.js +10 -0
- package/dist/non-gtin-numeric-identifier-validator.js.map +1 -0
- package/dist/non-numeric-identifier-creator.d.ts +40 -0
- package/dist/non-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/non-numeric-identifier-creator.js +82 -0
- package/dist/non-numeric-identifier-creator.js.map +1 -0
- package/dist/non-numeric-identifier-descriptor.d.ts +26 -0
- package/dist/non-numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/non-numeric-identifier-descriptor.js +2 -0
- package/dist/non-numeric-identifier-descriptor.js.map +1 -0
- package/dist/non-numeric-identifier-type.d.ts +26 -0
- package/dist/non-numeric-identifier-type.d.ts.map +1 -0
- package/dist/non-numeric-identifier-type.js +8 -0
- package/dist/non-numeric-identifier-type.js.map +1 -0
- package/dist/non-numeric-identifier-validator.d.ts +41 -0
- package/dist/non-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/non-numeric-identifier-validator.js +69 -0
- package/dist/non-numeric-identifier-validator.js.map +1 -0
- 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 +53 -0
- package/dist/numeric-identifier-creator.d.ts.map +1 -0
- package/dist/numeric-identifier-creator.js +2 -0
- package/dist/numeric-identifier-creator.js.map +1 -0
- package/dist/numeric-identifier-descriptor.d.ts +22 -0
- package/dist/numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/numeric-identifier-descriptor.js +2 -0
- package/dist/numeric-identifier-descriptor.js.map +1 -0
- package/dist/numeric-identifier-type.d.ts +26 -0
- package/dist/numeric-identifier-type.d.ts.map +1 -0
- package/dist/numeric-identifier-type.js +7 -0
- package/dist/numeric-identifier-type.js.map +1 -0
- package/dist/numeric-identifier-validator.d.ts +38 -0
- package/dist/numeric-identifier-validator.d.ts.map +1 -0
- package/dist/numeric-identifier-validator.js +61 -0
- package/dist/numeric-identifier-validator.js.map +1 -0
- package/dist/prefix-manager.d.ts +151 -0
- package/dist/prefix-manager.d.ts.map +1 -0
- package/dist/prefix-manager.js +297 -0
- package/dist/prefix-manager.js.map +1 -0
- package/dist/prefix-provider.d.ts +27 -0
- package/dist/prefix-provider.d.ts.map +1 -0
- package/dist/prefix-provider.js +2 -0
- package/dist/prefix-provider.js.map +1 -0
- package/dist/prefix-type.d.ts +26 -0
- package/dist/prefix-type.d.ts.map +1 -0
- package/dist/prefix-type.js +18 -0
- package/dist/prefix-type.js.map +1 -0
- package/dist/prefix-validator.d.ts +71 -0
- package/dist/prefix-validator.d.ts.map +1 -0
- package/dist/prefix-validator.js +204 -0
- package/dist/prefix-validator.js.map +1 -0
- package/dist/serializable-numeric-identifier-creator.d.ts +48 -0
- package/dist/serializable-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-creator.js +93 -0
- package/dist/serializable-numeric-identifier-creator.js.map +1 -0
- package/dist/serializable-numeric-identifier-descriptor.d.ts +26 -0
- package/dist/serializable-numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-descriptor.js +2 -0
- package/dist/serializable-numeric-identifier-descriptor.js.map +1 -0
- package/dist/serializable-numeric-identifier-type.d.ts +26 -0
- package/dist/serializable-numeric-identifier-type.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-type.js +8 -0
- package/dist/serializable-numeric-identifier-type.js.map +1 -0
- package/dist/serializable-numeric-identifier-validator.d.ts +67 -0
- package/dist/serializable-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-validator.js +97 -0
- package/dist/serializable-numeric-identifier-validator.js.map +1 -0
- package/dist/variable-measure.d.ts +68 -0
- package/dist/variable-measure.d.ts.map +1 -0
- package/dist/variable-measure.js +210 -0
- package/dist/variable-measure.js.map +1 -0
- package/dist/verified-by-gs1.d.ts +22 -0
- package/dist/verified-by-gs1.d.ts.map +1 -0
- package/dist/verified-by-gs1.js +46 -0
- package/dist/verified-by-gs1.js.map +1 -0
- package/package.json +4 -4
- package/src/gcp-length-cache.ts +7 -2
- package/tsconfig-src.tsbuildinfo +1 -1
- package/dist/index.cjs +0 -19
- package/dist/index.d.cts +0 -2205
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import { NUMERIC_CREATOR } from "@aidc-toolkit/utility";
|
|
2
|
+
import { checkDigit, hasValidCheckDigit } from "./check.js";
|
|
3
|
+
import { GTINLengths } from "./gtin-length.js";
|
|
4
|
+
import { IdentifierDescriptors } from "./identifier-descriptors.js";
|
|
5
|
+
import { i18nextGS1 } from "./locale/i18n.js";
|
|
6
|
+
import { NumericIdentifierValidator } from "./numeric-identifier-validator.js";
|
|
7
|
+
import { PrefixTypes } from "./prefix-type.js";
|
|
8
|
+
import { PrefixValidator } from "./prefix-validator.js";
|
|
9
|
+
/**
|
|
10
|
+
* Levels at which GTIN is to be validated.
|
|
11
|
+
*/
|
|
12
|
+
export const GTINLevels = {
|
|
13
|
+
/**
|
|
14
|
+
* Any level (level is ignored).
|
|
15
|
+
*/
|
|
16
|
+
Any: 0,
|
|
17
|
+
/**
|
|
18
|
+
* Retail consumer trade item level, supporting GTIN-13, GTIN-12 (optionally zero-suppressed), and GTIN-8.
|
|
19
|
+
*/
|
|
20
|
+
RetailConsumer: 1,
|
|
21
|
+
/**
|
|
22
|
+
* Other than retail consumer trade item level, supporting GTIN-13, GTIN-12 (not zero-suppressed), and GTIN-14.
|
|
23
|
+
*/
|
|
24
|
+
OtherThanRetailConsumer: 2
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* GTIN validator.
|
|
28
|
+
*/
|
|
29
|
+
export class GTINValidator extends NumericIdentifierValidator {
|
|
30
|
+
/**
|
|
31
|
+
* Validation parameters for optional indicator digit.
|
|
32
|
+
*/
|
|
33
|
+
static #OPTIONAL_INDICATOR_DIGIT_VALIDATION = {
|
|
34
|
+
minimumLength: 0,
|
|
35
|
+
maximumLength: 1,
|
|
36
|
+
component: () => i18nextGS1.t("Identifier.indicatorDigit")
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Validation parameters for zero-suppressed GTIN-12.
|
|
40
|
+
*/
|
|
41
|
+
static #ZERO_SUPPRESSED_GTIN12_VALIDATION = {
|
|
42
|
+
minimumLength: 8,
|
|
43
|
+
maximumLength: 8
|
|
44
|
+
};
|
|
45
|
+
static #ERROR_MESSAGE_PARSE_KEYS = {
|
|
46
|
+
[GTINLevels.Any]: undefined,
|
|
47
|
+
[GTINLevels.RetailConsumer]: "Identifier.invalidGTINAtRetail",
|
|
48
|
+
[GTINLevels.OtherThanRetailConsumer]: "Identifier.invalidGTINAtOtherThanRetail"
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Prefix type.
|
|
52
|
+
*/
|
|
53
|
+
#prefixType;
|
|
54
|
+
/**
|
|
55
|
+
* Constructor.
|
|
56
|
+
*
|
|
57
|
+
* @param gtinBaseLength
|
|
58
|
+
* GTIN base length (all except GTIN-14).
|
|
59
|
+
*/
|
|
60
|
+
constructor(gtinBaseLength) {
|
|
61
|
+
const identifierDescriptor = IdentifierDescriptors.GTIN[gtinBaseLength];
|
|
62
|
+
super(identifierDescriptor);
|
|
63
|
+
this.#prefixType = identifierDescriptor.prefixType;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @inheritDoc
|
|
67
|
+
*/
|
|
68
|
+
get prefixType() {
|
|
69
|
+
return this.#prefixType;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @inheritDoc
|
|
73
|
+
*/
|
|
74
|
+
validatePrefix(partialIdentifier) {
|
|
75
|
+
// Delegate to prefix validator requiring exact match for prefix type.
|
|
76
|
+
PrefixValidator.validate(this.prefixType, false, false, partialIdentifier, true, true);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Zero suppress a GTIN-12.
|
|
80
|
+
*
|
|
81
|
+
* @param gtin12
|
|
82
|
+
* GTIN-12.
|
|
83
|
+
*
|
|
84
|
+
* @returns
|
|
85
|
+
* Zero-suppressed GTIN-12.
|
|
86
|
+
*/
|
|
87
|
+
static zeroSuppress(gtin12) {
|
|
88
|
+
GTIN12_VALIDATOR.validate(gtin12);
|
|
89
|
+
// Convert to individual digits.
|
|
90
|
+
const d = Array.from(gtin12);
|
|
91
|
+
let zeroSuppressedGTIN12;
|
|
92
|
+
// All rules require that digits in positions 1, 5, and 6 be zero.
|
|
93
|
+
if (d[0] === "0" && d[6] === "0" && d[7] === "0") {
|
|
94
|
+
if (d[10] >= "5" && d[8] === "0" && d[9] === "0" && d[5] !== "0") {
|
|
95
|
+
zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[3]}${d[4]}${d[5]}${d[10]}${d[11]}`;
|
|
96
|
+
}
|
|
97
|
+
else if (d[5] === "0" && d[8] === "0" && d[9] === "0" && d[4] !== "0") {
|
|
98
|
+
zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[3]}${d[4]}${d[10]}4${d[11]}`;
|
|
99
|
+
}
|
|
100
|
+
else if (d[3] <= "2" && d[4] === "0" && d[5] === "0") {
|
|
101
|
+
zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[8]}${d[9]}${d[10]}${d[3]}${d[11]}`;
|
|
102
|
+
}
|
|
103
|
+
else if (d[3] >= "3" && d[4] === "0" && d[5] === "0" && d[8] === "0") {
|
|
104
|
+
zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[3]}${d[9]}${d[10]}3${d[11]}`;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (zeroSuppressedGTIN12 === undefined) {
|
|
108
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidZeroSuppressibleGTIN12"));
|
|
109
|
+
}
|
|
110
|
+
return zeroSuppressedGTIN12;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Zero expand a zero-suppressed GTIN-12.
|
|
114
|
+
*
|
|
115
|
+
* @param zeroSuppressedGTIN12
|
|
116
|
+
* Zero-suppressed GTIN-12.
|
|
117
|
+
*
|
|
118
|
+
* @returns
|
|
119
|
+
* GTIN-12.
|
|
120
|
+
*/
|
|
121
|
+
static zeroExpand(zeroSuppressedGTIN12) {
|
|
122
|
+
NUMERIC_CREATOR.validate(zeroSuppressedGTIN12, GTINValidator.#ZERO_SUPPRESSED_GTIN12_VALIDATION);
|
|
123
|
+
// Convert to individual digits.
|
|
124
|
+
const d = Array.from(zeroSuppressedGTIN12);
|
|
125
|
+
let gtin12;
|
|
126
|
+
// Zero-suppressed GTIN-12 always starts with 0.
|
|
127
|
+
if (d[0] === "0") {
|
|
128
|
+
if (d[6] >= "5" && d[5] !== "0") {
|
|
129
|
+
gtin12 = `0${d[1]}${d[2]}${d[3]}${d[4]}${d[5]}0000${d[6]}${d[7]}`;
|
|
130
|
+
}
|
|
131
|
+
else if (d[6] === "4" && d[4] !== "0") {
|
|
132
|
+
gtin12 = `0${d[1]}${d[2]}${d[3]}${d[4]}00000${d[5]}${d[7]}`;
|
|
133
|
+
}
|
|
134
|
+
else if (d[6] <= "2") {
|
|
135
|
+
gtin12 = `0${d[1]}${d[2]}${d[6]}0000${d[3]}${d[4]}${d[5]}${d[7]}`;
|
|
136
|
+
}
|
|
137
|
+
else if (d[6] === "3" && d[3] >= "3") {
|
|
138
|
+
gtin12 = `0${d[1]}${d[2]}${d[3]}00000${d[4]}${d[5]}${d[7]}`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (gtin12 === undefined) {
|
|
142
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidZeroSuppressedGTIN12"));
|
|
143
|
+
}
|
|
144
|
+
// Make sure that resulting GTIN-12 is valid.
|
|
145
|
+
GTIN12_VALIDATOR.validate(gtin12);
|
|
146
|
+
return gtin12;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Convert a GTIN of any length to a GTIN-14 with an optional indicator digit.
|
|
150
|
+
*
|
|
151
|
+
* @param indicatorDigit
|
|
152
|
+
* Indicator digit. If blank, assumes "0" if the GTIN is not already a GTIN-14.
|
|
153
|
+
*
|
|
154
|
+
* @param gtin
|
|
155
|
+
* GTIN.
|
|
156
|
+
*
|
|
157
|
+
* @returns
|
|
158
|
+
* GTIN-14.
|
|
159
|
+
*/
|
|
160
|
+
static convertToGTIN14(indicatorDigit, gtin) {
|
|
161
|
+
NUMERIC_CREATOR.validate(indicatorDigit, GTINValidator.#OPTIONAL_INDICATOR_DIGIT_VALIDATION);
|
|
162
|
+
// Check digit doesn't change by prepending zeros.
|
|
163
|
+
let gtin14 = GTINValidator.normalize(gtin).padStart(GTINLengths.GTIN14, "0");
|
|
164
|
+
// If indicator digit provided and is different, recalculate the check digit.
|
|
165
|
+
if (indicatorDigit.length !== 0 && !gtin14.startsWith(indicatorDigit)) {
|
|
166
|
+
const partialGTIN14 = `${indicatorDigit}${gtin14.substring(1, GTINLengths.GTIN14 - 1)}`;
|
|
167
|
+
gtin14 = `${partialGTIN14}${checkDigit(partialGTIN14)}`;
|
|
168
|
+
}
|
|
169
|
+
return gtin14;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Normalize a GTIN of any length.
|
|
173
|
+
* - A GTIN-14 that starts with six zeros or a GTIN-13 that starts with five zeros is normalized to GTIN-8.
|
|
174
|
+
* - A GTIN-14 that starts with two zeros or a GTIN-13 that starts with one zero is normalized to GTIN-12.
|
|
175
|
+
* - A GTIN-14 that starts with one zero is normalized to GTIN-13.
|
|
176
|
+
* - Otherwise, the GTIN is unchanged.
|
|
177
|
+
*
|
|
178
|
+
* @param gtin
|
|
179
|
+
* GTIN.
|
|
180
|
+
*
|
|
181
|
+
* @returns
|
|
182
|
+
* Normalized GTIN.
|
|
183
|
+
*/
|
|
184
|
+
static normalize(gtin) {
|
|
185
|
+
const gtinLength = gtin.length;
|
|
186
|
+
let normalizedGTIN;
|
|
187
|
+
switch (gtinLength) {
|
|
188
|
+
case GTINLengths.GTIN13:
|
|
189
|
+
if (!gtin.startsWith("0")) {
|
|
190
|
+
// GTIN is GTIN-13.
|
|
191
|
+
normalizedGTIN = gtin;
|
|
192
|
+
}
|
|
193
|
+
else if (!gtin.startsWith("00000")) {
|
|
194
|
+
// GTIN is GTIN-12.
|
|
195
|
+
normalizedGTIN = gtin.substring(1);
|
|
196
|
+
}
|
|
197
|
+
else if (!gtin.startsWith("000000")) {
|
|
198
|
+
// GTIN is GTIN-8.
|
|
199
|
+
normalizedGTIN = gtin.substring(5);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidZeroSuppressedGTIN12AsGTIN13"));
|
|
203
|
+
}
|
|
204
|
+
break;
|
|
205
|
+
case GTINLengths.GTIN12:
|
|
206
|
+
// GTIN is GTIN-12.
|
|
207
|
+
normalizedGTIN = gtin;
|
|
208
|
+
break;
|
|
209
|
+
case GTINLengths.GTIN8:
|
|
210
|
+
if (!gtin.startsWith("0")) {
|
|
211
|
+
// GTIN is GTIN-8.
|
|
212
|
+
normalizedGTIN = gtin;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
// GTIN is zero-suppressed GTIN-12.
|
|
216
|
+
normalizedGTIN = GTINValidator.zeroExpand(gtin);
|
|
217
|
+
}
|
|
218
|
+
break;
|
|
219
|
+
case GTINLengths.GTIN14:
|
|
220
|
+
if (!gtin.startsWith("0")) {
|
|
221
|
+
// GTIN is GTIN-14.
|
|
222
|
+
normalizedGTIN = gtin;
|
|
223
|
+
}
|
|
224
|
+
else if (!gtin.startsWith("00")) {
|
|
225
|
+
// GTIN is GTIN-13.
|
|
226
|
+
normalizedGTIN = gtin.substring(1);
|
|
227
|
+
}
|
|
228
|
+
else if (!gtin.startsWith("000000")) {
|
|
229
|
+
// GTIN is GTIN-12.
|
|
230
|
+
normalizedGTIN = gtin.substring(2);
|
|
231
|
+
}
|
|
232
|
+
else if (!gtin.startsWith("0000000")) {
|
|
233
|
+
// GTIN is GTIN-8.
|
|
234
|
+
normalizedGTIN = gtin.substring(6);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidZeroSuppressedGTIN12AsGTIN14"));
|
|
238
|
+
}
|
|
239
|
+
break;
|
|
240
|
+
default:
|
|
241
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidGTINLength"));
|
|
242
|
+
}
|
|
243
|
+
// Validation applies to the normalized GTIN.
|
|
244
|
+
GTINValidator.validateAny(normalizedGTIN);
|
|
245
|
+
return normalizedGTIN;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Validate any GTIN, optionally against a level.
|
|
249
|
+
*
|
|
250
|
+
* @param gtin
|
|
251
|
+
* GTIN.
|
|
252
|
+
*
|
|
253
|
+
* @param gtinLevel
|
|
254
|
+
* Level at which GTIN is to be validated.
|
|
255
|
+
*/
|
|
256
|
+
static validateAny(gtin, gtinLevel = GTINLevels.Any) {
|
|
257
|
+
// Assume length-validated GTIN is the GTIN (true for all except zero-suppressed GTIN-12).
|
|
258
|
+
let lengthValidatedGTIN = gtin;
|
|
259
|
+
let prefixType;
|
|
260
|
+
let allowUPCCompanyPrefix = false;
|
|
261
|
+
let allowGS18Prefix = false;
|
|
262
|
+
let validatePrefix = gtin;
|
|
263
|
+
let gtinLevelRestriction;
|
|
264
|
+
switch (gtin.length) {
|
|
265
|
+
case GTINLengths.GTIN13:
|
|
266
|
+
// Validate prefix with restrictions on prefix type depending on GTIN level.
|
|
267
|
+
prefixType = PrefixTypes.GS1CompanyPrefix;
|
|
268
|
+
allowUPCCompanyPrefix = gtinLevel !== GTINLevels.RetailConsumer;
|
|
269
|
+
allowGS18Prefix = gtinLevel === GTINLevels.Any;
|
|
270
|
+
gtinLevelRestriction = GTINLevels.Any;
|
|
271
|
+
break;
|
|
272
|
+
case GTINLengths.GTIN12:
|
|
273
|
+
// Validate prefix requiring exact match for prefix type.
|
|
274
|
+
prefixType = PrefixTypes.UPCCompanyPrefix;
|
|
275
|
+
gtinLevelRestriction = GTINLevels.Any;
|
|
276
|
+
break;
|
|
277
|
+
case GTINLengths.GTIN8:
|
|
278
|
+
// Zero-suppressed GTIN-12 always starts with 0.
|
|
279
|
+
if (!gtin.startsWith("0")) {
|
|
280
|
+
// Validate prefix requiring exact match for prefix type.
|
|
281
|
+
prefixType = PrefixTypes.GS18Prefix;
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
lengthValidatedGTIN = GTINValidator.zeroExpand(gtin);
|
|
285
|
+
prefixType = undefined;
|
|
286
|
+
}
|
|
287
|
+
gtinLevelRestriction = GTINLevels.RetailConsumer;
|
|
288
|
+
break;
|
|
289
|
+
case GTINLengths.GTIN14:
|
|
290
|
+
// Validate prefix with restrictions on prefix type depending on GTIN level.
|
|
291
|
+
prefixType = PrefixTypes.GS1CompanyPrefix;
|
|
292
|
+
allowUPCCompanyPrefix = true;
|
|
293
|
+
allowGS18Prefix = gtinLevel !== GTINLevels.OtherThanRetailConsumer || !gtin.startsWith("0");
|
|
294
|
+
validatePrefix = gtin.substring(1);
|
|
295
|
+
gtinLevelRestriction = GTINLevels.OtherThanRetailConsumer;
|
|
296
|
+
break;
|
|
297
|
+
default:
|
|
298
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidGTINLength"));
|
|
299
|
+
}
|
|
300
|
+
if (prefixType !== undefined) {
|
|
301
|
+
PrefixValidator.validate(prefixType, allowUPCCompanyPrefix, allowGS18Prefix, validatePrefix, true, true, GTINValidator.#ERROR_MESSAGE_PARSE_KEYS[gtinLevel]);
|
|
302
|
+
}
|
|
303
|
+
// Validating the check digit will also validate the characters.
|
|
304
|
+
if (!hasValidCheckDigit(lengthValidatedGTIN)) {
|
|
305
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidCheckDigit"));
|
|
306
|
+
}
|
|
307
|
+
// Validate against level if required.
|
|
308
|
+
if (gtinLevel !== GTINLevels.Any && gtinLevelRestriction !== GTINLevels.Any && gtinLevelRestriction !== gtinLevel) {
|
|
309
|
+
throw new RangeError(i18nextGS1.t(gtinLevel === GTINLevels.RetailConsumer ? "Identifier.invalidGTINAtRetail" : "Identifier.invalidGTINAtOtherThanRetail"));
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Validate a GTIN-14.
|
|
314
|
+
*
|
|
315
|
+
* @param gtin14
|
|
316
|
+
* GTIN-14.
|
|
317
|
+
*/
|
|
318
|
+
static validateGTIN14(gtin14) {
|
|
319
|
+
if (gtin14.length !== GTINLengths.GTIN14) {
|
|
320
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidGTIN14Length"));
|
|
321
|
+
}
|
|
322
|
+
GTINValidator.validateAny(gtin14);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* GTIN-13 validator.
|
|
327
|
+
*/
|
|
328
|
+
// Defined here because of circular reference.
|
|
329
|
+
export const GTIN13_VALIDATOR = new GTINValidator(GTINLengths.GTIN13);
|
|
330
|
+
/**
|
|
331
|
+
* GTIN-12 validator.
|
|
332
|
+
*/
|
|
333
|
+
// Defined here because of circular reference.
|
|
334
|
+
export const GTIN12_VALIDATOR = new GTINValidator(GTINLengths.GTIN12);
|
|
335
|
+
/**
|
|
336
|
+
* GTIN-8 validator.
|
|
337
|
+
*/
|
|
338
|
+
// Defined here because of circular reference.
|
|
339
|
+
export const GTIN8_VALIDATOR = new GTINValidator(GTINLengths.GTIN8);
|
|
340
|
+
/**
|
|
341
|
+
* GTIN validators indexed by prefix type.
|
|
342
|
+
*/
|
|
343
|
+
// Defined here because of circular reference.
|
|
344
|
+
export const GTIN_VALIDATORS = {
|
|
345
|
+
[GTINLengths.GTIN13]: GTIN13_VALIDATOR,
|
|
346
|
+
[GTINLengths.GTIN12]: GTIN12_VALIDATOR,
|
|
347
|
+
[GTINLengths.GTIN8]: GTIN8_VALIDATOR
|
|
348
|
+
};
|
|
349
|
+
//# sourceMappingURL=gtin-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gtin-validator.js","sourceRoot":"","sources":["../src/gtin-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAErF,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAE5D,OAAO,EAAuB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAmB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACtB;;OAEG;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gB;IACtC,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,eAAe;CACvC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { IdentifierType } from "./identifier-type.js";
|
|
2
|
+
import type { IdentifierValidation, IdentifierValidator } from "./identifier-validator.js";
|
|
3
|
+
import type { PrefixProvider } from "./prefix-provider.js";
|
|
4
|
+
/**
|
|
5
|
+
* Identifier creator. Creates an identifier based on its definition in section 3 of the {@link
|
|
6
|
+
* https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}.
|
|
7
|
+
*
|
|
8
|
+
* Keys are created based on a prefix defined in a prefix provider to which the identifier creator is bound.
|
|
9
|
+
*
|
|
10
|
+
* @template TIdentifierType
|
|
11
|
+
* Identifier type type.
|
|
12
|
+
*
|
|
13
|
+
* @template TIdentifierValidation
|
|
14
|
+
* Identifier validation type.
|
|
15
|
+
*/
|
|
16
|
+
export interface IdentifierCreator<TIdentifierType extends IdentifierType = IdentifierType, TIdentifierValidation extends IdentifierValidation = IdentifierValidation> extends IdentifierValidator<TIdentifierType, TIdentifierValidation> {
|
|
17
|
+
/**
|
|
18
|
+
* Get the prefix provider to which this identifier creator is bound.
|
|
19
|
+
*/
|
|
20
|
+
get prefixProvider(): PrefixProvider;
|
|
21
|
+
/**
|
|
22
|
+
* Get the prefix, equivalent to calling {@linkcode PrefixProvider.prefix | prefixProvider.prefix} for a GTIN or
|
|
23
|
+
* {@linkcode PrefixProvider.gs1CompanyPrefix | prefixProvider.gs1CompanyPrefix} for all other identifier types.
|
|
24
|
+
*/
|
|
25
|
+
get prefix(): string;
|
|
26
|
+
/**
|
|
27
|
+
* Get the reference length.
|
|
28
|
+
*/
|
|
29
|
+
get referenceLength(): number;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=identifier-creator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifier-creator.d.ts","sourceRoot":"","sources":["../src/identifier-creator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAC3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,iBAAiB,CAAC,eAAe,SAAS,cAAc,GAAG,cAAc,EAAE,qBAAqB,SAAS,oBAAoB,GAAG,oBAAoB,CAAE,SAAQ,mBAAmB,CAAC,eAAe,EAAE,qBAAqB,CAAC;IACtO;;OAEG;IACH,IAAI,cAAc,IAAI,cAAc,CAAC;IAErC;;;OAGG;IACH,IAAI,MAAM,IAAI,MAAM,CAAC;IAErB;;OAEG;IACH,IAAI,eAAe,IAAI,MAAM,CAAC;CACjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifier-creator.js","sourceRoot":"","sources":["../src/identifier-creator.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { GTINCreator } from "./gtin-creator.js";
|
|
2
|
+
import type { GTINBaseLength } from "./gtin-length.js";
|
|
3
|
+
import type { GTINType } from "./gtin-type.js";
|
|
4
|
+
import type { IdentifierCreator } from "./identifier-creator.js";
|
|
5
|
+
import { type IdentifierTypeExtension } from "./identifier-extension.js";
|
|
6
|
+
import type { IdentifierType } from "./identifier-type.js";
|
|
7
|
+
import type { NonGTINNumericIdentifierCreator } from "./non-gtin-numeric-identifier-creator.js";
|
|
8
|
+
import { NonNumericIdentifierCreator } from "./non-numeric-identifier-creator.js";
|
|
9
|
+
import { NonSerializableNumericIdentifierCreator } from "./non-serializable-numeric-identifier-creator.js";
|
|
10
|
+
import type { NumericIdentifierCreator } from "./numeric-identifier-creator.js";
|
|
11
|
+
import type { PrefixProvider } from "./prefix-provider.js";
|
|
12
|
+
import { SerializableNumericIdentifierCreator } from "./serializable-numeric-identifier-creator.js";
|
|
13
|
+
/**
|
|
14
|
+
* Identifier creator type based on identifier type type.
|
|
15
|
+
*
|
|
16
|
+
* @template TIdentifierType
|
|
17
|
+
* Identifier type type.
|
|
18
|
+
*/
|
|
19
|
+
export type IdentifierTypeCreator<TIdentifierType extends IdentifierType> = IdentifierTypeExtension<TIdentifierType, IdentifierCreator, NumericIdentifierCreator, GTINCreator, NonGTINNumericIdentifierCreator, NonSerializableNumericIdentifierCreator, SerializableNumericIdentifierCreator, NonNumericIdentifierCreator>;
|
|
20
|
+
/**
|
|
21
|
+
* Identifier creators entry type based on identifier type type.
|
|
22
|
+
*
|
|
23
|
+
* @template TIdentifierType
|
|
24
|
+
* Identifier type type.
|
|
25
|
+
*/
|
|
26
|
+
export type IdentifierCreatorsEntry<TIdentifierType extends IdentifierType> = IdentifierTypeCreator<TIdentifierType>;
|
|
27
|
+
/**
|
|
28
|
+
* Identifier creators record type.
|
|
29
|
+
*/
|
|
30
|
+
export type IdentifierCreatorsRecord = {
|
|
31
|
+
[TIdentifierType in IdentifierType]: IdentifierCreatorsEntry<TIdentifierType>;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* GTIN creator constructor type.
|
|
35
|
+
*/
|
|
36
|
+
export type GTINCreatorConstructor = new (prefixProvider: PrefixProvider, gtinBaseLength: GTINBaseLength) => GTINCreator;
|
|
37
|
+
/**
|
|
38
|
+
* Non-GTIN creator constructor type.
|
|
39
|
+
*
|
|
40
|
+
* @template TIdentifierType
|
|
41
|
+
* Identifier type type.
|
|
42
|
+
*/
|
|
43
|
+
export type NonGTINCreatorConstructor<TIdentifierType extends Exclude<IdentifierType, GTINType>> = new (prefixProvider: PrefixProvider, identifierType: TIdentifierType) => IdentifierCreatorsRecord[TIdentifierType];
|
|
44
|
+
/**
|
|
45
|
+
* Identifier creator constructors entry type based on identifier type type.
|
|
46
|
+
*
|
|
47
|
+
* @template TIdentifierType
|
|
48
|
+
* Identifier type type.
|
|
49
|
+
*/
|
|
50
|
+
export type IdentifierCreatorConstructorsEntry<TIdentifierType extends IdentifierType> = TIdentifierType extends GTINType ? GTINCreatorConstructor : NonGTINCreatorConstructor<Exclude<TIdentifierType, GTINType>>;
|
|
51
|
+
/**
|
|
52
|
+
* Identifier creator constructors record type.
|
|
53
|
+
*/
|
|
54
|
+
export type IdentifierCreatorConstructorsRecord = {
|
|
55
|
+
readonly [TIdentifierType in IdentifierType]: IdentifierCreatorConstructorsEntry<TIdentifierType>;
|
|
56
|
+
};
|
|
57
|
+
export declare const IdentifierCreatorConstructors: IdentifierCreatorConstructorsRecord;
|
|
58
|
+
/**
|
|
59
|
+
* Determine if identifier creator is a numeric identifier creator.
|
|
60
|
+
*
|
|
61
|
+
* @param identifierCreator
|
|
62
|
+
* Identifier creator.
|
|
63
|
+
*
|
|
64
|
+
* @returns
|
|
65
|
+
* True if identifier creator is a numeric identifier creator.
|
|
66
|
+
*/
|
|
67
|
+
export declare function isNumericIdentifierCreator(identifierCreator: IdentifierCreator): identifierCreator is NumericIdentifierCreator;
|
|
68
|
+
/**
|
|
69
|
+
* Determine if identifier creator is a GTIN creator.
|
|
70
|
+
*
|
|
71
|
+
* @param identifierCreator
|
|
72
|
+
* Identifier creator.
|
|
73
|
+
*
|
|
74
|
+
* @returns
|
|
75
|
+
* True if identifier creator is a GTIN creator.
|
|
76
|
+
*/
|
|
77
|
+
export declare function isGTINCreator(identifierCreator: IdentifierCreator): identifierCreator is GTINCreator;
|
|
78
|
+
/**
|
|
79
|
+
* Determine if identifier creator is a non-GTIN numeric identifier creator.
|
|
80
|
+
*
|
|
81
|
+
* @param identifierCreator
|
|
82
|
+
* Identifier creator.
|
|
83
|
+
*
|
|
84
|
+
* @returns
|
|
85
|
+
* True if identifier creator is a non-GTIN numeric identifier creator.
|
|
86
|
+
*/
|
|
87
|
+
export declare function isNonGTINNumericIdentifierCreator(identifierCreator: IdentifierCreator): identifierCreator is NonGTINNumericIdentifierCreator;
|
|
88
|
+
/**
|
|
89
|
+
* Determine if identifier creator is a non-serializable numeric identifier creator.
|
|
90
|
+
*
|
|
91
|
+
* @param identifierCreator
|
|
92
|
+
* Identifier creator.
|
|
93
|
+
*
|
|
94
|
+
* @returns
|
|
95
|
+
* True if identifier creator is a non-serializable numeric identifier creator.
|
|
96
|
+
*/
|
|
97
|
+
export declare function isNonSerializableNumericIdentifierCreator(identifierCreator: IdentifierCreator): identifierCreator is NonSerializableNumericIdentifierCreator;
|
|
98
|
+
/**
|
|
99
|
+
* Determine if identifier creator is a serializable numeric identifier creator.
|
|
100
|
+
*
|
|
101
|
+
* @param identifierCreator
|
|
102
|
+
* Identifier creator.
|
|
103
|
+
*
|
|
104
|
+
* @returns
|
|
105
|
+
* True if identifier creator is a serializable numeric identifier creator.
|
|
106
|
+
*/
|
|
107
|
+
export declare function isSerializableNumericIdentifierCreator(identifierCreator: IdentifierCreator): identifierCreator is SerializableNumericIdentifierCreator;
|
|
108
|
+
/**
|
|
109
|
+
* Determine if identifier creator is a non-numeric identifier creator.
|
|
110
|
+
*
|
|
111
|
+
* @param identifierCreator
|
|
112
|
+
* Identifier creator.
|
|
113
|
+
*
|
|
114
|
+
* @returns
|
|
115
|
+
* True if identifier creator is a non-numeric identifier creator.
|
|
116
|
+
*/
|
|
117
|
+
export declare function isNonNumericIdentifierCreator(identifierCreator: IdentifierCreator): identifierCreator is NonNumericIdentifierCreator;
|
|
118
|
+
//# sourceMappingURL=identifier-creators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifier-creators.d.ts","sourceRoot":"","sources":["../src/identifier-creators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,E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,IAAI,eAAe,SAAS,QAAQ,GACrH,sBAAsB,GACtB,yBAAyB,CAAC,OAAO,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC,CAAC;AAElE;;GAEG;AACH,MAAM,MAAM,mCAAmC,GAAG;IAC9C,QAAQ,EAAE,eAAe,IAAI,cAAc,GAAG,kCAAkC,CAAC,eAAe,CAAC;CACpG,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,mCAa3C,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,iBAAiB,EAAE,iBAAiB,GAAG,iBAAiB,IAAI,wBAAwB,CAE9H;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,iBAAiB,EAAE,iBAAiB,GAAG,iBAAiB,IAAI,WAAW,CAEpG;AAED;;;;;;;;GAQG;AACH,wBAAgB,iCAAiC,CAAC,iBAAiB,EAAE,iBAAiB,GAAG,iBAAiB,IAAI,+BAA+B,CAE5I;AAED;;;;;;;;GAQG;AACH,wBAAgB,yCAAyC,CAAC,iBAAiB,EAAE,iBAAiB,GAAG,iBAAiB,IAAI,uCAAuC,CAE5J;AAED;;;;;;;;GAQG;AACH,wBAAgB,sCAAsC,CAAC,iBAAiB,EAAE,iBAAiB,GAAG,iBAAiB,IAAI,oCAAoC,CAEtJ;AAED;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAAC,iBAAiB,EAAE,iBAAiB,GAAG,iBAAiB,IAAI,2BAA2B,CAEpI"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { GTINCreator } from "./gtin-creator.js";
|
|
2
|
+
import { isGTINExtension, isNonGTINNumericIdentifierExtension, isNonNumericIdentifierExtension, isNonSerializableNumericIdentifierExtension, isNumericIdentifierExtension, isSerializableNumericIdentifierExtension } from "./identifier-extension.js";
|
|
3
|
+
import { NonNumericIdentifierCreator } from "./non-numeric-identifier-creator.js";
|
|
4
|
+
import { NonSerializableNumericIdentifierCreator } from "./non-serializable-numeric-identifier-creator.js";
|
|
5
|
+
import { SerializableNumericIdentifierCreator } from "./serializable-numeric-identifier-creator.js";
|
|
6
|
+
export const IdentifierCreatorConstructors = {
|
|
7
|
+
GTIN: GTINCreator,
|
|
8
|
+
GLN: NonSerializableNumericIdentifierCreator,
|
|
9
|
+
SSCC: NonSerializableNumericIdentifierCreator,
|
|
10
|
+
GRAI: SerializableNumericIdentifierCreator,
|
|
11
|
+
GIAI: NonNumericIdentifierCreator,
|
|
12
|
+
GSRN: NonSerializableNumericIdentifierCreator,
|
|
13
|
+
GDTI: SerializableNumericIdentifierCreator,
|
|
14
|
+
GINC: NonNumericIdentifierCreator,
|
|
15
|
+
GSIN: NonSerializableNumericIdentifierCreator,
|
|
16
|
+
GCN: SerializableNumericIdentifierCreator,
|
|
17
|
+
CPID: NonNumericIdentifierCreator,
|
|
18
|
+
GMN: NonNumericIdentifierCreator
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Determine if identifier creator is a numeric identifier creator.
|
|
22
|
+
*
|
|
23
|
+
* @param identifierCreator
|
|
24
|
+
* Identifier creator.
|
|
25
|
+
*
|
|
26
|
+
* @returns
|
|
27
|
+
* True if identifier creator is a numeric identifier creator.
|
|
28
|
+
*/
|
|
29
|
+
export function isNumericIdentifierCreator(identifierCreator) {
|
|
30
|
+
return isNumericIdentifierExtension(identifierCreator);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Determine if identifier creator is a GTIN creator.
|
|
34
|
+
*
|
|
35
|
+
* @param identifierCreator
|
|
36
|
+
* Identifier creator.
|
|
37
|
+
*
|
|
38
|
+
* @returns
|
|
39
|
+
* True if identifier creator is a GTIN creator.
|
|
40
|
+
*/
|
|
41
|
+
export function isGTINCreator(identifierCreator) {
|
|
42
|
+
return isGTINExtension(identifierCreator);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Determine if identifier creator is a non-GTIN numeric identifier creator.
|
|
46
|
+
*
|
|
47
|
+
* @param identifierCreator
|
|
48
|
+
* Identifier creator.
|
|
49
|
+
*
|
|
50
|
+
* @returns
|
|
51
|
+
* True if identifier creator is a non-GTIN numeric identifier creator.
|
|
52
|
+
*/
|
|
53
|
+
export function isNonGTINNumericIdentifierCreator(identifierCreator) {
|
|
54
|
+
return isNonGTINNumericIdentifierExtension(identifierCreator);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Determine if identifier creator is a non-serializable numeric identifier creator.
|
|
58
|
+
*
|
|
59
|
+
* @param identifierCreator
|
|
60
|
+
* Identifier creator.
|
|
61
|
+
*
|
|
62
|
+
* @returns
|
|
63
|
+
* True if identifier creator is a non-serializable numeric identifier creator.
|
|
64
|
+
*/
|
|
65
|
+
export function isNonSerializableNumericIdentifierCreator(identifierCreator) {
|
|
66
|
+
return isNonSerializableNumericIdentifierExtension(identifierCreator);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Determine if identifier creator is a serializable numeric identifier creator.
|
|
70
|
+
*
|
|
71
|
+
* @param identifierCreator
|
|
72
|
+
* Identifier creator.
|
|
73
|
+
*
|
|
74
|
+
* @returns
|
|
75
|
+
* True if identifier creator is a serializable numeric identifier creator.
|
|
76
|
+
*/
|
|
77
|
+
export function isSerializableNumericIdentifierCreator(identifierCreator) {
|
|
78
|
+
return isSerializableNumericIdentifierExtension(identifierCreator);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Determine if identifier creator is a non-numeric identifier creator.
|
|
82
|
+
*
|
|
83
|
+
* @param identifierCreator
|
|
84
|
+
* Identifier creator.
|
|
85
|
+
*
|
|
86
|
+
* @returns
|
|
87
|
+
* True if identifier creator is a non-numeric identifier creator.
|
|
88
|
+
*/
|
|
89
|
+
export function isNonNumericIdentifierCreator(identifierCreator) {
|
|
90
|
+
return isNonNumericIdentifierExtension(identifierCreator);
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=identifier-creators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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AAC,CAAC;AAC1E,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,sCAAsC,CAAC,iBAAoC;IACvF,OAAO,wCAAwC,CAAC,iBAAiB,CAAC,CAAC;AACvE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,6BAA6B,CAAC,iBAAoC;IAC9E,OAAO,+BAA+B,CAAC,iBAAiB,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ContentCharacterSet } from "./content-character-set.js";
|
|
2
|
+
import type { IdentifierType } from "./identifier-type.js";
|
|
3
|
+
import type { PrefixType } from "./prefix-type.js";
|
|
4
|
+
/**
|
|
5
|
+
* Identifier descriptor. Instantiations of this type are used to parameterize validators and creators.
|
|
6
|
+
*/
|
|
7
|
+
export interface IdentifierDescriptor {
|
|
8
|
+
/**
|
|
9
|
+
* Identifier type. Per the GS1 General Specifications, the identifier type determines the remaining properties.
|
|
10
|
+
*/
|
|
11
|
+
readonly identifierType: IdentifierType;
|
|
12
|
+
/**
|
|
13
|
+
* Prefix type supported by the identifier type. For all identifier types except the GTIN, this is a GS1 Company
|
|
14
|
+
* Prefix. For the GTIN, the prefix type determines the length.
|
|
15
|
+
*/
|
|
16
|
+
readonly prefixType: PrefixType;
|
|
17
|
+
/**
|
|
18
|
+
* Length. For numeric identifier types, the length is fixed; for non-numeric identifier types, the length is the
|
|
19
|
+
* maximum.
|
|
20
|
+
*/
|
|
21
|
+
readonly length: number;
|
|
22
|
+
/**
|
|
23
|
+
* Reference character set.
|
|
24
|
+
*/
|
|
25
|
+
readonly referenceCharacterSet: ContentCharacterSet;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=identifier-descriptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifier-descriptor.d.ts","sourceRoot":"","sources":["../src/identifier-descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC;;OAEG;IACH,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IAExC;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAEhC;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,qBAAqB,EAAE,mBAAmB,CAAC;CACvD"}
|