@aidc-toolkit/gs1 0.9.10-beta → 0.9.11-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 +118 -118
- package/dist/index.d.cts +52 -52
- package/dist/index.d.ts +52 -52
- package/dist/index.js +118 -118
- package/package.json +6 -6
- package/src/idkey.ts +171 -171
- package/test/idkey.test.ts +114 -114
package/dist/index.cjs
CHANGED
|
@@ -725,7 +725,15 @@ var GTINLevel = /* @__PURE__ */ ((GTINLevel2) => {
|
|
|
725
725
|
})(GTINLevel || {});
|
|
726
726
|
var GTINValidator = class _GTINValidator extends AbstractNumericIdentificationKeyValidator {
|
|
727
727
|
/**
|
|
728
|
-
*
|
|
728
|
+
* Validation parameters for optional indicator digit.
|
|
729
|
+
*/
|
|
730
|
+
static OPTIONAL_INDICATOR_DIGIT_VALIDATION = {
|
|
731
|
+
minimumLength: 0,
|
|
732
|
+
maximumLength: 1,
|
|
733
|
+
component: () => i18nextGS1.t("IdentificationKey.indicatorDigit")
|
|
734
|
+
};
|
|
735
|
+
/**
|
|
736
|
+
* Validation parameters for zero-suppressed GTIN-12.
|
|
729
737
|
*/
|
|
730
738
|
static ZERO_SUPPRESSED_GTIN12_VALIDATION = {
|
|
731
739
|
minimumLength: 8,
|
|
@@ -766,6 +774,35 @@ var GTINValidator = class _GTINValidator extends AbstractNumericIdentificationKe
|
|
|
766
774
|
validatePrefix(partialIdentificationKey, positionOffset) {
|
|
767
775
|
PrefixManager.validatePrefix(this.prefixType, false, false, partialIdentificationKey, true, true, positionOffset);
|
|
768
776
|
}
|
|
777
|
+
/**
|
|
778
|
+
* Zero suppress a GTIN-12.
|
|
779
|
+
*
|
|
780
|
+
* @param gtin12
|
|
781
|
+
* GTIN-12.
|
|
782
|
+
*
|
|
783
|
+
* @returns
|
|
784
|
+
* Zero-suppressed GTIN-12.
|
|
785
|
+
*/
|
|
786
|
+
static zeroSuppress(gtin12) {
|
|
787
|
+
GTIN12_VALIDATOR.validate(gtin12);
|
|
788
|
+
const d = Array.from(gtin12);
|
|
789
|
+
let zeroSuppressedGTIN12;
|
|
790
|
+
if (d[0] === "0" && d[6] === "0" && d[7] === "0") {
|
|
791
|
+
if (d[10] >= "5" && d[8] === "0" && d[9] === "0" && d[5] !== "0") {
|
|
792
|
+
zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[3]}${d[4]}${d[5]}${d[10]}${d[11]}`;
|
|
793
|
+
} else if (d[5] === "0" && d[8] === "0" && d[9] === "0" && d[4] !== "0") {
|
|
794
|
+
zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[3]}${d[4]}${d[10]}4${d[11]}`;
|
|
795
|
+
} else if (d[3] <= "2" && d[4] === "0" && d[5] === "0") {
|
|
796
|
+
zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[8]}${d[9]}${d[10]}${d[3]}${d[11]}`;
|
|
797
|
+
} else if (d[3] >= "3" && d[4] === "0" && d[5] === "0" && d[8] === "0") {
|
|
798
|
+
zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[3]}${d[9]}${d[10]}3${d[11]}`;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
if (zeroSuppressedGTIN12 === void 0) {
|
|
802
|
+
throw new RangeError(i18nextGS1.t("IdentificationKey.invalidZeroSuppressibleGTIN12"));
|
|
803
|
+
}
|
|
804
|
+
return zeroSuppressedGTIN12;
|
|
805
|
+
}
|
|
769
806
|
/**
|
|
770
807
|
* Zero expand a zero-suppressed GTIN-12.
|
|
771
808
|
*
|
|
@@ -796,6 +833,86 @@ var GTINValidator = class _GTINValidator extends AbstractNumericIdentificationKe
|
|
|
796
833
|
GTIN12_VALIDATOR.validate(gtin12);
|
|
797
834
|
return gtin12;
|
|
798
835
|
}
|
|
836
|
+
/**
|
|
837
|
+
* Convert a GTIN of any length to a GTIN-14 with an optional indicator digit.
|
|
838
|
+
*
|
|
839
|
+
* @param indicatorDigit
|
|
840
|
+
* Indicator digit. If blank, assumes "0" if the GTIN is not already a GTIN-14.
|
|
841
|
+
*
|
|
842
|
+
* @param gtin
|
|
843
|
+
* GTIN.
|
|
844
|
+
*
|
|
845
|
+
* @returns
|
|
846
|
+
* GTIN-14.
|
|
847
|
+
*/
|
|
848
|
+
static convertToGTIN14(indicatorDigit, gtin) {
|
|
849
|
+
GTINCreator.validateAny(gtin);
|
|
850
|
+
import_utility4.NUMERIC_CREATOR.validate(indicatorDigit, _GTINValidator.OPTIONAL_INDICATOR_DIGIT_VALIDATION);
|
|
851
|
+
const gtinLength = gtin.length;
|
|
852
|
+
let gtin14 = "0".repeat(14 /* GTIN14 */ - gtinLength) + gtin;
|
|
853
|
+
if (indicatorDigit.length !== 0 && indicatorDigit !== gtin14.charAt(0)) {
|
|
854
|
+
const partialGTIN14 = indicatorDigit + gtin14.substring(1, 14 /* GTIN14 */ - 1);
|
|
855
|
+
gtin14 = partialGTIN14 + checkDigit(partialGTIN14);
|
|
856
|
+
}
|
|
857
|
+
return gtin14;
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* Normalize a GTIN of any length.
|
|
861
|
+
* - A GTIN-14 that starts with six zeros or a GTIN-13 that starts with five zeros is normalized to GTIN-8.
|
|
862
|
+
* - A GTIN-14 that starts with two zeros or a GTIN-13 that starts with one zero is normalized to GTIN-12.
|
|
863
|
+
* - A GTIN-14 that starts with one zero is normalized to GTIN-13.
|
|
864
|
+
* - Otherwise, the GTIN is unchanged.
|
|
865
|
+
*
|
|
866
|
+
* @param gtin
|
|
867
|
+
* GTIN.
|
|
868
|
+
*
|
|
869
|
+
* @returns
|
|
870
|
+
* Normalized GTIN.
|
|
871
|
+
*/
|
|
872
|
+
static normalize(gtin) {
|
|
873
|
+
const gtinLength = gtin.length;
|
|
874
|
+
let normalizedGTIN;
|
|
875
|
+
switch (gtinLength) {
|
|
876
|
+
case 13 /* GTIN13 */:
|
|
877
|
+
if (!gtin.startsWith("0")) {
|
|
878
|
+
normalizedGTIN = gtin;
|
|
879
|
+
} else if (!gtin.startsWith("00000")) {
|
|
880
|
+
normalizedGTIN = gtin.substring(1);
|
|
881
|
+
} else if (!gtin.startsWith("000000")) {
|
|
882
|
+
normalizedGTIN = gtin.substring(5);
|
|
883
|
+
} else {
|
|
884
|
+
throw new RangeError(i18nextGS1.t("IdentificationKey.invalidZeroSuppressedGTIN12AsGTIN13"));
|
|
885
|
+
}
|
|
886
|
+
break;
|
|
887
|
+
case 12 /* GTIN12 */:
|
|
888
|
+
normalizedGTIN = gtin;
|
|
889
|
+
break;
|
|
890
|
+
case 8 /* GTIN8 */:
|
|
891
|
+
if (!gtin.startsWith("0")) {
|
|
892
|
+
normalizedGTIN = gtin;
|
|
893
|
+
} else {
|
|
894
|
+
normalizedGTIN = _GTINValidator.zeroExpand(gtin);
|
|
895
|
+
}
|
|
896
|
+
break;
|
|
897
|
+
case 14 /* GTIN14 */:
|
|
898
|
+
if (!gtin.startsWith("0")) {
|
|
899
|
+
normalizedGTIN = gtin;
|
|
900
|
+
} else if (!gtin.startsWith("00")) {
|
|
901
|
+
normalizedGTIN = gtin.substring(1);
|
|
902
|
+
} else if (!gtin.startsWith("000000")) {
|
|
903
|
+
normalizedGTIN = gtin.substring(2);
|
|
904
|
+
} else if (!gtin.startsWith("0000000")) {
|
|
905
|
+
normalizedGTIN = gtin.substring(6);
|
|
906
|
+
} else {
|
|
907
|
+
throw new RangeError(i18nextGS1.t("IdentificationKey.invalidZeroSuppressedGTIN12AsGTIN14"));
|
|
908
|
+
}
|
|
909
|
+
break;
|
|
910
|
+
default:
|
|
911
|
+
throw new RangeError(i18nextGS1.t("IdentificationKey.invalidGTINLength"));
|
|
912
|
+
}
|
|
913
|
+
GTINCreator.validateAny(normalizedGTIN);
|
|
914
|
+
return normalizedGTIN;
|
|
915
|
+
}
|
|
799
916
|
/**
|
|
800
917
|
* Validate any GTIN, optionally against a level.
|
|
801
918
|
*
|
|
@@ -1205,14 +1322,6 @@ var GTINCreator = class _GTINCreator extends (0, import_ts_mixer.Mixin)(GTINVali
|
|
|
1205
1322
|
maximumLength: 1,
|
|
1206
1323
|
component: () => i18nextGS1.t("IdentificationKey.indicatorDigit")
|
|
1207
1324
|
};
|
|
1208
|
-
/**
|
|
1209
|
-
* Validation parameters for optional indicator digit.
|
|
1210
|
-
*/
|
|
1211
|
-
static OPTIONAL_INDICATOR_DIGIT_VALIDATION = {
|
|
1212
|
-
minimumLength: 0,
|
|
1213
|
-
maximumLength: 1,
|
|
1214
|
-
component: () => i18nextGS1.t("IdentificationKey.indicatorDigit")
|
|
1215
|
-
};
|
|
1216
1325
|
/**
|
|
1217
1326
|
* Constructor. Called internally by {@link PrefixManager.gtinCreator}; should not be called by other code.
|
|
1218
1327
|
*
|
|
@@ -1255,115 +1364,6 @@ var GTINCreator = class _GTINCreator extends (0, import_ts_mixer.Mixin)(GTINVali
|
|
|
1255
1364
|
return partialIdentificationKey + checkDigit(partialIdentificationKey);
|
|
1256
1365
|
});
|
|
1257
1366
|
}
|
|
1258
|
-
/**
|
|
1259
|
-
* Zero suppress a GTIN-12.
|
|
1260
|
-
*
|
|
1261
|
-
* @param gtin12
|
|
1262
|
-
* GTIN-12.
|
|
1263
|
-
*
|
|
1264
|
-
* @returns
|
|
1265
|
-
* Zero-suppressed GTIN-12.
|
|
1266
|
-
*/
|
|
1267
|
-
static zeroSuppress(gtin12) {
|
|
1268
|
-
GTIN12_VALIDATOR.validate(gtin12);
|
|
1269
|
-
const d = Array.from(gtin12);
|
|
1270
|
-
let zeroSuppressedGTIN12;
|
|
1271
|
-
if (d[0] === "0" && d[6] === "0" && d[7] === "0") {
|
|
1272
|
-
if (d[10] >= "5" && d[8] === "0" && d[9] === "0" && d[5] !== "0") {
|
|
1273
|
-
zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[3]}${d[4]}${d[5]}${d[10]}${d[11]}`;
|
|
1274
|
-
} else if (d[5] === "0" && d[8] === "0" && d[9] === "0" && d[4] !== "0") {
|
|
1275
|
-
zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[3]}${d[4]}${d[10]}4${d[11]}`;
|
|
1276
|
-
} else if (d[3] <= "2" && d[4] === "0" && d[5] === "0") {
|
|
1277
|
-
zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[8]}${d[9]}${d[10]}${d[3]}${d[11]}`;
|
|
1278
|
-
} else if (d[3] >= "3" && d[4] === "0" && d[5] === "0" && d[8] === "0") {
|
|
1279
|
-
zeroSuppressedGTIN12 = `0${d[1]}${d[2]}${d[3]}${d[9]}${d[10]}3${d[11]}`;
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
if (zeroSuppressedGTIN12 === void 0) {
|
|
1283
|
-
throw new RangeError(i18nextGS1.t("IdentificationKey.invalidZeroSuppressibleGTIN12"));
|
|
1284
|
-
}
|
|
1285
|
-
return zeroSuppressedGTIN12;
|
|
1286
|
-
}
|
|
1287
|
-
/**
|
|
1288
|
-
* Convert a GTIN of any length to a GTIN-14 with an optional indicator digit.
|
|
1289
|
-
*
|
|
1290
|
-
* @param indicatorDigit
|
|
1291
|
-
* Indicator digit. If blank, assumes "0" if the GTIN is not already a GTIN-14.
|
|
1292
|
-
*
|
|
1293
|
-
* @param gtin
|
|
1294
|
-
* GTIN.
|
|
1295
|
-
*
|
|
1296
|
-
* @returns
|
|
1297
|
-
* GTIN-14.
|
|
1298
|
-
*/
|
|
1299
|
-
static convertToGTIN14(indicatorDigit, gtin) {
|
|
1300
|
-
_GTINCreator.validateAny(gtin);
|
|
1301
|
-
import_utility4.NUMERIC_CREATOR.validate(indicatorDigit, _GTINCreator.OPTIONAL_INDICATOR_DIGIT_VALIDATION);
|
|
1302
|
-
const gtinLength = gtin.length;
|
|
1303
|
-
let gtin14 = "0".repeat(14 /* GTIN14 */ - gtinLength) + gtin;
|
|
1304
|
-
if (indicatorDigit.length !== 0 && indicatorDigit !== gtin14.charAt(0)) {
|
|
1305
|
-
const partialGTIN14 = indicatorDigit + gtin14.substring(1, 14 /* GTIN14 */ - 1);
|
|
1306
|
-
gtin14 = partialGTIN14 + checkDigit(partialGTIN14);
|
|
1307
|
-
}
|
|
1308
|
-
return gtin14;
|
|
1309
|
-
}
|
|
1310
|
-
/**
|
|
1311
|
-
* Normalize a GTIN of any length.
|
|
1312
|
-
* - A GTIN-14 that starts with six zeros or a GTIN-13 that starts with five zeros is normalized to GTIN-8.
|
|
1313
|
-
* - A GTIN-14 that starts with two zeros or a GTIN-13 that starts with one zero is normalized to GTIN-12.
|
|
1314
|
-
* - A GTIN-14 that starts with one zero is normalized to GTIN-13.
|
|
1315
|
-
* - Otherwise, the GTIN is unchanged.
|
|
1316
|
-
*
|
|
1317
|
-
* @param gtin
|
|
1318
|
-
* GTIN.
|
|
1319
|
-
*
|
|
1320
|
-
* @returns
|
|
1321
|
-
* Normalized GTIN.
|
|
1322
|
-
*/
|
|
1323
|
-
static normalize(gtin) {
|
|
1324
|
-
const gtinLength = gtin.length;
|
|
1325
|
-
let normalizedGTIN;
|
|
1326
|
-
switch (gtinLength) {
|
|
1327
|
-
case 13 /* GTIN13 */:
|
|
1328
|
-
if (!gtin.startsWith("0")) {
|
|
1329
|
-
normalizedGTIN = gtin;
|
|
1330
|
-
} else if (!gtin.startsWith("00000")) {
|
|
1331
|
-
normalizedGTIN = gtin.substring(1);
|
|
1332
|
-
} else if (!gtin.startsWith("000000")) {
|
|
1333
|
-
normalizedGTIN = gtin.substring(5);
|
|
1334
|
-
} else {
|
|
1335
|
-
throw new RangeError(i18nextGS1.t("IdentificationKey.invalidZeroSuppressedGTIN12AsGTIN13"));
|
|
1336
|
-
}
|
|
1337
|
-
break;
|
|
1338
|
-
case 12 /* GTIN12 */:
|
|
1339
|
-
normalizedGTIN = gtin;
|
|
1340
|
-
break;
|
|
1341
|
-
case 8 /* GTIN8 */:
|
|
1342
|
-
if (!gtin.startsWith("0")) {
|
|
1343
|
-
normalizedGTIN = gtin;
|
|
1344
|
-
} else {
|
|
1345
|
-
normalizedGTIN = _GTINCreator.zeroExpand(gtin);
|
|
1346
|
-
}
|
|
1347
|
-
break;
|
|
1348
|
-
case 14 /* GTIN14 */:
|
|
1349
|
-
if (!gtin.startsWith("0")) {
|
|
1350
|
-
normalizedGTIN = gtin;
|
|
1351
|
-
} else if (!gtin.startsWith("00")) {
|
|
1352
|
-
normalizedGTIN = gtin.substring(1);
|
|
1353
|
-
} else if (!gtin.startsWith("000000")) {
|
|
1354
|
-
normalizedGTIN = gtin.substring(2);
|
|
1355
|
-
} else if (!gtin.startsWith("0000000")) {
|
|
1356
|
-
normalizedGTIN = gtin.substring(6);
|
|
1357
|
-
} else {
|
|
1358
|
-
throw new RangeError(i18nextGS1.t("IdentificationKey.invalidZeroSuppressedGTIN12AsGTIN14"));
|
|
1359
|
-
}
|
|
1360
|
-
break;
|
|
1361
|
-
default:
|
|
1362
|
-
throw new RangeError(i18nextGS1.t("IdentificationKey.invalidGTINLength"));
|
|
1363
|
-
}
|
|
1364
|
-
_GTINCreator.validateAny(normalizedGTIN);
|
|
1365
|
-
return normalizedGTIN;
|
|
1366
|
-
}
|
|
1367
1367
|
};
|
|
1368
1368
|
var NonGTINNumericIdentificationKeyCreator = class extends (0, import_ts_mixer.Mixin)(NonGTINNumericIdentificationKeyValidator, AbstractNumericIdentificationKeyCreator) {
|
|
1369
1369
|
/**
|
package/dist/index.d.cts
CHANGED
|
@@ -333,7 +333,7 @@ interface IdentificationKeyValidation extends StringValidation {
|
|
|
333
333
|
* Identification key validator. Validates an identification key against its definition in section 3 of the {@link
|
|
334
334
|
* https://www.gs1.org/genspecs | GS1 General Specifications}.
|
|
335
335
|
*/
|
|
336
|
-
interface IdentificationKeyValidator<
|
|
336
|
+
interface IdentificationKeyValidator<TIdentificationKeyValidation extends IdentificationKeyValidation = IdentificationKeyValidation> extends StringValidator<TIdentificationKeyValidation> {
|
|
337
337
|
/**
|
|
338
338
|
* Get the identification key type. Per the GS1 General Specifications, the identification key type determines
|
|
339
339
|
* the remaining properties.
|
|
@@ -366,12 +366,12 @@ interface IdentificationKeyValidator<V extends IdentificationKeyValidation = Ide
|
|
|
366
366
|
* @param validation
|
|
367
367
|
* Identification key validation parameters.
|
|
368
368
|
*/
|
|
369
|
-
validate: (identificationKey: string, validation?:
|
|
369
|
+
validate: (identificationKey: string, validation?: TIdentificationKeyValidation) => void;
|
|
370
370
|
}
|
|
371
371
|
/**
|
|
372
372
|
* Abstract identification key validator. Implements common functionality for an identification key validator.
|
|
373
373
|
*/
|
|
374
|
-
declare abstract class AbstractIdentificationKeyValidator<
|
|
374
|
+
declare abstract class AbstractIdentificationKeyValidator<TIdentificationKeyValidation extends IdentificationKeyValidation = IdentificationKeyValidation> implements IdentificationKeyValidator<TIdentificationKeyValidation> {
|
|
375
375
|
private static readonly CHARACTER_SET_CREATORS;
|
|
376
376
|
/**
|
|
377
377
|
* Identification key type.
|
|
@@ -463,7 +463,7 @@ declare abstract class AbstractIdentificationKeyValidator<V extends Identificati
|
|
|
463
463
|
* Position offset within a larger string.
|
|
464
464
|
*/
|
|
465
465
|
protected validatePrefix(partialIdentificationKey: string, positionOffset?: number): void;
|
|
466
|
-
abstract validate(identificationKey: string, validation?:
|
|
466
|
+
abstract validate(identificationKey: string, validation?: TIdentificationKeyValidation): void;
|
|
467
467
|
}
|
|
468
468
|
/**
|
|
469
469
|
* Leader type.
|
|
@@ -572,7 +572,11 @@ declare enum GTINLevel {
|
|
|
572
572
|
*/
|
|
573
573
|
declare class GTINValidator extends AbstractNumericIdentificationKeyValidator {
|
|
574
574
|
/**
|
|
575
|
-
*
|
|
575
|
+
* Validation parameters for optional indicator digit.
|
|
576
|
+
*/
|
|
577
|
+
private static readonly OPTIONAL_INDICATOR_DIGIT_VALIDATION;
|
|
578
|
+
/**
|
|
579
|
+
* Validation parameters for zero-suppressed GTIN-12.
|
|
576
580
|
*/
|
|
577
581
|
private static readonly ZERO_SUPPRESSED_GTIN12_VALIDATION;
|
|
578
582
|
/**
|
|
@@ -590,6 +594,16 @@ declare class GTINValidator extends AbstractNumericIdentificationKeyValidator {
|
|
|
590
594
|
* @inheritDoc
|
|
591
595
|
*/
|
|
592
596
|
protected validatePrefix(partialIdentificationKey: string, positionOffset?: number): void;
|
|
597
|
+
/**
|
|
598
|
+
* Zero suppress a GTIN-12.
|
|
599
|
+
*
|
|
600
|
+
* @param gtin12
|
|
601
|
+
* GTIN-12.
|
|
602
|
+
*
|
|
603
|
+
* @returns
|
|
604
|
+
* Zero-suppressed GTIN-12.
|
|
605
|
+
*/
|
|
606
|
+
static zeroSuppress(gtin12: string): string;
|
|
593
607
|
/**
|
|
594
608
|
* Zero expand a zero-suppressed GTIN-12.
|
|
595
609
|
*
|
|
@@ -600,6 +614,33 @@ declare class GTINValidator extends AbstractNumericIdentificationKeyValidator {
|
|
|
600
614
|
* GTIN-12.
|
|
601
615
|
*/
|
|
602
616
|
static zeroExpand(zeroSuppressedGTIN12: string): string;
|
|
617
|
+
/**
|
|
618
|
+
* Convert a GTIN of any length to a GTIN-14 with an optional indicator digit.
|
|
619
|
+
*
|
|
620
|
+
* @param indicatorDigit
|
|
621
|
+
* Indicator digit. If blank, assumes "0" if the GTIN is not already a GTIN-14.
|
|
622
|
+
*
|
|
623
|
+
* @param gtin
|
|
624
|
+
* GTIN.
|
|
625
|
+
*
|
|
626
|
+
* @returns
|
|
627
|
+
* GTIN-14.
|
|
628
|
+
*/
|
|
629
|
+
static convertToGTIN14(indicatorDigit: string, gtin: string): string;
|
|
630
|
+
/**
|
|
631
|
+
* Normalize a GTIN of any length.
|
|
632
|
+
* - A GTIN-14 that starts with six zeros or a GTIN-13 that starts with five zeros is normalized to GTIN-8.
|
|
633
|
+
* - A GTIN-14 that starts with two zeros or a GTIN-13 that starts with one zero is normalized to GTIN-12.
|
|
634
|
+
* - A GTIN-14 that starts with one zero is normalized to GTIN-13.
|
|
635
|
+
* - Otherwise, the GTIN is unchanged.
|
|
636
|
+
*
|
|
637
|
+
* @param gtin
|
|
638
|
+
* GTIN.
|
|
639
|
+
*
|
|
640
|
+
* @returns
|
|
641
|
+
* Normalized GTIN.
|
|
642
|
+
*/
|
|
643
|
+
static normalize(gtin: string): string;
|
|
603
644
|
/**
|
|
604
645
|
* Validate any GTIN, optionally against a level.
|
|
605
646
|
*
|
|
@@ -895,7 +936,7 @@ interface NumericIdentificationKeyCreator extends NumericIdentificationKeyValida
|
|
|
895
936
|
* @returns
|
|
896
937
|
* Identification key(s).
|
|
897
938
|
*/
|
|
898
|
-
create: <
|
|
939
|
+
create: <TTransformerInput extends TransformerInput<number | bigint>>(valueOrValues: TTransformerInput, sparse?: boolean) => TransformerOutput<TTransformerInput, string>;
|
|
899
940
|
/**
|
|
900
941
|
* Create all identification keys for the prefix from `0` to `capacity - 1`.
|
|
901
942
|
*
|
|
@@ -956,7 +997,7 @@ declare abstract class AbstractNumericIdentificationKeyCreator extends AbstractI
|
|
|
956
997
|
/**
|
|
957
998
|
* @inheritDoc
|
|
958
999
|
*/
|
|
959
|
-
create<
|
|
1000
|
+
create<TTransformerInput extends TransformerInput<number | bigint>>(valueOrValues: TTransformerInput, sparse?: boolean): TransformerOutput<TTransformerInput, string>;
|
|
960
1001
|
/**
|
|
961
1002
|
* Create all identification keys from a partial identification key. Call is recursive until remaining reference
|
|
962
1003
|
* length is 0.
|
|
@@ -995,10 +1036,6 @@ declare class GTINCreator extends GTINCreator_base {
|
|
|
995
1036
|
* Validation parameters for required indicator digit.
|
|
996
1037
|
*/
|
|
997
1038
|
private static readonly REQUIRED_INDICATOR_DIGIT_VALIDATION;
|
|
998
|
-
/**
|
|
999
|
-
* Validation parameters for optional indicator digit.
|
|
1000
|
-
*/
|
|
1001
|
-
private static readonly OPTIONAL_INDICATOR_DIGIT_VALIDATION;
|
|
1002
1039
|
/**
|
|
1003
1040
|
* Constructor. Called internally by {@link PrefixManager.gtinCreator}; should not be called by other code.
|
|
1004
1041
|
*
|
|
@@ -1029,44 +1066,7 @@ declare class GTINCreator extends GTINCreator_base {
|
|
|
1029
1066
|
* @returns
|
|
1030
1067
|
* GTIN-14(s).
|
|
1031
1068
|
*/
|
|
1032
|
-
createGTIN14<
|
|
1033
|
-
/**
|
|
1034
|
-
* Zero suppress a GTIN-12.
|
|
1035
|
-
*
|
|
1036
|
-
* @param gtin12
|
|
1037
|
-
* GTIN-12.
|
|
1038
|
-
*
|
|
1039
|
-
* @returns
|
|
1040
|
-
* Zero-suppressed GTIN-12.
|
|
1041
|
-
*/
|
|
1042
|
-
static zeroSuppress(gtin12: string): string;
|
|
1043
|
-
/**
|
|
1044
|
-
* Convert a GTIN of any length to a GTIN-14 with an optional indicator digit.
|
|
1045
|
-
*
|
|
1046
|
-
* @param indicatorDigit
|
|
1047
|
-
* Indicator digit. If blank, assumes "0" if the GTIN is not already a GTIN-14.
|
|
1048
|
-
*
|
|
1049
|
-
* @param gtin
|
|
1050
|
-
* GTIN.
|
|
1051
|
-
*
|
|
1052
|
-
* @returns
|
|
1053
|
-
* GTIN-14.
|
|
1054
|
-
*/
|
|
1055
|
-
static convertToGTIN14(indicatorDigit: string, gtin: string): string;
|
|
1056
|
-
/**
|
|
1057
|
-
* Normalize a GTIN of any length.
|
|
1058
|
-
* - A GTIN-14 that starts with six zeros or a GTIN-13 that starts with five zeros is normalized to GTIN-8.
|
|
1059
|
-
* - A GTIN-14 that starts with two zeros or a GTIN-13 that starts with one zero is normalized to GTIN-12.
|
|
1060
|
-
* - A GTIN-14 that starts with one zero is normalized to GTIN-13.
|
|
1061
|
-
* - Otherwise, the GTIN is unchanged.
|
|
1062
|
-
*
|
|
1063
|
-
* @param gtin
|
|
1064
|
-
* GTIN.
|
|
1065
|
-
*
|
|
1066
|
-
* @returns
|
|
1067
|
-
* Normalized GTIN.
|
|
1068
|
-
*/
|
|
1069
|
-
static normalize(gtin: string): string;
|
|
1069
|
+
createGTIN14<TTransformerInput extends TransformerInput<number | bigint>>(indicatorDigit: string, valueOrValues: TTransformerInput, sparse?: boolean): TransformerOutput<TTransformerInput, string>;
|
|
1070
1070
|
}
|
|
1071
1071
|
declare const NonGTINNumericIdentificationKeyCreator_base: ts_mixer_dist_types_types_js.Class<any[], NonGTINNumericIdentificationKeyValidator & AbstractNumericIdentificationKeyCreator, typeof NonGTINNumericIdentificationKeyValidator & typeof AbstractNumericIdentificationKeyCreator>;
|
|
1072
1072
|
/**
|
|
@@ -1145,7 +1145,7 @@ declare class SerializableNumericIdentificationKeyCreator extends SerializableNu
|
|
|
1145
1145
|
* @returns
|
|
1146
1146
|
* Serialized identification keys.
|
|
1147
1147
|
*/
|
|
1148
|
-
createSerialized<
|
|
1148
|
+
createSerialized<TTransformerInput extends TransformerInput<string>>(value: number, serialComponentOrComponents: TTransformerInput, sparse?: boolean): TransformerOutput<TTransformerInput, string>;
|
|
1149
1149
|
/**
|
|
1150
1150
|
* Concatenate a base identification key with serial component(s).
|
|
1151
1151
|
*
|
|
@@ -1158,7 +1158,7 @@ declare class SerializableNumericIdentificationKeyCreator extends SerializableNu
|
|
|
1158
1158
|
* @returns
|
|
1159
1159
|
* Serialized identification key(s).
|
|
1160
1160
|
*/
|
|
1161
|
-
concatenate<
|
|
1161
|
+
concatenate<TTransformerInput extends TransformerInput<string>>(baseIdentificationKey: string, serialComponentOrComponents: TTransformerInput): TransformerOutput<TTransformerInput, string>;
|
|
1162
1162
|
}
|
|
1163
1163
|
declare const NonNumericIdentificationKeyCreator_base: ts_mixer_dist_types_types_js.Class<any[], NonNumericIdentificationKeyValidator & AbstractIdentificationKeyCreator, typeof NonNumericIdentificationKeyValidator & typeof AbstractIdentificationKeyCreator>;
|
|
1164
1164
|
/**
|
|
@@ -1202,7 +1202,7 @@ declare class NonNumericIdentificationKeyCreator extends NonNumericIdentificatio
|
|
|
1202
1202
|
* @returns
|
|
1203
1203
|
* Identification key(s).
|
|
1204
1204
|
*/
|
|
1205
|
-
create<
|
|
1205
|
+
create<TTransformerInput extends TransformerInput<string>>(referenceOrReferences: TTransformerInput): TransformerOutput<TTransformerInput, string>;
|
|
1206
1206
|
}
|
|
1207
1207
|
/**
|
|
1208
1208
|
* Prefix manager. This is the core class for identification key creation.
|
package/dist/index.d.ts
CHANGED
|
@@ -333,7 +333,7 @@ interface IdentificationKeyValidation extends StringValidation {
|
|
|
333
333
|
* Identification key validator. Validates an identification key against its definition in section 3 of the {@link
|
|
334
334
|
* https://www.gs1.org/genspecs | GS1 General Specifications}.
|
|
335
335
|
*/
|
|
336
|
-
interface IdentificationKeyValidator<
|
|
336
|
+
interface IdentificationKeyValidator<TIdentificationKeyValidation extends IdentificationKeyValidation = IdentificationKeyValidation> extends StringValidator<TIdentificationKeyValidation> {
|
|
337
337
|
/**
|
|
338
338
|
* Get the identification key type. Per the GS1 General Specifications, the identification key type determines
|
|
339
339
|
* the remaining properties.
|
|
@@ -366,12 +366,12 @@ interface IdentificationKeyValidator<V extends IdentificationKeyValidation = Ide
|
|
|
366
366
|
* @param validation
|
|
367
367
|
* Identification key validation parameters.
|
|
368
368
|
*/
|
|
369
|
-
validate: (identificationKey: string, validation?:
|
|
369
|
+
validate: (identificationKey: string, validation?: TIdentificationKeyValidation) => void;
|
|
370
370
|
}
|
|
371
371
|
/**
|
|
372
372
|
* Abstract identification key validator. Implements common functionality for an identification key validator.
|
|
373
373
|
*/
|
|
374
|
-
declare abstract class AbstractIdentificationKeyValidator<
|
|
374
|
+
declare abstract class AbstractIdentificationKeyValidator<TIdentificationKeyValidation extends IdentificationKeyValidation = IdentificationKeyValidation> implements IdentificationKeyValidator<TIdentificationKeyValidation> {
|
|
375
375
|
private static readonly CHARACTER_SET_CREATORS;
|
|
376
376
|
/**
|
|
377
377
|
* Identification key type.
|
|
@@ -463,7 +463,7 @@ declare abstract class AbstractIdentificationKeyValidator<V extends Identificati
|
|
|
463
463
|
* Position offset within a larger string.
|
|
464
464
|
*/
|
|
465
465
|
protected validatePrefix(partialIdentificationKey: string, positionOffset?: number): void;
|
|
466
|
-
abstract validate(identificationKey: string, validation?:
|
|
466
|
+
abstract validate(identificationKey: string, validation?: TIdentificationKeyValidation): void;
|
|
467
467
|
}
|
|
468
468
|
/**
|
|
469
469
|
* Leader type.
|
|
@@ -572,7 +572,11 @@ declare enum GTINLevel {
|
|
|
572
572
|
*/
|
|
573
573
|
declare class GTINValidator extends AbstractNumericIdentificationKeyValidator {
|
|
574
574
|
/**
|
|
575
|
-
*
|
|
575
|
+
* Validation parameters for optional indicator digit.
|
|
576
|
+
*/
|
|
577
|
+
private static readonly OPTIONAL_INDICATOR_DIGIT_VALIDATION;
|
|
578
|
+
/**
|
|
579
|
+
* Validation parameters for zero-suppressed GTIN-12.
|
|
576
580
|
*/
|
|
577
581
|
private static readonly ZERO_SUPPRESSED_GTIN12_VALIDATION;
|
|
578
582
|
/**
|
|
@@ -590,6 +594,16 @@ declare class GTINValidator extends AbstractNumericIdentificationKeyValidator {
|
|
|
590
594
|
* @inheritDoc
|
|
591
595
|
*/
|
|
592
596
|
protected validatePrefix(partialIdentificationKey: string, positionOffset?: number): void;
|
|
597
|
+
/**
|
|
598
|
+
* Zero suppress a GTIN-12.
|
|
599
|
+
*
|
|
600
|
+
* @param gtin12
|
|
601
|
+
* GTIN-12.
|
|
602
|
+
*
|
|
603
|
+
* @returns
|
|
604
|
+
* Zero-suppressed GTIN-12.
|
|
605
|
+
*/
|
|
606
|
+
static zeroSuppress(gtin12: string): string;
|
|
593
607
|
/**
|
|
594
608
|
* Zero expand a zero-suppressed GTIN-12.
|
|
595
609
|
*
|
|
@@ -600,6 +614,33 @@ declare class GTINValidator extends AbstractNumericIdentificationKeyValidator {
|
|
|
600
614
|
* GTIN-12.
|
|
601
615
|
*/
|
|
602
616
|
static zeroExpand(zeroSuppressedGTIN12: string): string;
|
|
617
|
+
/**
|
|
618
|
+
* Convert a GTIN of any length to a GTIN-14 with an optional indicator digit.
|
|
619
|
+
*
|
|
620
|
+
* @param indicatorDigit
|
|
621
|
+
* Indicator digit. If blank, assumes "0" if the GTIN is not already a GTIN-14.
|
|
622
|
+
*
|
|
623
|
+
* @param gtin
|
|
624
|
+
* GTIN.
|
|
625
|
+
*
|
|
626
|
+
* @returns
|
|
627
|
+
* GTIN-14.
|
|
628
|
+
*/
|
|
629
|
+
static convertToGTIN14(indicatorDigit: string, gtin: string): string;
|
|
630
|
+
/**
|
|
631
|
+
* Normalize a GTIN of any length.
|
|
632
|
+
* - A GTIN-14 that starts with six zeros or a GTIN-13 that starts with five zeros is normalized to GTIN-8.
|
|
633
|
+
* - A GTIN-14 that starts with two zeros or a GTIN-13 that starts with one zero is normalized to GTIN-12.
|
|
634
|
+
* - A GTIN-14 that starts with one zero is normalized to GTIN-13.
|
|
635
|
+
* - Otherwise, the GTIN is unchanged.
|
|
636
|
+
*
|
|
637
|
+
* @param gtin
|
|
638
|
+
* GTIN.
|
|
639
|
+
*
|
|
640
|
+
* @returns
|
|
641
|
+
* Normalized GTIN.
|
|
642
|
+
*/
|
|
643
|
+
static normalize(gtin: string): string;
|
|
603
644
|
/**
|
|
604
645
|
* Validate any GTIN, optionally against a level.
|
|
605
646
|
*
|
|
@@ -895,7 +936,7 @@ interface NumericIdentificationKeyCreator extends NumericIdentificationKeyValida
|
|
|
895
936
|
* @returns
|
|
896
937
|
* Identification key(s).
|
|
897
938
|
*/
|
|
898
|
-
create: <
|
|
939
|
+
create: <TTransformerInput extends TransformerInput<number | bigint>>(valueOrValues: TTransformerInput, sparse?: boolean) => TransformerOutput<TTransformerInput, string>;
|
|
899
940
|
/**
|
|
900
941
|
* Create all identification keys for the prefix from `0` to `capacity - 1`.
|
|
901
942
|
*
|
|
@@ -956,7 +997,7 @@ declare abstract class AbstractNumericIdentificationKeyCreator extends AbstractI
|
|
|
956
997
|
/**
|
|
957
998
|
* @inheritDoc
|
|
958
999
|
*/
|
|
959
|
-
create<
|
|
1000
|
+
create<TTransformerInput extends TransformerInput<number | bigint>>(valueOrValues: TTransformerInput, sparse?: boolean): TransformerOutput<TTransformerInput, string>;
|
|
960
1001
|
/**
|
|
961
1002
|
* Create all identification keys from a partial identification key. Call is recursive until remaining reference
|
|
962
1003
|
* length is 0.
|
|
@@ -995,10 +1036,6 @@ declare class GTINCreator extends GTINCreator_base {
|
|
|
995
1036
|
* Validation parameters for required indicator digit.
|
|
996
1037
|
*/
|
|
997
1038
|
private static readonly REQUIRED_INDICATOR_DIGIT_VALIDATION;
|
|
998
|
-
/**
|
|
999
|
-
* Validation parameters for optional indicator digit.
|
|
1000
|
-
*/
|
|
1001
|
-
private static readonly OPTIONAL_INDICATOR_DIGIT_VALIDATION;
|
|
1002
1039
|
/**
|
|
1003
1040
|
* Constructor. Called internally by {@link PrefixManager.gtinCreator}; should not be called by other code.
|
|
1004
1041
|
*
|
|
@@ -1029,44 +1066,7 @@ declare class GTINCreator extends GTINCreator_base {
|
|
|
1029
1066
|
* @returns
|
|
1030
1067
|
* GTIN-14(s).
|
|
1031
1068
|
*/
|
|
1032
|
-
createGTIN14<
|
|
1033
|
-
/**
|
|
1034
|
-
* Zero suppress a GTIN-12.
|
|
1035
|
-
*
|
|
1036
|
-
* @param gtin12
|
|
1037
|
-
* GTIN-12.
|
|
1038
|
-
*
|
|
1039
|
-
* @returns
|
|
1040
|
-
* Zero-suppressed GTIN-12.
|
|
1041
|
-
*/
|
|
1042
|
-
static zeroSuppress(gtin12: string): string;
|
|
1043
|
-
/**
|
|
1044
|
-
* Convert a GTIN of any length to a GTIN-14 with an optional indicator digit.
|
|
1045
|
-
*
|
|
1046
|
-
* @param indicatorDigit
|
|
1047
|
-
* Indicator digit. If blank, assumes "0" if the GTIN is not already a GTIN-14.
|
|
1048
|
-
*
|
|
1049
|
-
* @param gtin
|
|
1050
|
-
* GTIN.
|
|
1051
|
-
*
|
|
1052
|
-
* @returns
|
|
1053
|
-
* GTIN-14.
|
|
1054
|
-
*/
|
|
1055
|
-
static convertToGTIN14(indicatorDigit: string, gtin: string): string;
|
|
1056
|
-
/**
|
|
1057
|
-
* Normalize a GTIN of any length.
|
|
1058
|
-
* - A GTIN-14 that starts with six zeros or a GTIN-13 that starts with five zeros is normalized to GTIN-8.
|
|
1059
|
-
* - A GTIN-14 that starts with two zeros or a GTIN-13 that starts with one zero is normalized to GTIN-12.
|
|
1060
|
-
* - A GTIN-14 that starts with one zero is normalized to GTIN-13.
|
|
1061
|
-
* - Otherwise, the GTIN is unchanged.
|
|
1062
|
-
*
|
|
1063
|
-
* @param gtin
|
|
1064
|
-
* GTIN.
|
|
1065
|
-
*
|
|
1066
|
-
* @returns
|
|
1067
|
-
* Normalized GTIN.
|
|
1068
|
-
*/
|
|
1069
|
-
static normalize(gtin: string): string;
|
|
1069
|
+
createGTIN14<TTransformerInput extends TransformerInput<number | bigint>>(indicatorDigit: string, valueOrValues: TTransformerInput, sparse?: boolean): TransformerOutput<TTransformerInput, string>;
|
|
1070
1070
|
}
|
|
1071
1071
|
declare const NonGTINNumericIdentificationKeyCreator_base: ts_mixer_dist_types_types_js.Class<any[], NonGTINNumericIdentificationKeyValidator & AbstractNumericIdentificationKeyCreator, typeof NonGTINNumericIdentificationKeyValidator & typeof AbstractNumericIdentificationKeyCreator>;
|
|
1072
1072
|
/**
|
|
@@ -1145,7 +1145,7 @@ declare class SerializableNumericIdentificationKeyCreator extends SerializableNu
|
|
|
1145
1145
|
* @returns
|
|
1146
1146
|
* Serialized identification keys.
|
|
1147
1147
|
*/
|
|
1148
|
-
createSerialized<
|
|
1148
|
+
createSerialized<TTransformerInput extends TransformerInput<string>>(value: number, serialComponentOrComponents: TTransformerInput, sparse?: boolean): TransformerOutput<TTransformerInput, string>;
|
|
1149
1149
|
/**
|
|
1150
1150
|
* Concatenate a base identification key with serial component(s).
|
|
1151
1151
|
*
|
|
@@ -1158,7 +1158,7 @@ declare class SerializableNumericIdentificationKeyCreator extends SerializableNu
|
|
|
1158
1158
|
* @returns
|
|
1159
1159
|
* Serialized identification key(s).
|
|
1160
1160
|
*/
|
|
1161
|
-
concatenate<
|
|
1161
|
+
concatenate<TTransformerInput extends TransformerInput<string>>(baseIdentificationKey: string, serialComponentOrComponents: TTransformerInput): TransformerOutput<TTransformerInput, string>;
|
|
1162
1162
|
}
|
|
1163
1163
|
declare const NonNumericIdentificationKeyCreator_base: ts_mixer_dist_types_types_js.Class<any[], NonNumericIdentificationKeyValidator & AbstractIdentificationKeyCreator, typeof NonNumericIdentificationKeyValidator & typeof AbstractIdentificationKeyCreator>;
|
|
1164
1164
|
/**
|
|
@@ -1202,7 +1202,7 @@ declare class NonNumericIdentificationKeyCreator extends NonNumericIdentificatio
|
|
|
1202
1202
|
* @returns
|
|
1203
1203
|
* Identification key(s).
|
|
1204
1204
|
*/
|
|
1205
|
-
create<
|
|
1205
|
+
create<TTransformerInput extends TransformerInput<string>>(referenceOrReferences: TTransformerInput): TransformerOutput<TTransformerInput, string>;
|
|
1206
1206
|
}
|
|
1207
1207
|
/**
|
|
1208
1208
|
* Prefix manager. This is the core class for identification key creation.
|