@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.
@@ -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(s) with an indicator digit and reference(s) based on numeric value(s). The value(s) is/are
53
- * converted to reference(s) of the appropriate length using {@linkcode NUMERIC_CREATOR}.
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
- * @template TTransformerInput
56
- * Transformer input type.
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 valueOrValues
62
- * Numeric value(s).
70
+ * @param values
71
+ * Numeric values.
63
72
  *
64
73
  * @param sparse
65
- * If true, the value(s) is/are mapped to a sparse sequence resistant to discovery. Default is false.
74
+ * If true, the values are mapped to a sparse sequence resistant to discovery.
66
75
  *
67
76
  * @returns
68
- * GTIN-14(s).
77
+ * GTIN-14s.
69
78
  */
70
- createGTIN14<TTransformerInput extends TransformerInput<number | bigint>>(indicatorDigit: string, valueOrValues: TTransformerInput, sparse = false): TransformerOutput<TTransformerInput, string> {
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(s) with reference(s).
53
+ * Create an identifier with a reference.
54
+ *
55
+ * @param reference
56
+ * Reference.
59
57
  *
60
- * @template TTransformerInput
61
- * Transformer input type.
58
+ * @returns
59
+ * Identifier.
60
+ */
61
+ create(reference: string): string;
62
+
63
+ /**
64
+ * Create identifiers with references.
62
65
  *
63
- * @param referenceOrReferences
64
- * Reference(s).
66
+ * @param references
67
+ * References.
65
68
  *
66
69
  * @returns
67
- * Identifier(s).
70
+ * Identifiers.
68
71
  */
69
- create<TTransformerInput extends TransformerInput<string>>(referenceOrReferences: TTransformerInput): TransformerOutput<TTransformerInput, string> {
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
- if (typeof referenceOrReferences !== "object") {
96
- result = validateAndCreate(referenceOrReferences);
97
- } else {
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, type TransformerInput, type TransformerOutput } from "@aidc-toolkit/utility";
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
- * Create identifier(s) with reference(s) based on numeric value(s). The value(s) is/are converted to references of
31
- * the appropriate length using {@linkcode NUMERIC_CREATOR}.
32
- *
33
- * @template TTransformerInput
34
- * Transformer input type.
35
- *
36
- * @param valueOrValues
37
- * Numeric value(s).
38
- *
39
- * @param sparse
40
- * If true, the value(s) are mapped to a sparse sequence resistant to discovery. Default is false.
41
- *
42
- * @returns
43
- * Identifier(s).
44
- */
45
- create: <TTransformerInput extends TransformerInput<number | bigint>>(valueOrValues: TTransformerInput, sparse?: boolean) => TransformerOutput<TTransformerInput, string>;
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, type TransformerInput, type TransformerOutput } from "@aidc-toolkit/utility";
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(s).
14
+ * Concatenate a validated base identifier with a serial component.
15
15
  *
16
- * @template TTransformerInput
17
- * Transformer input type.
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 serialComponentOrComponents
23
- * Serial component(s).
33
+ * @param serialComponents
34
+ * Serial components.
24
35
  *
25
36
  * @returns
26
- * Serialized identifier(s).
37
+ * Serialized identifiers.
27
38
  */
28
- #concatenateValidated<TTransformerInput extends TransformerInput<string>>(baseIdentifier: string, serialComponentOrComponents: TTransformerInput): TransformerOutput<TTransformerInput, string> {
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
- if (typeof serialComponentOrComponents !== "object") {
51
- result = validateAndConcatenate(serialComponentOrComponents);
52
- } else {
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(s) with a reference based on a numeric value concatenated with serial component(s).
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
- * @template TTransformerInput
65
- * Transformer input type.
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 serialComponentOrComponents
71
- * Serial component(s).
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. Default is false.
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<TTransformerInput extends TransformerInput<string>>(value: number, serialComponentOrComponents: TTransformerInput, sparse?: boolean): TransformerOutput<TTransformerInput, string> {
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(s).
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
- * @template TTransformerInput
87
- * Transformer input type.
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 serialComponentOrComponents
93
- * Serial component(s).
127
+ * @param serialComponents
128
+ * Serial components.
94
129
  *
95
130
  * @returns
96
- * Serialized identifier(s).
131
+ * Serialized identifiers.
97
132
  */
98
- concatenate<TTransformerInput extends TransformerInput<string>>(baseIdentifier: string, serialComponentOrComponents: TTransformerInput): TransformerOutput<TTransformerInput, string> {
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
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Repository version, updated automatically during publication.
3
3
  */
4
- export const VERSION = "1.0.46-beta";
4
+ export const VERSION = "1.0.47-beta";