@aidc-toolkit/gs1 0.9.5 → 0.9.6-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 +115 -47
- package/dist/index.d.cts +57 -144
- package/dist/index.d.ts +57 -144
- package/dist/index.js +115 -47
- package/package.json +9 -10
- package/src/idkey.ts +120 -211
- package/test/check.test.ts +1 -1
- package/test/idkey.test.ts +4 -4
- 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/src/idkey.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CharacterSetCreator,
|
|
3
3
|
type CharacterSetValidation,
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
Exclusion,
|
|
5
|
+
IteratorProxy,
|
|
6
6
|
NUMERIC_CREATOR,
|
|
7
7
|
RegExpValidator,
|
|
8
8
|
type StringValidation,
|
|
9
|
-
type StringValidator
|
|
9
|
+
type StringValidator,
|
|
10
|
+
type TransformerInput,
|
|
11
|
+
type TransformerOutput
|
|
10
12
|
} from "@aidc-toolkit/utility";
|
|
11
13
|
import { Mixin } from "ts-mixer";
|
|
12
14
|
import { AI39_CREATOR, AI82_CREATOR } from "./character_set.js";
|
|
@@ -167,7 +169,7 @@ export interface IdentificationKeyValidator<V extends IdentificationKeyValidatio
|
|
|
167
169
|
/**
|
|
168
170
|
* Get the reference validator.
|
|
169
171
|
*/
|
|
170
|
-
get
|
|
172
|
+
get referenceCreator(): CharacterSetCreator;
|
|
171
173
|
|
|
172
174
|
/**
|
|
173
175
|
* Validate an identification key and throw an error if validation fails.
|
|
@@ -210,20 +212,20 @@ abstract class AbstractIdentificationKeyValidator<V extends IdentificationKeyVal
|
|
|
210
212
|
private readonly _referenceCharacterSet: CharacterSet;
|
|
211
213
|
|
|
212
214
|
/**
|
|
213
|
-
* Reference
|
|
215
|
+
* Reference creator.
|
|
214
216
|
*/
|
|
215
|
-
private readonly
|
|
217
|
+
private readonly _referenceCreator: CharacterSetCreator;
|
|
216
218
|
|
|
217
219
|
/**
|
|
218
|
-
* Get the character set
|
|
220
|
+
* Get the character set creator for a character set.
|
|
219
221
|
*
|
|
220
222
|
* @param characterSet
|
|
221
223
|
* Character set.
|
|
222
224
|
*
|
|
223
225
|
* @returns
|
|
224
|
-
* Character set
|
|
226
|
+
* Character set creator.
|
|
225
227
|
*/
|
|
226
|
-
protected static
|
|
228
|
+
protected static creatorFor(characterSet: CharacterSet): CharacterSetCreator {
|
|
227
229
|
return AbstractIdentificationKeyValidator.CHARACTER_SET_CREATORS[characterSet];
|
|
228
230
|
}
|
|
229
231
|
|
|
@@ -247,7 +249,7 @@ abstract class AbstractIdentificationKeyValidator<V extends IdentificationKeyVal
|
|
|
247
249
|
this._prefixType = prefixType;
|
|
248
250
|
this._length = length;
|
|
249
251
|
this._referenceCharacterSet = referenceCharacterSet;
|
|
250
|
-
this.
|
|
252
|
+
this._referenceCreator = AbstractIdentificationKeyValidator.creatorFor(referenceCharacterSet);
|
|
251
253
|
}
|
|
252
254
|
|
|
253
255
|
/**
|
|
@@ -281,8 +283,8 @@ abstract class AbstractIdentificationKeyValidator<V extends IdentificationKeyVal
|
|
|
281
283
|
/**
|
|
282
284
|
* @inheritDoc
|
|
283
285
|
*/
|
|
284
|
-
get
|
|
285
|
-
return this.
|
|
286
|
+
get referenceCreator(): CharacterSetCreator {
|
|
287
|
+
return this._referenceCreator;
|
|
286
288
|
}
|
|
287
289
|
|
|
288
290
|
/**
|
|
@@ -300,7 +302,7 @@ abstract class AbstractIdentificationKeyValidator<V extends IdentificationKeyVal
|
|
|
300
302
|
*/
|
|
301
303
|
protected padIdentificationKey(identificationKey: string, validation: IdentificationKeyValidation | undefined): string {
|
|
302
304
|
// Identification key is returned as is if position offset is undefined.
|
|
303
|
-
return validation?.positionOffset === undefined ? identificationKey : this.
|
|
305
|
+
return validation?.positionOffset === undefined ? identificationKey : this.referenceCreator.character(0).repeat(validation.positionOffset).concat(identificationKey);
|
|
304
306
|
}
|
|
305
307
|
|
|
306
308
|
/**
|
|
@@ -704,9 +706,9 @@ export class SerializableNumericIdentificationKeyValidator extends NonGTINNumeri
|
|
|
704
706
|
private readonly _serialComponentValidation: CharacterSetValidation;
|
|
705
707
|
|
|
706
708
|
/**
|
|
707
|
-
* Serial component
|
|
709
|
+
* Serial component creator.
|
|
708
710
|
*/
|
|
709
|
-
private readonly
|
|
711
|
+
private readonly _serialComponentCreator: CharacterSetCreator;
|
|
710
712
|
|
|
711
713
|
/**
|
|
712
714
|
* Constructor.
|
|
@@ -737,7 +739,7 @@ export class SerializableNumericIdentificationKeyValidator extends NonGTINNumeri
|
|
|
737
739
|
})
|
|
738
740
|
};
|
|
739
741
|
|
|
740
|
-
this.
|
|
742
|
+
this._serialComponentCreator = SerializableNumericIdentificationKeyValidator.creatorFor(serialComponentCharacterSet);
|
|
741
743
|
}
|
|
742
744
|
|
|
743
745
|
/**
|
|
@@ -762,10 +764,10 @@ export class SerializableNumericIdentificationKeyValidator extends NonGTINNumeri
|
|
|
762
764
|
}
|
|
763
765
|
|
|
764
766
|
/**
|
|
765
|
-
* Get the serial component
|
|
767
|
+
* Get the serial component creator.
|
|
766
768
|
*/
|
|
767
|
-
get
|
|
768
|
-
return this.
|
|
769
|
+
get serialComponentCreator(): CharacterSetCreator {
|
|
770
|
+
return this._serialComponentCreator;
|
|
769
771
|
}
|
|
770
772
|
|
|
771
773
|
/**
|
|
@@ -775,7 +777,7 @@ export class SerializableNumericIdentificationKeyValidator extends NonGTINNumeri
|
|
|
775
777
|
super.validate(identificationKey.substring(0, this.length), validation);
|
|
776
778
|
|
|
777
779
|
if (identificationKey.length > this.length) {
|
|
778
|
-
this.
|
|
780
|
+
this.serialComponentCreator.validate(identificationKey.substring(this.length), this._serialComponentValidation);
|
|
779
781
|
}
|
|
780
782
|
}
|
|
781
783
|
}
|
|
@@ -857,7 +859,7 @@ export class NonNumericIdentificationKeyValidator extends AbstractIdentification
|
|
|
857
859
|
super.validatePrefix(partialIdentificationKey, validation?.positionOffset);
|
|
858
860
|
|
|
859
861
|
if (!this.requiresCheckCharacterPair) {
|
|
860
|
-
this.
|
|
862
|
+
this.referenceCreator.validate(identificationKey, {
|
|
861
863
|
maximumLength: this.length,
|
|
862
864
|
positionOffset: validation?.positionOffset
|
|
863
865
|
});
|
|
@@ -959,11 +961,6 @@ export const GMN_VALIDATOR = new NonNumericIdentificationKeyValidator(Identifica
|
|
|
959
961
|
* Keys are created based on a prefix defined in a prefix manager to which the identification key creator is bound.
|
|
960
962
|
*/
|
|
961
963
|
export interface IdentificationKeyCreator extends IdentificationKeyValidator {
|
|
962
|
-
/**
|
|
963
|
-
* Get the reference creator.
|
|
964
|
-
*/
|
|
965
|
-
get referenceCreator(): CharacterSetCreator;
|
|
966
|
-
|
|
967
964
|
/**
|
|
968
965
|
* Get the prefix manager to which this identification key creator is bound.
|
|
969
966
|
*/
|
|
@@ -1024,14 +1021,7 @@ abstract class AbstractIdentificationKeyCreator implements IdentificationKeyCrea
|
|
|
1024
1021
|
|
|
1025
1022
|
abstract get referenceCharacterSet(): CharacterSet;
|
|
1026
1023
|
|
|
1027
|
-
abstract get
|
|
1028
|
-
|
|
1029
|
-
/**
|
|
1030
|
-
* @inheritDoc
|
|
1031
|
-
*/
|
|
1032
|
-
get referenceCreator(): CharacterSetCreator {
|
|
1033
|
-
return this.referenceValidator as CharacterSetCreator;
|
|
1034
|
-
}
|
|
1024
|
+
abstract get referenceCreator(): CharacterSetCreator;
|
|
1035
1025
|
|
|
1036
1026
|
/**
|
|
1037
1027
|
* @inheritDoc
|
|
@@ -1066,37 +1056,20 @@ export interface NumericIdentificationKeyCreator extends NumericIdentificationKe
|
|
|
1066
1056
|
*/
|
|
1067
1057
|
get capacity(): number;
|
|
1068
1058
|
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
(value: number | bigint, sparse?: boolean): string;
|
|
1084
|
-
|
|
1085
|
-
/**
|
|
1086
|
-
* Create identification keys with references based on numeric values. The values are converted to references of
|
|
1087
|
-
* the appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
1088
|
-
*
|
|
1089
|
-
* @param values
|
|
1090
|
-
* Numeric values.
|
|
1091
|
-
*
|
|
1092
|
-
* @param sparse
|
|
1093
|
-
* If true, the values are mapped to a sparse sequence resistant to discovery. Default is false.
|
|
1094
|
-
*
|
|
1095
|
-
* @returns
|
|
1096
|
-
* Identification keys.
|
|
1097
|
-
*/
|
|
1098
|
-
(values: Iterable<number | bigint>, sparse?: boolean): IterableIterator<string>;
|
|
1099
|
-
};
|
|
1059
|
+
/**
|
|
1060
|
+
* Create identification key(s) with reference(s) based on numeric value(s). The value(s) is/are converted to
|
|
1061
|
+
* references of the appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
1062
|
+
*
|
|
1063
|
+
* @param valueOrValues
|
|
1064
|
+
* Numeric value(s).
|
|
1065
|
+
*
|
|
1066
|
+
* @param sparse
|
|
1067
|
+
* If true, the value(s) are mapped to a sparse sequence resistant to discovery. Default is false.
|
|
1068
|
+
*
|
|
1069
|
+
* @returns
|
|
1070
|
+
* Identification key(s).
|
|
1071
|
+
*/
|
|
1072
|
+
create: <T extends TransformerInput<number | bigint>>(valueOrValues: T, sparse?: boolean) => TransformerOutput<T, string>;
|
|
1100
1073
|
|
|
1101
1074
|
/**
|
|
1102
1075
|
* Create all identification keys for the prefix from `0` to `capacity - 1`.
|
|
@@ -1181,15 +1154,7 @@ abstract class AbstractNumericIdentificationKeyCreator extends AbstractIdentific
|
|
|
1181
1154
|
/**
|
|
1182
1155
|
* @inheritDoc
|
|
1183
1156
|
*/
|
|
1184
|
-
create
|
|
1185
|
-
|
|
1186
|
-
/**
|
|
1187
|
-
* @inheritDoc
|
|
1188
|
-
*/
|
|
1189
|
-
create(values: Iterable<number | bigint>, sparse?: boolean): IterableIterator<string>;
|
|
1190
|
-
|
|
1191
|
-
// eslint-disable-next-line jsdoc/require-jsdoc -- Implementation of overloaded signatures.
|
|
1192
|
-
create(valueOrValues: number | bigint | Iterable<number | bigint>, sparse = false): string | IterableIterator<string> {
|
|
1157
|
+
create<T extends TransformerInput<number | bigint>>(valueOrValues: T, sparse = false): TransformerOutput<T, string> {
|
|
1193
1158
|
return NUMERIC_CREATOR.create(this.referenceLength, valueOrValues, Exclusion.None, sparse ? this.tweak : undefined, reference => this.buildIdentificationKey(reference));
|
|
1194
1159
|
}
|
|
1195
1160
|
|
|
@@ -1309,45 +1274,22 @@ export class GTINCreator extends Mixin(GTINValidator, AbstractNumericIdentificat
|
|
|
1309
1274
|
}
|
|
1310
1275
|
|
|
1311
1276
|
/**
|
|
1312
|
-
* Create
|
|
1313
|
-
* reference of the appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
1314
|
-
*
|
|
1315
|
-
* @param indicatorDigit
|
|
1316
|
-
* Indicator digit.
|
|
1317
|
-
*
|
|
1318
|
-
* @param value
|
|
1319
|
-
* Numeric value of the reference.
|
|
1320
|
-
*
|
|
1321
|
-
* @param sparse
|
|
1322
|
-
* If true, the value is mapped to a sparse sequence resistant to discovery. Default is false.
|
|
1323
|
-
*
|
|
1324
|
-
* @returns
|
|
1325
|
-
* GTIN-14.
|
|
1326
|
-
*/
|
|
1327
|
-
createGTIN14(indicatorDigit: string, value: number | bigint, sparse?: boolean): string;
|
|
1328
|
-
|
|
1329
|
-
/**
|
|
1330
|
-
* Create multiple GTIN-14s with an indicator digit and references based on numeric values. The values are converted
|
|
1331
|
-
* to references of the appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
1332
|
-
*
|
|
1333
|
-
* The implementation uses {@link CharacterSetCreator.create}, so the values are created only as needed.
|
|
1277
|
+
* Create GTIN-14(s) with an indicator digit and reference(s) based on numeric value(s). The value(s) is/are
|
|
1278
|
+
* converted to reference(s) of the appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
1334
1279
|
*
|
|
1335
1280
|
* @param indicatorDigit
|
|
1336
1281
|
* Indicator digit.
|
|
1337
1282
|
*
|
|
1338
|
-
* @param
|
|
1339
|
-
*
|
|
1283
|
+
* @param valueOrValues
|
|
1284
|
+
* Numeric value(s).
|
|
1340
1285
|
*
|
|
1341
1286
|
* @param sparse
|
|
1342
|
-
* If true, the
|
|
1287
|
+
* If true, the value(s) is/are mapped to a sparse sequence resistant to discovery. Default is false.
|
|
1343
1288
|
*
|
|
1344
1289
|
* @returns
|
|
1345
|
-
*
|
|
1290
|
+
* GTIN-14(s).
|
|
1346
1291
|
*/
|
|
1347
|
-
createGTIN14(indicatorDigit: string,
|
|
1348
|
-
|
|
1349
|
-
// eslint-disable-next-line jsdoc/require-jsdoc -- Implementation of overloaded signatures.
|
|
1350
|
-
createGTIN14(indicatorDigit: string, valueOrValues: number | bigint | Iterable<number | bigint>, sparse = false): string | IterableIterator<string> {
|
|
1292
|
+
createGTIN14<T extends TransformerInput<number | bigint>>(indicatorDigit: string, valueOrValues: T, sparse = false): TransformerOutput<T, string> {
|
|
1351
1293
|
NUMERIC_CREATOR.validate(indicatorDigit, GTINCreator.REQUIRED_INDICATOR_DIGIT_VALIDATION);
|
|
1352
1294
|
|
|
1353
1295
|
return NUMERIC_CREATOR.create(GTINType.GTIN13 - this.prefixManager.gs1CompanyPrefix.length - 1, valueOrValues, Exclusion.None, sparse ? this.tweak : undefined, (reference) => {
|
|
@@ -1569,82 +1511,57 @@ export class SerializableNumericIdentificationKeyCreator extends Mixin(Serializa
|
|
|
1569
1511
|
}
|
|
1570
1512
|
|
|
1571
1513
|
/**
|
|
1572
|
-
*
|
|
1573
|
-
*/
|
|
1574
|
-
get serialComponentCreator(): CharacterSetCreator {
|
|
1575
|
-
return this.serialComponentValidator as CharacterSetCreator;
|
|
1576
|
-
}
|
|
1577
|
-
|
|
1578
|
-
/**
|
|
1579
|
-
* Concatenate a validated base identification key with a serial component.
|
|
1514
|
+
* Concatenate a validated base identification key with serial component(s).
|
|
1580
1515
|
*
|
|
1581
1516
|
* @param baseIdentificationKey
|
|
1582
1517
|
* Base identification key.
|
|
1583
1518
|
*
|
|
1584
|
-
* @param
|
|
1585
|
-
* Serial component.
|
|
1519
|
+
* @param serialComponentOrComponents
|
|
1520
|
+
* Serial component(s).
|
|
1586
1521
|
*
|
|
1587
1522
|
* @returns
|
|
1588
|
-
* Serialized identification key.
|
|
1523
|
+
* Serialized identification key(s).
|
|
1589
1524
|
*/
|
|
1590
|
-
private concatenateValidated(baseIdentificationKey: string,
|
|
1525
|
+
private concatenateValidated<T extends TransformerInput<string>>(baseIdentificationKey: string, serialComponentOrComponents: T): TransformerOutput<T, string> {
|
|
1526
|
+
// TODO Refactor type when https://github.com/microsoft/TypeScript/pull/56941 released.
|
|
1527
|
+
let result: string | IterableIterator<string>;
|
|
1591
1528
|
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
*
|
|
1595
|
-
* @param baseIdentificationKey
|
|
1596
|
-
* Base identification key.
|
|
1597
|
-
*
|
|
1598
|
-
* @param serialComponents
|
|
1599
|
-
* Serial components.
|
|
1600
|
-
*
|
|
1601
|
-
* @returns
|
|
1602
|
-
* Serialized identification keys.
|
|
1603
|
-
*/
|
|
1604
|
-
private concatenateValidated(baseIdentificationKey: string, serialComponents: Iterable<string>): IterableIterator<string>;
|
|
1529
|
+
const serialComponentCreator = this.serialComponentCreator;
|
|
1530
|
+
const serialComponentValidation = this.serialComponentValidation;
|
|
1605
1531
|
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1532
|
+
/**
|
|
1533
|
+
* Validate a serial component and concatenate it to the base identification key.
|
|
1534
|
+
*
|
|
1535
|
+
* @param serialComponent
|
|
1536
|
+
* Serial component.
|
|
1537
|
+
*
|
|
1538
|
+
* @returns
|
|
1539
|
+
* Serialized identification key.
|
|
1540
|
+
*/
|
|
1541
|
+
function validateAndConcatenate(serialComponent: string): string {
|
|
1542
|
+
serialComponentCreator.validate(serialComponent, serialComponentValidation);
|
|
1609
1543
|
|
|
1610
|
-
|
|
1611
|
-
|
|
1544
|
+
return baseIdentificationKey + serialComponent;
|
|
1545
|
+
}
|
|
1612
1546
|
|
|
1613
|
-
|
|
1547
|
+
if (typeof serialComponentOrComponents !== "object") {
|
|
1548
|
+
result = validateAndConcatenate(serialComponentOrComponents);
|
|
1614
1549
|
} else {
|
|
1615
|
-
result = IteratorProxy.from(
|
|
1550
|
+
result = IteratorProxy.from(serialComponentOrComponents).map(validateAndConcatenate);
|
|
1616
1551
|
}
|
|
1617
1552
|
|
|
1618
|
-
return result
|
|
1553
|
+
return result as TransformerOutput<T, string>;
|
|
1619
1554
|
}
|
|
1620
1555
|
|
|
1621
1556
|
/**
|
|
1622
|
-
* Create
|
|
1623
|
-
* value is converted to a reference of the appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
1624
|
-
*
|
|
1625
|
-
* @param value
|
|
1626
|
-
* Numeric value of the references.
|
|
1627
|
-
*
|
|
1628
|
-
* @param serialComponent
|
|
1629
|
-
* Serial component.
|
|
1630
|
-
*
|
|
1631
|
-
* @param sparse
|
|
1632
|
-
* If true, the value is mapped to a sparse sequence resistant to discovery. Default is false.
|
|
1633
|
-
*
|
|
1634
|
-
* @returns
|
|
1635
|
-
* Serialized identification key.
|
|
1636
|
-
*/
|
|
1637
|
-
createSerialized(value: number, serialComponent: string, sparse?: boolean): string;
|
|
1638
|
-
|
|
1639
|
-
/**
|
|
1640
|
-
* Create multiple serialized identification keys with a reference based on a numeric value and multiple serial
|
|
1641
|
-
* components. The value is converted to a reference of the appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
1557
|
+
* Create serialized identification key(s) with a reference based on a numeric value concatenated with serial
|
|
1558
|
+
* component(s). The value is converted to a reference of the appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
1642
1559
|
*
|
|
1643
1560
|
* @param value
|
|
1644
|
-
* Numeric value.
|
|
1561
|
+
* Numeric value of the reference.
|
|
1645
1562
|
*
|
|
1646
|
-
* @param
|
|
1647
|
-
* Serial
|
|
1563
|
+
* @param serialComponentOrComponents
|
|
1564
|
+
* Serial component(s).
|
|
1648
1565
|
*
|
|
1649
1566
|
* @param sparse
|
|
1650
1567
|
* If true, the value is mapped to a sparse sequence resistant to discovery. Default is false.
|
|
@@ -1652,46 +1569,26 @@ export class SerializableNumericIdentificationKeyCreator extends Mixin(Serializa
|
|
|
1652
1569
|
* @returns
|
|
1653
1570
|
* Serialized identification keys.
|
|
1654
1571
|
*/
|
|
1655
|
-
createSerialized(value: number,
|
|
1656
|
-
|
|
1657
|
-
// eslint-disable-next-line jsdoc/require-jsdoc -- Implementation of overloaded signatures.
|
|
1658
|
-
createSerialized(value: number, serialComponent: string | Iterable<string>, sparse = false): string | IterableIterator<string> {
|
|
1659
|
-
return this.concatenateValidated(this.create(value, sparse), serialComponent);
|
|
1572
|
+
createSerialized<T extends TransformerInput<string>>(value: number, serialComponentOrComponents: T, sparse?: boolean): TransformerOutput<T, string> {
|
|
1573
|
+
return this.concatenateValidated(this.create(value, sparse), serialComponentOrComponents);
|
|
1660
1574
|
}
|
|
1661
1575
|
|
|
1662
1576
|
/**
|
|
1663
|
-
* Concatenate a base identification key with
|
|
1577
|
+
* Concatenate a base identification key with serial component(s).
|
|
1664
1578
|
*
|
|
1665
1579
|
* @param baseIdentificationKey
|
|
1666
1580
|
* Base identification key.
|
|
1667
1581
|
*
|
|
1668
|
-
* @param
|
|
1669
|
-
* Serial component.
|
|
1582
|
+
* @param serialComponentOrComponents
|
|
1583
|
+
* Serial component(s).
|
|
1670
1584
|
*
|
|
1671
1585
|
* @returns
|
|
1672
|
-
* Serialized identification key.
|
|
1586
|
+
* Serialized identification key(s).
|
|
1673
1587
|
*/
|
|
1674
|
-
concatenate(baseIdentificationKey: string,
|
|
1675
|
-
|
|
1676
|
-
/**
|
|
1677
|
-
* Concatenate a base identification key with multiple serial components.
|
|
1678
|
-
*
|
|
1679
|
-
* @param baseIdentificationKey
|
|
1680
|
-
* Base identification key.
|
|
1681
|
-
*
|
|
1682
|
-
* @param serialComponents
|
|
1683
|
-
* Serial components.
|
|
1684
|
-
*
|
|
1685
|
-
* @returns
|
|
1686
|
-
* Serialized identification keys.
|
|
1687
|
-
*/
|
|
1688
|
-
concatenate(baseIdentificationKey: string, serialComponents: Iterable<string>): IterableIterator<string>;
|
|
1689
|
-
|
|
1690
|
-
// eslint-disable-next-line jsdoc/require-jsdoc -- Implementation of overloaded signatures.
|
|
1691
|
-
concatenate(baseIdentificationKey: string, serialComponent: string | Iterable<string>): string | IterableIterator<string> {
|
|
1588
|
+
concatenate<T extends TransformerInput<string>>(baseIdentificationKey: string, serialComponentOrComponents: T): TransformerOutput<T, string> {
|
|
1692
1589
|
this.validate(baseIdentificationKey);
|
|
1693
1590
|
|
|
1694
|
-
return this.concatenateValidated(baseIdentificationKey,
|
|
1591
|
+
return this.concatenateValidated(baseIdentificationKey, serialComponentOrComponents);
|
|
1695
1592
|
}
|
|
1696
1593
|
}
|
|
1697
1594
|
|
|
@@ -1739,42 +1636,54 @@ export class NonNumericIdentificationKeyCreator extends Mixin(NonNumericIdentifi
|
|
|
1739
1636
|
}
|
|
1740
1637
|
|
|
1741
1638
|
/**
|
|
1742
|
-
*
|
|
1743
|
-
*
|
|
1744
|
-
* @param reference
|
|
1745
|
-
* Reference.
|
|
1746
|
-
*
|
|
1747
|
-
* @returns
|
|
1748
|
-
* Identification key.
|
|
1639
|
+
* Get the reference validation parameters.
|
|
1749
1640
|
*/
|
|
1750
|
-
|
|
1641
|
+
protected get referenceValidation(): CharacterSetValidation {
|
|
1642
|
+
return this._referenceValidation;
|
|
1643
|
+
}
|
|
1751
1644
|
|
|
1752
1645
|
/**
|
|
1753
|
-
* Create
|
|
1646
|
+
* Create identification key(s) with reference(s).
|
|
1754
1647
|
*
|
|
1755
|
-
* @param
|
|
1756
|
-
*
|
|
1648
|
+
* @param referenceOrReferences
|
|
1649
|
+
* Reference(s).
|
|
1757
1650
|
*
|
|
1758
1651
|
* @returns
|
|
1759
|
-
* Identification
|
|
1652
|
+
* Identification key(s).
|
|
1760
1653
|
*/
|
|
1761
|
-
create(
|
|
1762
|
-
|
|
1763
|
-
// eslint-disable-next-line jsdoc/require-jsdoc -- Implementation of overloaded signatures.
|
|
1764
|
-
create(referenceOrReferences: string | Iterable<string>): string | IterableIterator<string> {
|
|
1654
|
+
create<T extends TransformerInput<string>>(referenceOrReferences: T): TransformerOutput<T, string> {
|
|
1655
|
+
// TODO Refactor type when https://github.com/microsoft/TypeScript/pull/56941 released.
|
|
1765
1656
|
let result: string | IterableIterator<string>;
|
|
1766
1657
|
|
|
1767
|
-
|
|
1768
|
-
|
|
1658
|
+
const referenceCreator = this.referenceCreator;
|
|
1659
|
+
const referenceValidation = this.referenceValidation;
|
|
1660
|
+
const prefix = this.prefix;
|
|
1661
|
+
const requiresCheckCharacterPair = this.requiresCheckCharacterPair;
|
|
1769
1662
|
|
|
1770
|
-
|
|
1663
|
+
/**
|
|
1664
|
+
* Validate a reference and create an identification key.
|
|
1665
|
+
*
|
|
1666
|
+
* @param reference
|
|
1667
|
+
* Reference.
|
|
1668
|
+
*
|
|
1669
|
+
* @returns
|
|
1670
|
+
* Identification key.
|
|
1671
|
+
*/
|
|
1672
|
+
function validateAndCreate(reference: string): string {
|
|
1673
|
+
referenceCreator.validate(reference, referenceValidation);
|
|
1674
|
+
|
|
1675
|
+
const partialIdentificationKey = prefix + reference;
|
|
1676
|
+
|
|
1677
|
+
return requiresCheckCharacterPair ? partialIdentificationKey + checkCharacterPair(partialIdentificationKey) : partialIdentificationKey;
|
|
1678
|
+
}
|
|
1771
1679
|
|
|
1772
|
-
|
|
1680
|
+
if (typeof referenceOrReferences !== "object") {
|
|
1681
|
+
result = validateAndCreate(referenceOrReferences);
|
|
1773
1682
|
} else {
|
|
1774
|
-
result = IteratorProxy.from(referenceOrReferences).map(
|
|
1683
|
+
result = IteratorProxy.from(referenceOrReferences).map(validateAndCreate);
|
|
1775
1684
|
}
|
|
1776
1685
|
|
|
1777
|
-
return result
|
|
1686
|
+
return result as TransformerOutput<T, string>;
|
|
1778
1687
|
}
|
|
1779
1688
|
}
|
|
1780
1689
|
|
|
@@ -2032,7 +1941,7 @@ export class PrefixManager {
|
|
|
2032
1941
|
|
|
2033
1942
|
// Creator tweak factor is defined for numeric identification keys only.
|
|
2034
1943
|
if (creatorTweakFactor !== undefined) {
|
|
2035
|
-
// Explicit cast without testing is necessary as "instanceof" doesn't work for mixin types.
|
|
1944
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Explicit cast without testing is necessary as "instanceof" doesn't work for mixin types.
|
|
2036
1945
|
(creator as AbstractNumericIdentificationKeyCreator).tweak = this.tweakFactor * creatorTweakFactor;
|
|
2037
1946
|
}
|
|
2038
1947
|
}
|
package/test/check.test.ts
CHANGED
package/test/idkey.test.ts
CHANGED
|
@@ -41,7 +41,7 @@ import {
|
|
|
41
41
|
SSCC_VALIDATOR
|
|
42
42
|
} from "../src/index.js";
|
|
43
43
|
|
|
44
|
-
await i18nInit(I18NEnvironment.CLI
|
|
44
|
+
await i18nInit(I18NEnvironment.CLI);
|
|
45
45
|
|
|
46
46
|
function creatorFor(characterSet: CharacterSet): CharacterSetCreator {
|
|
47
47
|
let creator: CharacterSetCreator;
|
|
@@ -74,7 +74,7 @@ function validateNumericIdentificationKeyValidator(validator: NumericIdentificat
|
|
|
74
74
|
|
|
75
75
|
expect(validator.leaderType).toBe(leaderType);
|
|
76
76
|
expect(validator.referenceCharacterSet).toBe(CharacterSet.Numeric);
|
|
77
|
-
expect(validator.
|
|
77
|
+
expect(validator.referenceCreator).toBe(NUMERIC_CREATOR);
|
|
78
78
|
|
|
79
79
|
if (isCreator) {
|
|
80
80
|
expect((validator as NumericIdentificationKeyCreator).referenceCreator).toBe(NUMERIC_CREATOR);
|
|
@@ -117,7 +117,7 @@ function validateSerializableNumericIdentificationKeyValidator(validator: Serial
|
|
|
117
117
|
|
|
118
118
|
expect(validator.serialComponentLength).toBe(serialLength);
|
|
119
119
|
expect(validator.serialComponentCharacterSet).toBe(serialCharacterSet);
|
|
120
|
-
expect(validator.
|
|
120
|
+
expect(validator.serialComponentCreator).toBe(serialCreator);
|
|
121
121
|
|
|
122
122
|
if (isCreator) {
|
|
123
123
|
expect((validator as SerializableNumericIdentificationKeyCreator).serialComponentCreator).toBe(serialCreator);
|
|
@@ -130,7 +130,7 @@ function validateNonNumericIdentificationKeyValidator(validator: NonNumericIdent
|
|
|
130
130
|
const referenceCreator = creatorFor(referenceCharacterSet);
|
|
131
131
|
|
|
132
132
|
expect(validator.referenceCharacterSet).toBe(referenceCharacterSet);
|
|
133
|
-
expect(validator.
|
|
133
|
+
expect(validator.referenceCreator).toBe(referenceCreator);
|
|
134
134
|
expect(validator.requiresCheckCharacterPair).toBe(requiresCheckCharacterPair);
|
|
135
135
|
|
|
136
136
|
if (isCreator) {
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Bug report
|
|
3
|
-
about: Create a report to help us improve
|
|
4
|
-
title: ''
|
|
5
|
-
labels: ''
|
|
6
|
-
assignees: ''
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
**Describe the bug**
|
|
11
|
-
A clear and concise description of what the bug is.
|
|
12
|
-
|
|
13
|
-
**To Reproduce**
|
|
14
|
-
Steps to reproduce the behavior:
|
|
15
|
-
1. Go to '...'
|
|
16
|
-
2. Click on '....'
|
|
17
|
-
3. Scroll down to '....'
|
|
18
|
-
4. See error
|
|
19
|
-
|
|
20
|
-
**Expected behavior**
|
|
21
|
-
A clear and concise description of what you expected to happen.
|
|
22
|
-
|
|
23
|
-
**Screenshots**
|
|
24
|
-
If applicable, add screenshots to help explain your problem.
|
|
25
|
-
|
|
26
|
-
**Platform**
|
|
27
|
-
- OS: [e.g. Windows, iOS]
|
|
28
|
-
- Browser [e.g. chrome, safari]
|
|
29
|
-
- Browser Version [e.g. 22]
|
|
30
|
-
|
|
31
|
-
**Additional context**
|
|
32
|
-
Add any other context about the problem here.
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Feature request
|
|
3
|
-
about: Suggest an idea for this project
|
|
4
|
-
title: ''
|
|
5
|
-
labels: ''
|
|
6
|
-
assignees: ''
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
**Is your feature request related to a problem? Please describe.**
|
|
11
|
-
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
|
12
|
-
|
|
13
|
-
**Describe the solution you'd like**
|
|
14
|
-
A clear and concise description of what you want to happen.
|
|
15
|
-
|
|
16
|
-
**Describe alternatives you've considered**
|
|
17
|
-
A clear and concise description of any alternative solutions or features you've considered.
|
|
18
|
-
|
|
19
|
-
**Additional context**
|
|
20
|
-
Add any other context or screenshots about the feature request here.
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
name: Build and publish
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
release:
|
|
5
|
-
types:
|
|
6
|
-
- published
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
build-and-publish:
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
|
|
12
|
-
steps:
|
|
13
|
-
- name: Build and publish gs1
|
|
14
|
-
uses: aidc-toolkit/dev/.github/actions/build-publish@main
|
|
15
|
-
with:
|
|
16
|
-
project: gs1
|
|
17
|
-
node_version: ${{ vars.NODE_VERSION }}
|
|
18
|
-
node_auth_token: ${{ secrets.NODE_AUTH_TOKEN }}
|
|
19
|
-
terminal_pre_build: ${{ vars.TERMINAL_PRE_BUILD }}
|
|
20
|
-
terminal_post_build: ${{ vars.TERMINAL_POST_BUILD }}
|
package/.idea/gs1.iml
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="JAVA_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
4
|
-
<exclude-output />
|
|
5
|
-
<content url="file://$MODULE_DIR$" />
|
|
6
|
-
<orderEntry type="inheritedJdk" />
|
|
7
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
8
|
-
</component>
|
|
9
|
-
</module>
|