@aidc-toolkit/gs1 0.9.5 → 0.9.7-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 +207 -139
- package/dist/index.d.cts +70 -155
- package/dist/index.d.ts +70 -155
- package/dist/index.js +205 -138
- package/package.json +9 -10
- package/src/idkey.ts +141 -232
- package/src/index.ts +1 -0
- package/test/check.test.ts +1 -1
- package/test/idkey.test.ts +29 -29
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -32
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/workflows/build-publish.yml +0 -20
- package/.idea/gs1.iml +0 -9
- package/.idea/inspectionProfiles/Project_Default.xml +0 -7
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/runConfigurations/Test_all.xml +0 -12
- package/.idea/runConfigurations/Test_check.xml +0 -12
- package/.idea/runConfigurations/Test_identification_key.xml +0 -12
- package/.idea/runConfigurations/build.xml +0 -12
- package/.idea/runConfigurations/eslint.xml +0 -12
- package/.idea/vcs.xml +0 -6
package/dist/index.js
CHANGED
|
@@ -1,3 +1,85 @@
|
|
|
1
|
+
// src/locale/i18n.ts
|
|
2
|
+
import { i18nAddResourceBundle, i18nAssertValidResources, i18next } from "@aidc-toolkit/core";
|
|
3
|
+
|
|
4
|
+
// src/locale/en/locale_strings.ts
|
|
5
|
+
var localeStrings = {
|
|
6
|
+
Check: {
|
|
7
|
+
lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "Length {{length}} of string for check character pair must be less than or equal to {{maximumLength}}"
|
|
8
|
+
},
|
|
9
|
+
IdentificationKey: {
|
|
10
|
+
identificationKeyTypeLength: "{{identificationKeyType}} must be {{length}} digits long",
|
|
11
|
+
invalidCheckDigit: "Invalid check digit",
|
|
12
|
+
invalidGTINLength: "GTIN must be 13, 12, 8, or 14 digits long",
|
|
13
|
+
invalidGTIN14Length: "GTIN must be 14 digits long",
|
|
14
|
+
invalidZeroSuppressedGTIN12: "Invalid zero-suppressed GTIN-12",
|
|
15
|
+
invalidZeroSuppressibleGTIN12: "GTIN-12 not zero-suppressible",
|
|
16
|
+
invalidZeroSuppressedGTIN12AsGTIN13: "Invalid zero-suppressed GTIN-12 as GTIN-13",
|
|
17
|
+
invalidZeroSuppressedGTIN12AsGTIN14: "Invalid zero-suppressed GTIN-12 as GTIN-14",
|
|
18
|
+
invalidGTIN13AtRetail: "GTIN-13 at retail consumer trade item level can't start with zero",
|
|
19
|
+
invalidGTINAtRetail: "GTIN not supported at retail consumer trade item level",
|
|
20
|
+
invalidGTINAtOtherThanRetail: "GTIN not supported at other than retail consumer trade item level",
|
|
21
|
+
indicatorDigit: "indicator digit",
|
|
22
|
+
serialComponent: "serial component",
|
|
23
|
+
reference: "reference",
|
|
24
|
+
referenceCantBeAllNumeric: "Reference can't be all-numeric",
|
|
25
|
+
invalidCheckCharacterPair: "Invalid check character pair"
|
|
26
|
+
},
|
|
27
|
+
Prefix: {
|
|
28
|
+
gs1CompanyPrefix: "GS1 Company Prefix",
|
|
29
|
+
upcCompanyPrefix: "U.P.C. Company Prefix",
|
|
30
|
+
gs18Prefix: "GS1-8 Prefix",
|
|
31
|
+
gs1CompanyPrefixCantStartWith0: `GS1 Company Prefix can't start with "0"`,
|
|
32
|
+
gs1CompanyPrefixCantStartWith00000: `GS1 Company Prefix can't start with "00000"`,
|
|
33
|
+
gs1CompanyPrefixCantStartWith000000: `GS1 Company Prefix can't start with "000000"`,
|
|
34
|
+
upcCompanyPrefixCantStartWith0000: `U.P.C. Company Prefix can't start with "0000"`,
|
|
35
|
+
gs18PrefixCantStartWith0: `GS1-8 Prefix can't start with "0"`,
|
|
36
|
+
identificationKeyTypeNotSupportedByGS18Prefix: "{{identificationKeyType}} not supported by GS1-8 Prefix"
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// src/locale/fr/locale_strings.ts
|
|
41
|
+
var localeStrings2 = {
|
|
42
|
+
Check: {
|
|
43
|
+
lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "La longueur {{length}} de la cha\xEEne pour la paire de caract\xE8res de v\xE9rification doit \xEAtre inf\xE9rieure ou \xE9gale \xE0 {{maximum Length}}"
|
|
44
|
+
},
|
|
45
|
+
IdentificationKey: {
|
|
46
|
+
identificationKeyTypeLength: "{{identificationKeyType}} doit comporter {{length}} chiffres",
|
|
47
|
+
invalidCheckDigit: "Chiffre de contr\xF4le non valide",
|
|
48
|
+
invalidGTINLength: "Le GTIN doit comporter 13, 12, 8 ou 14 chiffres",
|
|
49
|
+
invalidGTIN14Length: "Le GTIN doit comporter 14 chiffres",
|
|
50
|
+
invalidZeroSuppressedGTIN12: "Code GTIN-12 non valide avec z\xE9ro supprim\xE9",
|
|
51
|
+
invalidZeroSuppressibleGTIN12: "Le GTIN-12 ne peut pas \xEAtre supprim\xE9 par z\xE9ro",
|
|
52
|
+
invalidZeroSuppressedGTIN12AsGTIN13: "GTIN-12 non valide avec z\xE9ro supprim\xE9 en tant que GTIN-13",
|
|
53
|
+
invalidZeroSuppressedGTIN12AsGTIN14: "GTIN-12 non valide avec z\xE9ro supprim\xE9 en tant que GTIN-14",
|
|
54
|
+
invalidGTIN13AtRetail: "Le GTIN-13 au niveau des articles de consommation au d\xE9tail ne peut pas commencer par z\xE9ro",
|
|
55
|
+
invalidGTINAtRetail: "Le GTIN n'est pas pris en charge au niveau des articles de consommation au d\xE9tail",
|
|
56
|
+
invalidGTINAtOtherThanRetail: "Le GTIN n'est pas pris en charge \xE0 d'autres niveaux que ceux des articles de consommation au d\xE9tail",
|
|
57
|
+
indicatorDigit: "chiffre indicateur",
|
|
58
|
+
serialComponent: "composant s\xE9rie",
|
|
59
|
+
reference: "r\xE9f\xE9rence",
|
|
60
|
+
referenceCantBeAllNumeric: "La r\xE9f\xE9rence ne peut pas \xEAtre enti\xE8rement num\xE9rique",
|
|
61
|
+
invalidCheckCharacterPair: "Paire de caract\xE8res de contr\xF4le non valide"
|
|
62
|
+
},
|
|
63
|
+
Prefix: {
|
|
64
|
+
gs1CompanyPrefix: "Pr\xE9fixe de l'entreprise GS1",
|
|
65
|
+
upcCompanyPrefix: "Pr\xE9fixe de l'entreprise U.P.C.",
|
|
66
|
+
gs18Prefix: "Pr\xE9fixe GS1-8",
|
|
67
|
+
gs1CompanyPrefixCantStartWith0: `Le pr\xE9fixe de l'entreprise GS1 ne peut pas commencer par "0"`,
|
|
68
|
+
gs1CompanyPrefixCantStartWith00000: `Le pr\xE9fixe de l'entreprise GS1 ne peut pas commencer par "00000"`,
|
|
69
|
+
gs1CompanyPrefixCantStartWith000000: `Le pr\xE9fixe de l'entreprise GS1 ne peut pas commencer par "000000"`,
|
|
70
|
+
upcCompanyPrefixCantStartWith0000: `Le pr\xE9fixe de l'entreprise U.P.C. ne peut pas commencer par "0000"`,
|
|
71
|
+
gs18PrefixCantStartWith0: 'Le pr\xE9fixe GS1-8 ne peut pas commencer par "0"',
|
|
72
|
+
identificationKeyTypeNotSupportedByGS18Prefix: "{{identificationKeyType}} non pris en charge par le pr\xE9fixe GS1-8"
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/locale/i18n.ts
|
|
77
|
+
var gs1NS = "aidct_gs1";
|
|
78
|
+
i18nAssertValidResources(localeStrings, "fr", localeStrings2);
|
|
79
|
+
i18nAddResourceBundle("en", gs1NS, localeStrings);
|
|
80
|
+
i18nAddResourceBundle("fr", gs1NS, localeStrings2);
|
|
81
|
+
var i18n_default = i18next;
|
|
82
|
+
|
|
1
83
|
// src/character_set.ts
|
|
2
84
|
import { CharacterSetCreator, Exclusion } from "@aidc-toolkit/utility";
|
|
3
85
|
var AI82_CREATOR = new CharacterSetCreator([
|
|
@@ -128,90 +210,6 @@ var AI39_CREATOR = new CharacterSetCreator([
|
|
|
128
210
|
|
|
129
211
|
// src/check.ts
|
|
130
212
|
import { NUMERIC_CREATOR } from "@aidc-toolkit/utility";
|
|
131
|
-
|
|
132
|
-
// src/locale/i18n.ts
|
|
133
|
-
import { i18nAddResourceBundle, i18nAssertValidResources, i18next } from "@aidc-toolkit/core";
|
|
134
|
-
|
|
135
|
-
// src/locale/en/locale_strings.ts
|
|
136
|
-
var localeStrings = {
|
|
137
|
-
Check: {
|
|
138
|
-
lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "Length {{length}} of string for check character pair must be less than or equal to {{maximumLength}}"
|
|
139
|
-
},
|
|
140
|
-
IdentificationKey: {
|
|
141
|
-
identificationKeyTypeLength: "{{identificationKeyType}} must be {{length}} digits long",
|
|
142
|
-
invalidCheckDigit: "Invalid check digit",
|
|
143
|
-
invalidGTINLength: "GTIN must be 13, 12, 8, or 14 digits long",
|
|
144
|
-
invalidGTIN14Length: "GTIN must be 14 digits long",
|
|
145
|
-
invalidZeroSuppressedGTIN12: "Invalid zero-suppressed GTIN-12",
|
|
146
|
-
invalidZeroSuppressibleGTIN12: "GTIN-12 not zero-suppressible",
|
|
147
|
-
invalidZeroSuppressedGTIN12AsGTIN13: "Invalid zero-suppressed GTIN-12 as GTIN-13",
|
|
148
|
-
invalidZeroSuppressedGTIN12AsGTIN14: "Invalid zero-suppressed GTIN-12 as GTIN-14",
|
|
149
|
-
invalidGTIN13AtRetail: "GTIN-13 at retail consumer trade item level can't start with zero",
|
|
150
|
-
invalidGTINAtRetail: "GTIN not supported at retail consumer trade item level",
|
|
151
|
-
invalidGTINAtOtherThanRetail: "GTIN not supported at other than retail consumer trade item level",
|
|
152
|
-
indicatorDigit: "indicator digit",
|
|
153
|
-
serialComponent: "serial component",
|
|
154
|
-
reference: "reference",
|
|
155
|
-
referenceCantBeAllNumeric: "Reference can't be all-numeric",
|
|
156
|
-
invalidCheckCharacterPair: "Invalid check character pair"
|
|
157
|
-
},
|
|
158
|
-
Prefix: {
|
|
159
|
-
gs1CompanyPrefix: "GS1 Company Prefix",
|
|
160
|
-
upcCompanyPrefix: "U.P.C. Company Prefix",
|
|
161
|
-
gs18Prefix: "GS1-8 Prefix",
|
|
162
|
-
gs1CompanyPrefixCantStartWith0: `GS1 Company Prefix can't start with "0"`,
|
|
163
|
-
gs1CompanyPrefixCantStartWith00000: `GS1 Company Prefix can't start with "00000"`,
|
|
164
|
-
gs1CompanyPrefixCantStartWith000000: `GS1 Company Prefix can't start with "000000"`,
|
|
165
|
-
upcCompanyPrefixCantStartWith0000: `U.P.C. Company Prefix can't start with "0000"`,
|
|
166
|
-
gs18PrefixCantStartWith0: `GS1-8 Prefix can't start with "0"`,
|
|
167
|
-
identificationKeyTypeNotSupportedByGS18Prefix: "{{identificationKeyType}} not supported by GS1-8 Prefix"
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
// src/locale/fr/locale_strings.ts
|
|
172
|
-
var localeStrings2 = {
|
|
173
|
-
Check: {
|
|
174
|
-
lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "La longueur {{length}} de la cha\xEEne pour la paire de caract\xE8res de v\xE9rification doit \xEAtre inf\xE9rieure ou \xE9gale \xE0 {{maximum Length}}"
|
|
175
|
-
},
|
|
176
|
-
IdentificationKey: {
|
|
177
|
-
identificationKeyTypeLength: "{{identificationKeyType}} doit comporter {{length}} chiffres",
|
|
178
|
-
invalidCheckDigit: "Chiffre de contr\xF4le non valide",
|
|
179
|
-
invalidGTINLength: "Le GTIN doit comporter 13, 12, 8 ou 14 chiffres",
|
|
180
|
-
invalidGTIN14Length: "Le GTIN doit comporter 14 chiffres",
|
|
181
|
-
invalidZeroSuppressedGTIN12: "Code GTIN-12 non valide avec z\xE9ro supprim\xE9",
|
|
182
|
-
invalidZeroSuppressibleGTIN12: "Le GTIN-12 ne peut pas \xEAtre supprim\xE9 par z\xE9ro",
|
|
183
|
-
invalidZeroSuppressedGTIN12AsGTIN13: "GTIN-12 non valide avec z\xE9ro supprim\xE9 en tant que GTIN-13",
|
|
184
|
-
invalidZeroSuppressedGTIN12AsGTIN14: "GTIN-12 non valide avec z\xE9ro supprim\xE9 en tant que GTIN-14",
|
|
185
|
-
invalidGTIN13AtRetail: "Le GTIN-13 au niveau des articles de consommation au d\xE9tail ne peut pas commencer par z\xE9ro",
|
|
186
|
-
invalidGTINAtRetail: "Le GTIN n'est pas pris en charge au niveau des articles de consommation au d\xE9tail",
|
|
187
|
-
invalidGTINAtOtherThanRetail: "Le GTIN n'est pas pris en charge \xE0 d'autres niveaux que ceux des articles de consommation au d\xE9tail",
|
|
188
|
-
indicatorDigit: "chiffre indicateur",
|
|
189
|
-
serialComponent: "composant s\xE9rie",
|
|
190
|
-
reference: "r\xE9f\xE9rence",
|
|
191
|
-
referenceCantBeAllNumeric: "La r\xE9f\xE9rence ne peut pas \xEAtre enti\xE8rement num\xE9rique",
|
|
192
|
-
invalidCheckCharacterPair: "Paire de caract\xE8res de contr\xF4le non valide"
|
|
193
|
-
},
|
|
194
|
-
Prefix: {
|
|
195
|
-
gs1CompanyPrefix: "Pr\xE9fixe de l'entreprise GS1",
|
|
196
|
-
upcCompanyPrefix: "Pr\xE9fixe de l'entreprise U.P.C.",
|
|
197
|
-
gs18Prefix: "Pr\xE9fixe GS1-8",
|
|
198
|
-
gs1CompanyPrefixCantStartWith0: `Le pr\xE9fixe de l'entreprise GS1 ne peut pas commencer par "0"`,
|
|
199
|
-
gs1CompanyPrefixCantStartWith00000: `Le pr\xE9fixe de l'entreprise GS1 ne peut pas commencer par "00000"`,
|
|
200
|
-
gs1CompanyPrefixCantStartWith000000: `Le pr\xE9fixe de l'entreprise GS1 ne peut pas commencer par "000000"`,
|
|
201
|
-
upcCompanyPrefixCantStartWith0000: `Le pr\xE9fixe de l'entreprise U.P.C. ne peut pas commencer par "0000"`,
|
|
202
|
-
gs18PrefixCantStartWith0: 'Le pr\xE9fixe GS1-8 ne peut pas commencer par "0"',
|
|
203
|
-
identificationKeyTypeNotSupportedByGS18Prefix: "{{identificationKeyType}} non pris en charge par le pr\xE9fixe GS1-8"
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
// src/locale/i18n.ts
|
|
208
|
-
var gs1NS = "aidct_gs1";
|
|
209
|
-
i18nAssertValidResources(localeStrings, "fr", localeStrings2);
|
|
210
|
-
i18nAddResourceBundle("en", gs1NS, localeStrings);
|
|
211
|
-
i18nAddResourceBundle("fr", gs1NS, localeStrings2);
|
|
212
|
-
var i18n_default = i18next;
|
|
213
|
-
|
|
214
|
-
// src/check.ts
|
|
215
213
|
var THREE_WEIGHT_RESULTS = [
|
|
216
214
|
0,
|
|
217
215
|
3,
|
|
@@ -423,12 +421,12 @@ var PrefixType = /* @__PURE__ */ ((PrefixType2) => {
|
|
|
423
421
|
PrefixType2[PrefixType2["GS18Prefix"] = 2] = "GS18Prefix";
|
|
424
422
|
return PrefixType2;
|
|
425
423
|
})(PrefixType || {});
|
|
426
|
-
var
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
return
|
|
431
|
-
})(
|
|
424
|
+
var ContentCharacterSet = /* @__PURE__ */ ((ContentCharacterSet2) => {
|
|
425
|
+
ContentCharacterSet2[ContentCharacterSet2["Numeric"] = 0] = "Numeric";
|
|
426
|
+
ContentCharacterSet2[ContentCharacterSet2["AI82"] = 1] = "AI82";
|
|
427
|
+
ContentCharacterSet2[ContentCharacterSet2["AI39"] = 2] = "AI39";
|
|
428
|
+
return ContentCharacterSet2;
|
|
429
|
+
})(ContentCharacterSet || {});
|
|
432
430
|
var AbstractIdentificationKeyValidator = class _AbstractIdentificationKeyValidator {
|
|
433
431
|
static CHARACTER_SET_CREATORS = [
|
|
434
432
|
NUMERIC_CREATOR2,
|
|
@@ -452,19 +450,19 @@ var AbstractIdentificationKeyValidator = class _AbstractIdentificationKeyValidat
|
|
|
452
450
|
*/
|
|
453
451
|
_referenceCharacterSet;
|
|
454
452
|
/**
|
|
455
|
-
* Reference
|
|
453
|
+
* Reference creator.
|
|
456
454
|
*/
|
|
457
|
-
|
|
455
|
+
_referenceCreator;
|
|
458
456
|
/**
|
|
459
|
-
* Get the character set
|
|
457
|
+
* Get the character set creator for a character set.
|
|
460
458
|
*
|
|
461
459
|
* @param characterSet
|
|
462
460
|
* Character set.
|
|
463
461
|
*
|
|
464
462
|
* @returns
|
|
465
|
-
* Character set
|
|
463
|
+
* Character set creator.
|
|
466
464
|
*/
|
|
467
|
-
static
|
|
465
|
+
static creatorFor(characterSet) {
|
|
468
466
|
return _AbstractIdentificationKeyValidator.CHARACTER_SET_CREATORS[characterSet];
|
|
469
467
|
}
|
|
470
468
|
/**
|
|
@@ -487,7 +485,7 @@ var AbstractIdentificationKeyValidator = class _AbstractIdentificationKeyValidat
|
|
|
487
485
|
this._prefixType = prefixType;
|
|
488
486
|
this._length = length;
|
|
489
487
|
this._referenceCharacterSet = referenceCharacterSet;
|
|
490
|
-
this.
|
|
488
|
+
this._referenceCreator = _AbstractIdentificationKeyValidator.creatorFor(referenceCharacterSet);
|
|
491
489
|
}
|
|
492
490
|
/**
|
|
493
491
|
* @inheritDoc
|
|
@@ -516,8 +514,8 @@ var AbstractIdentificationKeyValidator = class _AbstractIdentificationKeyValidat
|
|
|
516
514
|
/**
|
|
517
515
|
* @inheritDoc
|
|
518
516
|
*/
|
|
519
|
-
get
|
|
520
|
-
return this.
|
|
517
|
+
get referenceCreator() {
|
|
518
|
+
return this._referenceCreator;
|
|
521
519
|
}
|
|
522
520
|
/**
|
|
523
521
|
* Pad an identification key on the left with zero-value character for validation purposes. This is done to align an
|
|
@@ -533,7 +531,7 @@ var AbstractIdentificationKeyValidator = class _AbstractIdentificationKeyValidat
|
|
|
533
531
|
* Padded identification key.
|
|
534
532
|
*/
|
|
535
533
|
padIdentificationKey(identificationKey, validation) {
|
|
536
|
-
return validation?.positionOffset === void 0 ? identificationKey : this.
|
|
534
|
+
return validation?.positionOffset === void 0 ? identificationKey : this.referenceCreator.character(0).repeat(validation.positionOffset).concat(identificationKey);
|
|
537
535
|
}
|
|
538
536
|
/**
|
|
539
537
|
* Validate the prefix within an identification key.
|
|
@@ -800,9 +798,9 @@ var SerializableNumericIdentificationKeyValidator = class _SerializableNumericId
|
|
|
800
798
|
*/
|
|
801
799
|
_serialComponentValidation;
|
|
802
800
|
/**
|
|
803
|
-
* Serial component
|
|
801
|
+
* Serial component creator.
|
|
804
802
|
*/
|
|
805
|
-
|
|
803
|
+
_serialComponentCreator;
|
|
806
804
|
/**
|
|
807
805
|
* Constructor.
|
|
808
806
|
*
|
|
@@ -829,7 +827,7 @@ var SerializableNumericIdentificationKeyValidator = class _SerializableNumericId
|
|
|
829
827
|
ns: gs1NS
|
|
830
828
|
})
|
|
831
829
|
};
|
|
832
|
-
this.
|
|
830
|
+
this._serialComponentCreator = _SerializableNumericIdentificationKeyValidator.creatorFor(serialComponentCharacterSet);
|
|
833
831
|
}
|
|
834
832
|
/**
|
|
835
833
|
* Get the serial component length.
|
|
@@ -850,10 +848,10 @@ var SerializableNumericIdentificationKeyValidator = class _SerializableNumericId
|
|
|
850
848
|
return this._serialComponentValidation;
|
|
851
849
|
}
|
|
852
850
|
/**
|
|
853
|
-
* Get the serial component
|
|
851
|
+
* Get the serial component creator.
|
|
854
852
|
*/
|
|
855
|
-
get
|
|
856
|
-
return this.
|
|
853
|
+
get serialComponentCreator() {
|
|
854
|
+
return this._serialComponentCreator;
|
|
857
855
|
}
|
|
858
856
|
/**
|
|
859
857
|
* @inheritDoc
|
|
@@ -861,7 +859,7 @@ var SerializableNumericIdentificationKeyValidator = class _SerializableNumericId
|
|
|
861
859
|
validate(identificationKey, validation) {
|
|
862
860
|
super.validate(identificationKey.substring(0, this.length), validation);
|
|
863
861
|
if (identificationKey.length > this.length) {
|
|
864
|
-
this.
|
|
862
|
+
this.serialComponentCreator.validate(identificationKey.substring(this.length), this._serialComponentValidation);
|
|
865
863
|
}
|
|
866
864
|
}
|
|
867
865
|
};
|
|
@@ -921,7 +919,7 @@ var NonNumericIdentificationKeyValidator = class _NonNumericIdentificationKeyVal
|
|
|
921
919
|
const partialIdentificationKey = this.requiresCheckCharacterPair ? identificationKey.substring(0, identificationKey.length - 2) : identificationKey;
|
|
922
920
|
super.validatePrefix(partialIdentificationKey, validation?.positionOffset);
|
|
923
921
|
if (!this.requiresCheckCharacterPair) {
|
|
924
|
-
this.
|
|
922
|
+
this.referenceCreator.validate(identificationKey, {
|
|
925
923
|
maximumLength: this.length,
|
|
926
924
|
positionOffset: validation?.positionOffset
|
|
927
925
|
});
|
|
@@ -979,12 +977,6 @@ var AbstractIdentificationKeyCreator = class {
|
|
|
979
977
|
this._prefixManager = prefixManager;
|
|
980
978
|
this._referenceLength = this.length - prefix.length - checkAllowance;
|
|
981
979
|
}
|
|
982
|
-
/**
|
|
983
|
-
* @inheritDoc
|
|
984
|
-
*/
|
|
985
|
-
get referenceCreator() {
|
|
986
|
-
return this.referenceValidator;
|
|
987
|
-
}
|
|
988
980
|
/**
|
|
989
981
|
* @inheritDoc
|
|
990
982
|
*/
|
|
@@ -1057,7 +1049,9 @@ var AbstractNumericIdentificationKeyCreator = class _AbstractNumericIdentificati
|
|
|
1057
1049
|
const partialIdentificationKey = this.leaderType === 2 /* ExtensionDigit */ ? reference.substring(0, 1) + this.prefix + reference.substring(1) : this.prefix + reference;
|
|
1058
1050
|
return partialIdentificationKey + checkDigit(partialIdentificationKey);
|
|
1059
1051
|
}
|
|
1060
|
-
|
|
1052
|
+
/**
|
|
1053
|
+
* @inheritDoc
|
|
1054
|
+
*/
|
|
1061
1055
|
create(valueOrValues, sparse = false) {
|
|
1062
1056
|
return NUMERIC_CREATOR2.create(this.referenceLength, valueOrValues, Exclusion2.None, sparse ? this.tweak : void 0, (reference) => this.buildIdentificationKey(reference));
|
|
1063
1057
|
}
|
|
@@ -1155,7 +1149,22 @@ var GTINCreator = class _GTINCreator extends Mixin(GTINValidator, AbstractNumeri
|
|
|
1155
1149
|
get prefix() {
|
|
1156
1150
|
return this.prefixManager.prefix;
|
|
1157
1151
|
}
|
|
1158
|
-
|
|
1152
|
+
/**
|
|
1153
|
+
* Create GTIN-14(s) with an indicator digit and reference(s) based on numeric value(s). The value(s) is/are
|
|
1154
|
+
* converted to reference(s) of the appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
1155
|
+
*
|
|
1156
|
+
* @param indicatorDigit
|
|
1157
|
+
* Indicator digit.
|
|
1158
|
+
*
|
|
1159
|
+
* @param valueOrValues
|
|
1160
|
+
* Numeric value(s).
|
|
1161
|
+
*
|
|
1162
|
+
* @param sparse
|
|
1163
|
+
* If true, the value(s) is/are mapped to a sparse sequence resistant to discovery. Default is false.
|
|
1164
|
+
*
|
|
1165
|
+
* @returns
|
|
1166
|
+
* GTIN-14(s).
|
|
1167
|
+
*/
|
|
1159
1168
|
createGTIN14(indicatorDigit, valueOrValues, sparse = false) {
|
|
1160
1169
|
NUMERIC_CREATOR2.validate(indicatorDigit, _GTINCreator.REQUIRED_INDICATOR_DIGIT_VALIDATION);
|
|
1161
1170
|
return NUMERIC_CREATOR2.create(13 /* GTIN13 */ - this.prefixManager.gs1CompanyPrefix.length - 1, valueOrValues, Exclusion2.None, sparse ? this.tweak : void 0, (reference) => {
|
|
@@ -1328,30 +1337,66 @@ var SerializableNumericIdentificationKeyCreator = class extends Mixin(Serializab
|
|
|
1328
1337
|
this.init(prefixManager, prefixManager.gs1CompanyPrefix);
|
|
1329
1338
|
}
|
|
1330
1339
|
/**
|
|
1331
|
-
*
|
|
1340
|
+
* Concatenate a validated base identification key with serial component(s).
|
|
1341
|
+
*
|
|
1342
|
+
* @param baseIdentificationKey
|
|
1343
|
+
* Base identification key.
|
|
1344
|
+
*
|
|
1345
|
+
* @param serialComponentOrComponents
|
|
1346
|
+
* Serial component(s).
|
|
1347
|
+
*
|
|
1348
|
+
* @returns
|
|
1349
|
+
* Serialized identification key(s).
|
|
1332
1350
|
*/
|
|
1333
|
-
|
|
1334
|
-
return this.serialComponentValidator;
|
|
1335
|
-
}
|
|
1336
|
-
// eslint-disable-next-line jsdoc/require-jsdoc -- Implementation of overloaded signatures.
|
|
1337
|
-
concatenateValidated(baseIdentificationKey, serialComponent) {
|
|
1351
|
+
concatenateValidated(baseIdentificationKey, serialComponentOrComponents) {
|
|
1338
1352
|
let result;
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1353
|
+
const serialComponentCreator = this.serialComponentCreator;
|
|
1354
|
+
const serialComponentValidation = this.serialComponentValidation;
|
|
1355
|
+
function validateAndConcatenate(serialComponent) {
|
|
1356
|
+
serialComponentCreator.validate(serialComponent, serialComponentValidation);
|
|
1357
|
+
return baseIdentificationKey + serialComponent;
|
|
1358
|
+
}
|
|
1359
|
+
if (typeof serialComponentOrComponents !== "object") {
|
|
1360
|
+
result = validateAndConcatenate(serialComponentOrComponents);
|
|
1342
1361
|
} else {
|
|
1343
|
-
result = IteratorProxy.from(
|
|
1362
|
+
result = IteratorProxy.from(serialComponentOrComponents).map(validateAndConcatenate);
|
|
1344
1363
|
}
|
|
1345
1364
|
return result;
|
|
1346
1365
|
}
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1366
|
+
/**
|
|
1367
|
+
* Create serialized identification key(s) with a reference based on a numeric value concatenated with serial
|
|
1368
|
+
* component(s). The value is converted to a reference of the appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
1369
|
+
*
|
|
1370
|
+
* @param value
|
|
1371
|
+
* Numeric value of the reference.
|
|
1372
|
+
*
|
|
1373
|
+
* @param serialComponentOrComponents
|
|
1374
|
+
* Serial component(s).
|
|
1375
|
+
*
|
|
1376
|
+
* @param sparse
|
|
1377
|
+
* If true, the value is mapped to a sparse sequence resistant to discovery. Default is false.
|
|
1378
|
+
*
|
|
1379
|
+
* @returns
|
|
1380
|
+
* Serialized identification keys.
|
|
1381
|
+
*/
|
|
1382
|
+
createSerialized(value, serialComponentOrComponents, sparse) {
|
|
1383
|
+
return this.concatenateValidated(this.create(value, sparse), serialComponentOrComponents);
|
|
1350
1384
|
}
|
|
1351
|
-
|
|
1352
|
-
|
|
1385
|
+
/**
|
|
1386
|
+
* Concatenate a base identification key with serial component(s).
|
|
1387
|
+
*
|
|
1388
|
+
* @param baseIdentificationKey
|
|
1389
|
+
* Base identification key.
|
|
1390
|
+
*
|
|
1391
|
+
* @param serialComponentOrComponents
|
|
1392
|
+
* Serial component(s).
|
|
1393
|
+
*
|
|
1394
|
+
* @returns
|
|
1395
|
+
* Serialized identification key(s).
|
|
1396
|
+
*/
|
|
1397
|
+
concatenate(baseIdentificationKey, serialComponentOrComponents) {
|
|
1353
1398
|
this.validate(baseIdentificationKey);
|
|
1354
|
-
return this.concatenateValidated(baseIdentificationKey,
|
|
1399
|
+
return this.concatenateValidated(baseIdentificationKey, serialComponentOrComponents);
|
|
1355
1400
|
}
|
|
1356
1401
|
};
|
|
1357
1402
|
var NonNumericIdentificationKeyCreator = class extends Mixin(NonNumericIdentificationKeyValidator, AbstractIdentificationKeyCreator) {
|
|
@@ -1390,15 +1435,36 @@ var NonNumericIdentificationKeyCreator = class extends Mixin(NonNumericIdentific
|
|
|
1390
1435
|
})
|
|
1391
1436
|
};
|
|
1392
1437
|
}
|
|
1393
|
-
|
|
1438
|
+
/**
|
|
1439
|
+
* Get the reference validation parameters.
|
|
1440
|
+
*/
|
|
1441
|
+
get referenceValidation() {
|
|
1442
|
+
return this._referenceValidation;
|
|
1443
|
+
}
|
|
1444
|
+
/**
|
|
1445
|
+
* Create identification key(s) with reference(s).
|
|
1446
|
+
*
|
|
1447
|
+
* @param referenceOrReferences
|
|
1448
|
+
* Reference(s).
|
|
1449
|
+
*
|
|
1450
|
+
* @returns
|
|
1451
|
+
* Identification key(s).
|
|
1452
|
+
*/
|
|
1394
1453
|
create(referenceOrReferences) {
|
|
1395
1454
|
let result;
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1455
|
+
const referenceCreator = this.referenceCreator;
|
|
1456
|
+
const referenceValidation = this.referenceValidation;
|
|
1457
|
+
const prefix = this.prefix;
|
|
1458
|
+
const requiresCheckCharacterPair = this.requiresCheckCharacterPair;
|
|
1459
|
+
function validateAndCreate(reference) {
|
|
1460
|
+
referenceCreator.validate(reference, referenceValidation);
|
|
1461
|
+
const partialIdentificationKey = prefix + reference;
|
|
1462
|
+
return requiresCheckCharacterPair ? partialIdentificationKey + checkCharacterPair(partialIdentificationKey) : partialIdentificationKey;
|
|
1463
|
+
}
|
|
1464
|
+
if (typeof referenceOrReferences !== "object") {
|
|
1465
|
+
result = validateAndCreate(referenceOrReferences);
|
|
1400
1466
|
} else {
|
|
1401
|
-
result = IteratorProxy.from(referenceOrReferences).map(
|
|
1467
|
+
result = IteratorProxy.from(referenceOrReferences).map(validateAndCreate);
|
|
1402
1468
|
}
|
|
1403
1469
|
return result;
|
|
1404
1470
|
}
|
|
@@ -1879,7 +1945,7 @@ export {
|
|
|
1879
1945
|
AI39_CREATOR,
|
|
1880
1946
|
AI82_CREATOR,
|
|
1881
1947
|
CPID_VALIDATOR,
|
|
1882
|
-
|
|
1948
|
+
ContentCharacterSet,
|
|
1883
1949
|
GCN_VALIDATOR,
|
|
1884
1950
|
GDTI_VALIDATOR,
|
|
1885
1951
|
GIAI_VALIDATOR,
|
|
@@ -1913,6 +1979,7 @@ export {
|
|
|
1913
1979
|
checkDigitSum,
|
|
1914
1980
|
fiveDigitPriceWeightCheckDigit,
|
|
1915
1981
|
fourDigitPriceWeightCheckDigit,
|
|
1982
|
+
gs1NS,
|
|
1916
1983
|
hasValidCheckCharacterPair,
|
|
1917
1984
|
hasValidCheckDigit
|
|
1918
1985
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aidc-toolkit/gs1",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.7-beta",
|
|
4
4
|
"description": "GS1 AIDC Toolkit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,24 +19,23 @@
|
|
|
19
19
|
"url": "https://www.linkedin.com/in/kdean"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
|
-
"
|
|
22
|
+
"lint": "eslint .",
|
|
23
23
|
"build": "tsup src/index.ts --clean --format cjs,esm --dts",
|
|
24
24
|
"build-doc": "npm run build && tsc src/index.ts --outDir dist --target esnext --moduleResolution nodenext --module nodenext --emitDeclarationOnly --declaration --declarationMap",
|
|
25
25
|
"test": "vitest run"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@aidc-toolkit/dev": "^0.9.
|
|
29
|
-
"eslint": "^9.
|
|
28
|
+
"@aidc-toolkit/dev": "^0.9.7-beta",
|
|
29
|
+
"eslint": "^9.16.0",
|
|
30
30
|
"ts-node": "^10.9.2",
|
|
31
31
|
"tsup": "^8.3.5",
|
|
32
|
-
"typescript": "^5.
|
|
33
|
-
"vitest": "^2.1.
|
|
32
|
+
"typescript": "^5.7.2",
|
|
33
|
+
"vitest": "^2.1.8"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@aidc-toolkit/core": "^0.9.
|
|
37
|
-
"@aidc-toolkit/utility": "^0.9.
|
|
38
|
-
"@rollup/rollup-linux-x64-gnu": "^4.
|
|
39
|
-
"i18next": "^23.16.8",
|
|
36
|
+
"@aidc-toolkit/core": "^0.9.7-beta",
|
|
37
|
+
"@aidc-toolkit/utility": "^0.9.7-beta",
|
|
38
|
+
"@rollup/rollup-linux-x64-gnu": "^4.28.1",
|
|
40
39
|
"ts-mixer": "^6.0.4"
|
|
41
40
|
}
|
|
42
41
|
}
|