@aidc-toolkit/gs1 1.0.46-beta → 1.0.47-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-numeric-identifier-creator.d.ts.map +1 -1
- package/dist/abstract-numeric-identifier-creator.js +3 -5
- package/dist/abstract-numeric-identifier-creator.js.map +1 -1
- package/dist/gtin-creator.d.ts +23 -10
- package/dist/gtin-creator.d.ts.map +1 -1
- package/dist/gtin-creator.js +3 -21
- package/dist/gtin-creator.js.map +1 -1
- package/dist/non-numeric-identifier-creator.d.ts +15 -8
- package/dist/non-numeric-identifier-creator.d.ts.map +1 -1
- package/dist/non-numeric-identifier-creator.js +4 -22
- package/dist/non-numeric-identifier-creator.js.map +1 -1
- package/dist/numeric-identifier-creator.d.ts +30 -18
- package/dist/numeric-identifier-creator.d.ts.map +1 -1
- package/dist/serializable-numeric-identifier-creator.d.ts +38 -15
- package/dist/serializable-numeric-identifier-creator.d.ts.map +1 -1
- package/dist/serializable-numeric-identifier-creator.js +6 -59
- package/dist/serializable-numeric-identifier-creator.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
- package/src/abstract-numeric-identifier-creator.ts +11 -9
- package/src/gtin-creator.ts +29 -17
- package/src/non-numeric-identifier-creator.ts +21 -23
- package/src/numeric-identifier-creator.ts +32 -18
- package/src/serializable-numeric-identifier-creator.ts +70 -32
- package/src/version.ts +1 -1
- package/tsconfig-src.tsbuildinfo +1 -1
package/src/gtin-creator.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type CharacterSetValidation,
|
|
3
|
-
Exclusions,
|
|
4
|
-
NUMERIC_CREATOR,
|
|
5
|
-
type TransformerInput,
|
|
6
|
-
type TransformerOutput
|
|
7
|
-
} from "@aidc-toolkit/utility";
|
|
1
|
+
import { type CharacterSetValidation, Exclusions, NUMERIC_CREATOR } from "@aidc-toolkit/utility";
|
|
8
2
|
import { MixinAbstractNumericIdentifierCreator } from "./abstract-numeric-identifier-creator.js";
|
|
9
3
|
import { checkDigit } from "./check.js";
|
|
10
4
|
import { type GTINBaseLength, GTINLengths } from "./gtin-length.js";
|
|
@@ -49,28 +43,46 @@ export class GTINCreator extends MixinAbstractNumericIdentifierCreator<
|
|
|
49
43
|
}
|
|
50
44
|
|
|
51
45
|
/**
|
|
52
|
-
* Create GTIN-14
|
|
53
|
-
*
|
|
46
|
+
* Create GTIN-14 with an indicator digit and reference based on a numeric value. The value is converted to a
|
|
47
|
+
* reference of the appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
54
48
|
*
|
|
55
|
-
* @
|
|
56
|
-
*
|
|
49
|
+
* @param indicatorDigit
|
|
50
|
+
* Indicator digit.
|
|
51
|
+
*
|
|
52
|
+
* @param value
|
|
53
|
+
* Numeric value.
|
|
54
|
+
*
|
|
55
|
+
* @param sparse
|
|
56
|
+
* If true, the value is mapped to a sparse sequence resistant to discovery.
|
|
57
|
+
*
|
|
58
|
+
* @returns
|
|
59
|
+
* GTIN-14.
|
|
60
|
+
*/
|
|
61
|
+
createGTIN14(indicatorDigit: string, value: number | bigint, sparse?: boolean): string;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Create GTIN-14s with an indicator digit and references based on numeric values. The values are converted to
|
|
65
|
+
* references of the appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
57
66
|
*
|
|
58
67
|
* @param indicatorDigit
|
|
59
68
|
* Indicator digit.
|
|
60
69
|
*
|
|
61
|
-
* @param
|
|
62
|
-
* Numeric
|
|
70
|
+
* @param values
|
|
71
|
+
* Numeric values.
|
|
63
72
|
*
|
|
64
73
|
* @param sparse
|
|
65
|
-
* If true, the
|
|
74
|
+
* If true, the values are mapped to a sparse sequence resistant to discovery.
|
|
66
75
|
*
|
|
67
76
|
* @returns
|
|
68
|
-
* GTIN-
|
|
77
|
+
* GTIN-14s.
|
|
69
78
|
*/
|
|
70
|
-
createGTIN14
|
|
79
|
+
createGTIN14(indicatorDigit: string, values: Iterable<number | bigint>, sparse?: boolean): Iterable<string>;
|
|
80
|
+
|
|
81
|
+
// eslint-disable-next-line jsdoc/require-jsdoc -- Implementation of overloaded signatures.
|
|
82
|
+
createGTIN14(indicatorDigit: string, valueOrValues: number | bigint | Iterable<number | bigint>, sparse?: boolean): string | Iterable<string> {
|
|
71
83
|
NUMERIC_CREATOR.validate(indicatorDigit, GTINCreator.#REQUIRED_INDICATOR_DIGIT_VALIDATION);
|
|
72
84
|
|
|
73
|
-
return NUMERIC_CREATOR.create(GTINLengths.GTIN13 - this.prefixProvider.gs1CompanyPrefix.length - 1, valueOrValues, Exclusions.None, sparse ? this.tweak : undefined, (reference) => {
|
|
85
|
+
return NUMERIC_CREATOR.create(GTINLengths.GTIN13 - this.prefixProvider.gs1CompanyPrefix.length - 1, valueOrValues, Exclusions.None, sparse === true ? this.tweak : undefined, (reference) => {
|
|
74
86
|
const partialIdentifier = indicatorDigit + this.prefixProvider.gs1CompanyPrefix + reference;
|
|
75
87
|
|
|
76
88
|
return partialIdentifier + checkDigit(partialIdentifier);
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type CharacterSetValidation,
|
|
3
|
-
mapIterable,
|
|
4
|
-
type TransformerInput,
|
|
5
|
-
type TransformerOutput
|
|
6
|
-
} from "@aidc-toolkit/utility";
|
|
1
|
+
import { type CharacterSetValidation, mapIterable } from "@aidc-toolkit/utility";
|
|
7
2
|
import { MixinAbstractIdentifierCreator } from "./abstract-identifier-creator.js";
|
|
8
3
|
import { checkCharacterPair } from "./check.js";
|
|
9
4
|
import { IdentifierDescriptors } from "./identifier-descriptors.js";
|
|
@@ -55,21 +50,29 @@ export class NonNumericIdentifierCreator extends MixinAbstractIdentifierCreator<
|
|
|
55
50
|
}
|
|
56
51
|
|
|
57
52
|
/**
|
|
58
|
-
* Create identifier
|
|
53
|
+
* Create an identifier with a reference.
|
|
54
|
+
*
|
|
55
|
+
* @param reference
|
|
56
|
+
* Reference.
|
|
59
57
|
*
|
|
60
|
-
* @
|
|
61
|
-
*
|
|
58
|
+
* @returns
|
|
59
|
+
* Identifier.
|
|
60
|
+
*/
|
|
61
|
+
create(reference: string): string;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Create identifiers with references.
|
|
62
65
|
*
|
|
63
|
-
* @param
|
|
64
|
-
*
|
|
66
|
+
* @param references
|
|
67
|
+
* References.
|
|
65
68
|
*
|
|
66
69
|
* @returns
|
|
67
|
-
*
|
|
70
|
+
* Identifiers.
|
|
68
71
|
*/
|
|
69
|
-
create
|
|
70
|
-
// TODO Refactor type when https://github.com/microsoft/TypeScript/pull/56941 released.
|
|
71
|
-
let result: string | Iterable<string>;
|
|
72
|
+
create(references: Iterable<string>): Iterable<string>;
|
|
72
73
|
|
|
74
|
+
// eslint-disable-next-line jsdoc/require-jsdoc -- Implementation of overloaded signatures.
|
|
75
|
+
create(referenceOrReferences: string | Iterable<string>): string | Iterable<string> {
|
|
73
76
|
const referenceCreator = this.referenceCreator;
|
|
74
77
|
const referenceValidation = this.referenceValidation;
|
|
75
78
|
const prefix = this.prefix;
|
|
@@ -92,13 +95,8 @@ export class NonNumericIdentifierCreator extends MixinAbstractIdentifierCreator<
|
|
|
92
95
|
return requiresCheckCharacterPair ? partialIdentifier + checkCharacterPair(partialIdentifier) : partialIdentifier;
|
|
93
96
|
}
|
|
94
97
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
result = mapIterable(referenceOrReferences, validateAndCreate);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type determination is handled above.
|
|
102
|
-
return result as TransformerOutput<TTransformerInput, string>;
|
|
98
|
+
return typeof referenceOrReferences !== "object" ?
|
|
99
|
+
validateAndCreate(referenceOrReferences) :
|
|
100
|
+
mapIterable(referenceOrReferences, validateAndCreate);
|
|
103
101
|
}
|
|
104
102
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Used in JSDoc.
|
|
2
|
-
import { NUMERIC_CREATOR
|
|
2
|
+
import { NUMERIC_CREATOR } from "@aidc-toolkit/utility";
|
|
3
3
|
import type { IdentifierCreator } from "./identifier-creator.js";
|
|
4
4
|
import type { NumericIdentifierType } from "./numeric-identifier-type.js";
|
|
5
5
|
import type { NumericIdentifierValidation, NumericIdentifierValidator } from "./numeric-identifier-validator.js";
|
|
@@ -26,23 +26,37 @@ export interface NumericIdentifierCreator<TNumericIdentifierType extends Numeric
|
|
|
26
26
|
*/
|
|
27
27
|
set tweak(value: bigint);
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
29
|
+
create: {
|
|
30
|
+
/**
|
|
31
|
+
* Create an identifier with a reference based on a numeric value. The value is converted to a reference of the
|
|
32
|
+
* appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
33
|
+
*
|
|
34
|
+
* @param value
|
|
35
|
+
* Numeric value.
|
|
36
|
+
*
|
|
37
|
+
* @param sparse
|
|
38
|
+
* If true, the value is mapped to a sparse sequence resistant to discovery.
|
|
39
|
+
*
|
|
40
|
+
* @returns
|
|
41
|
+
* Identifier.
|
|
42
|
+
*/
|
|
43
|
+
(value: number | bigint, sparse?: boolean): string;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Create identifiers with references based on numeric values. The values are converted to references of the
|
|
47
|
+
* appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
48
|
+
*
|
|
49
|
+
* @param values
|
|
50
|
+
* Numeric values.
|
|
51
|
+
*
|
|
52
|
+
* @param sparse
|
|
53
|
+
* If true, the values are mapped to a sparse sequence resistant to discovery.
|
|
54
|
+
*
|
|
55
|
+
* @returns
|
|
56
|
+
* Identifiers.
|
|
57
|
+
*/
|
|
58
|
+
(values: Iterable<number | bigint>, sparse?: boolean): Iterable<string>;
|
|
59
|
+
};
|
|
46
60
|
|
|
47
61
|
/**
|
|
48
62
|
* Create all identifiers for the prefix from `0` to `capacity - 1`.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Used in JSDoc.
|
|
2
|
-
import { mapIterable, NUMERIC_CREATOR
|
|
2
|
+
import { mapIterable, NUMERIC_CREATOR } from "@aidc-toolkit/utility";
|
|
3
3
|
import { MixinAbstractNonGTINNumericIdentifierCreator } from "./abstract-non-gtin-numeric-identifier-creator.js";
|
|
4
4
|
import type { SerializableNumericIdentifierType } from "./serializable-numeric-identifier-type.js";
|
|
5
5
|
import { SerializableNumericIdentifierValidator } from "./serializable-numeric-identifier-validator.js";
|
|
@@ -11,24 +11,35 @@ export class SerializableNumericIdentifierCreator extends MixinAbstractNonGTINNu
|
|
|
11
11
|
SerializableNumericIdentifierType
|
|
12
12
|
>(SerializableNumericIdentifierValidator) {
|
|
13
13
|
/**
|
|
14
|
-
* Concatenate a validated base identifier with serial component
|
|
14
|
+
* Concatenate a validated base identifier with a serial component.
|
|
15
15
|
*
|
|
16
|
-
* @
|
|
17
|
-
*
|
|
16
|
+
* @param baseIdentifier
|
|
17
|
+
* Base identifier.
|
|
18
|
+
*
|
|
19
|
+
* @param serialComponent
|
|
20
|
+
* Serial component.
|
|
21
|
+
*
|
|
22
|
+
* @returns
|
|
23
|
+
* Serialized identifier.
|
|
24
|
+
*/
|
|
25
|
+
#concatenateValidated(baseIdentifier: string, serialComponent: string): string;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Concatenate a validated base identifier with serial components.
|
|
18
29
|
*
|
|
19
30
|
* @param baseIdentifier
|
|
20
31
|
* Base identifier.
|
|
21
32
|
*
|
|
22
|
-
* @param
|
|
23
|
-
* Serial
|
|
33
|
+
* @param serialComponents
|
|
34
|
+
* Serial components.
|
|
24
35
|
*
|
|
25
36
|
* @returns
|
|
26
|
-
* Serialized
|
|
37
|
+
* Serialized identifiers.
|
|
27
38
|
*/
|
|
28
|
-
#concatenateValidated
|
|
29
|
-
// TODO Refactor type when https://github.com/microsoft/TypeScript/pull/56941 released.
|
|
30
|
-
let result: string | Iterable<string>;
|
|
39
|
+
#concatenateValidated(baseIdentifier: string, serialComponents: Iterable<string>): Iterable<string>;
|
|
31
40
|
|
|
41
|
+
// eslint-disable-next-line jsdoc/require-jsdoc -- Implementation of overloaded signatures.
|
|
42
|
+
#concatenateValidated(baseIdentifier: string, serialComponentOrComponents: string | Iterable<string>): string | Iterable<string> {
|
|
32
43
|
const serialComponentCreator = this.serialComponentCreator;
|
|
33
44
|
const serialComponentValidation = this.serialComponentValidation;
|
|
34
45
|
|
|
@@ -47,55 +58,82 @@ export class SerializableNumericIdentifierCreator extends MixinAbstractNonGTINNu
|
|
|
47
58
|
return baseIdentifier + serialComponent;
|
|
48
59
|
}
|
|
49
60
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
result = mapIterable(serialComponentOrComponents, validateAndConcatenate);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type determination is handled above.
|
|
57
|
-
return result as TransformerOutput<TTransformerInput, string>;
|
|
61
|
+
return typeof serialComponentOrComponents !== "object" ?
|
|
62
|
+
validateAndConcatenate(serialComponentOrComponents) :
|
|
63
|
+
mapIterable(serialComponentOrComponents, validateAndConcatenate);
|
|
58
64
|
}
|
|
59
65
|
|
|
60
66
|
/**
|
|
61
|
-
* Create serialized identifier
|
|
67
|
+
* Create a serialized identifier with a reference based on a numeric value concatenated with a serial component.
|
|
62
68
|
* The value is converted to a reference of the appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
63
69
|
*
|
|
64
|
-
* @
|
|
65
|
-
*
|
|
70
|
+
* @param value
|
|
71
|
+
* Numeric value of the reference.
|
|
72
|
+
*
|
|
73
|
+
* @param serialComponent
|
|
74
|
+
* Serial component.
|
|
75
|
+
*
|
|
76
|
+
* @param sparse
|
|
77
|
+
* If true, the value is mapped to a sparse sequence resistant to discovery.
|
|
78
|
+
*
|
|
79
|
+
* @returns
|
|
80
|
+
* Serialized identifier.
|
|
81
|
+
*/
|
|
82
|
+
createSerialized(value: number | bigint, serialComponent: string, sparse?: boolean): string;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Create serialized identifiers with a reference based on a numeric value concatenated with serial components. The
|
|
86
|
+
* value is converted to a reference of the appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
66
87
|
*
|
|
67
88
|
* @param value
|
|
68
89
|
* Numeric value of the reference.
|
|
69
90
|
*
|
|
70
|
-
* @param
|
|
71
|
-
* Serial
|
|
91
|
+
* @param serialComponents
|
|
92
|
+
* Serial components.
|
|
72
93
|
*
|
|
73
94
|
* @param sparse
|
|
74
|
-
* If true, the value is mapped to a sparse sequence resistant to discovery.
|
|
95
|
+
* If true, the value is mapped to a sparse sequence resistant to discovery.
|
|
75
96
|
*
|
|
76
97
|
* @returns
|
|
77
98
|
* Serialized identifiers.
|
|
78
99
|
*/
|
|
79
|
-
createSerialized
|
|
100
|
+
createSerialized(value: number | bigint, serialComponents: Iterable<string>, sparse?: boolean): Iterable<string>;
|
|
101
|
+
|
|
102
|
+
// eslint-disable-next-line jsdoc/require-jsdoc -- Implementation of overloaded signatures.
|
|
103
|
+
createSerialized(value: number | bigint, serialComponentOrComponents: string | Iterable<string>, sparse?: boolean): string | Iterable<string> {
|
|
80
104
|
return this.#concatenateValidated(this.create(value, sparse), serialComponentOrComponents);
|
|
81
105
|
}
|
|
82
106
|
|
|
83
107
|
/**
|
|
84
|
-
* Concatenate a base identifier with serial component
|
|
108
|
+
* Concatenate a base identifier with a serial component.
|
|
109
|
+
*
|
|
110
|
+
* @param baseIdentifier
|
|
111
|
+
* Base identifier.
|
|
112
|
+
*
|
|
113
|
+
* @param serialComponent
|
|
114
|
+
* Serial component.
|
|
85
115
|
*
|
|
86
|
-
* @
|
|
87
|
-
*
|
|
116
|
+
* @returns
|
|
117
|
+
* Serialized identifier.
|
|
118
|
+
*/
|
|
119
|
+
concatenate(baseIdentifier: string, serialComponent: string): string;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Concatenate a base identifier with serial components.
|
|
88
123
|
*
|
|
89
124
|
* @param baseIdentifier
|
|
90
125
|
* Base identifier.
|
|
91
126
|
*
|
|
92
|
-
* @param
|
|
93
|
-
* Serial
|
|
127
|
+
* @param serialComponents
|
|
128
|
+
* Serial components.
|
|
94
129
|
*
|
|
95
130
|
* @returns
|
|
96
|
-
* Serialized
|
|
131
|
+
* Serialized identifiers.
|
|
97
132
|
*/
|
|
98
|
-
concatenate
|
|
133
|
+
concatenate(baseIdentifier: string, serialComponents: Iterable<string>): Iterable<string>;
|
|
134
|
+
|
|
135
|
+
// eslint-disable-next-line jsdoc/require-jsdoc -- Implementation of overloaded signatures.
|
|
136
|
+
concatenate(baseIdentifier: string, serialComponentOrComponents: string | Iterable<string>): string | Iterable<string> {
|
|
99
137
|
this.validate(baseIdentifier);
|
|
100
138
|
|
|
101
139
|
return this.#concatenateValidated(baseIdentifier, serialComponentOrComponents);
|
package/src/version.ts
CHANGED