@aidc-toolkit/gs1 1.0.26-beta → 1.0.28-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-identifier-creator.d.ts +32 -66
- package/dist/abstract-identifier-creator.d.ts.map +1 -1
- package/dist/abstract-identifier-creator.js +62 -45
- package/dist/abstract-identifier-creator.js.map +1 -1
- package/dist/abstract-non-gtin-numeric-identifier-creator.d.ts +36 -0
- package/dist/abstract-non-gtin-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/abstract-non-gtin-numeric-identifier-creator.js +37 -0
- package/dist/abstract-non-gtin-numeric-identifier-creator.js.map +1 -0
- package/dist/abstract-numeric-identifier-creator.d.ts +28 -86
- package/dist/abstract-numeric-identifier-creator.d.ts.map +1 -1
- package/dist/abstract-numeric-identifier-creator.js +138 -121
- package/dist/abstract-numeric-identifier-creator.js.map +1 -1
- package/dist/content-character-set-creators.d.ts +4 -0
- package/dist/content-character-set-creators.d.ts.map +1 -0
- package/dist/content-character-set-creators.js +9 -0
- package/dist/content-character-set-creators.js.map +1 -0
- package/dist/gtin-creator.d.ts +8 -13
- package/dist/gtin-creator.d.ts.map +1 -1
- package/dist/gtin-creator.js +12 -15
- package/dist/gtin-creator.js.map +1 -1
- package/dist/gtin-descriptor.d.ts +8 -3
- package/dist/gtin-descriptor.d.ts.map +1 -1
- package/dist/gtin-length.d.ts +64 -0
- package/dist/gtin-length.d.ts.map +1 -0
- package/dist/gtin-length.js +36 -0
- package/dist/gtin-length.js.map +1 -0
- package/dist/gtin-type.d.ts +15 -28
- package/dist/gtin-type.d.ts.map +1 -1
- package/dist/gtin-type.js +4 -28
- package/dist/gtin-type.js.map +1 -1
- package/dist/gtin-validator.d.ts +9 -23
- package/dist/gtin-validator.d.ts.map +1 -1
- package/dist/gtin-validator.js +32 -39
- package/dist/gtin-validator.js.map +1 -1
- package/dist/identifier-creator.d.ts +4 -4
- package/dist/identifier-creator.d.ts.map +1 -1
- package/dist/{creators.d.ts → identifier-creators.d.ts} +47 -10
- package/dist/identifier-creators.d.ts.map +1 -0
- package/dist/identifier-creators.js +92 -0
- package/dist/identifier-creators.js.map +1 -0
- package/dist/{descriptors.d.ts → identifier-descriptors.d.ts} +20 -10
- package/dist/identifier-descriptors.d.ts.map +1 -0
- package/dist/{descriptors.js → identifier-descriptors.js} +27 -31
- package/dist/identifier-descriptors.js.map +1 -0
- package/dist/identifier-extension.d.ts +82 -0
- package/dist/identifier-extension.d.ts.map +1 -0
- package/dist/identifier-extension.js +79 -0
- package/dist/identifier-extension.js.map +1 -0
- package/dist/identifier-validator.d.ts +44 -9
- package/dist/identifier-validator.d.ts.map +1 -1
- package/dist/identifier-validator.js +109 -1
- package/dist/identifier-validator.js.map +1 -1
- package/dist/{validators.d.ts → identifier-validators.d.ts} +47 -12
- package/dist/identifier-validators.d.ts.map +1 -0
- package/dist/{validators.js → identifier-validators.js} +40 -13
- package/dist/identifier-validators.js.map +1 -0
- package/dist/index.d.ts +15 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/dist/leader-type.d.ts +26 -0
- package/dist/leader-type.d.ts.map +1 -0
- package/dist/leader-type.js +18 -0
- package/dist/leader-type.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-creator.d.ts +7 -19
- package/dist/non-gtin-numeric-identifier-creator.d.ts.map +1 -1
- package/dist/non-gtin-numeric-identifier-creator.js +1 -22
- package/dist/non-gtin-numeric-identifier-creator.js.map +1 -1
- package/dist/non-gtin-numeric-identifier-descriptor.d.ts +1 -1
- package/dist/non-gtin-numeric-identifier-descriptor.d.ts.map +1 -1
- package/dist/non-gtin-numeric-identifier-type.d.ts +22 -3
- package/dist/non-gtin-numeric-identifier-type.d.ts.map +1 -1
- package/dist/non-gtin-numeric-identifier-type.js +7 -1
- package/dist/non-gtin-numeric-identifier-type.js.map +1 -1
- package/dist/non-gtin-numeric-identifier-validator.d.ts +5 -10
- package/dist/non-gtin-numeric-identifier-validator.d.ts.map +1 -1
- package/dist/non-gtin-numeric-identifier-validator.js +5 -12
- package/dist/non-gtin-numeric-identifier-validator.js.map +1 -1
- package/dist/non-numeric-identifier-creator.d.ts +4 -9
- package/dist/non-numeric-identifier-creator.d.ts.map +1 -1
- package/dist/non-numeric-identifier-creator.js +8 -10
- package/dist/non-numeric-identifier-creator.js.map +1 -1
- package/dist/non-numeric-identifier-type.d.ts +22 -3
- package/dist/non-numeric-identifier-type.d.ts.map +1 -1
- package/dist/non-numeric-identifier-type.js +7 -1
- package/dist/non-numeric-identifier-type.js.map +1 -1
- package/dist/non-numeric-identifier-validator.d.ts +3 -11
- package/dist/non-numeric-identifier-validator.d.ts.map +1 -1
- package/dist/non-numeric-identifier-validator.js +8 -8
- package/dist/non-numeric-identifier-validator.js.map +1 -1
- package/dist/non-serializable-numeric-identifier-creator.d.ts +10 -0
- package/dist/non-serializable-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/non-serializable-numeric-identifier-creator.js +8 -0
- package/dist/non-serializable-numeric-identifier-creator.js.map +1 -0
- package/dist/non-serializable-numeric-identifier-descriptor.d.ts +12 -0
- package/dist/non-serializable-numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/non-serializable-numeric-identifier-descriptor.js +2 -0
- package/dist/non-serializable-numeric-identifier-descriptor.js.map +1 -0
- package/dist/non-serializable-numeric-identifier-type.d.ts +26 -0
- package/dist/non-serializable-numeric-identifier-type.d.ts.map +1 -0
- package/dist/non-serializable-numeric-identifier-type.js +7 -0
- package/dist/non-serializable-numeric-identifier-type.js.map +1 -0
- package/dist/non-serializable-numeric-identifier-validator.d.ts +16 -0
- package/dist/non-serializable-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/non-serializable-numeric-identifier-validator.js +17 -0
- package/dist/non-serializable-numeric-identifier-validator.js.map +1 -0
- package/dist/numeric-identifier-creator.d.ts +6 -6
- package/dist/numeric-identifier-creator.d.ts.map +1 -1
- package/dist/numeric-identifier-descriptor.d.ts +2 -1
- package/dist/numeric-identifier-descriptor.d.ts.map +1 -1
- package/dist/numeric-identifier-type.d.ts +19 -24
- package/dist/numeric-identifier-type.d.ts.map +1 -1
- package/dist/numeric-identifier-type.js +4 -15
- package/dist/numeric-identifier-type.js.map +1 -1
- package/dist/numeric-identifier-validator.d.ts +20 -6
- package/dist/numeric-identifier-validator.d.ts.map +1 -1
- package/dist/numeric-identifier-validator.js +60 -1
- package/dist/numeric-identifier-validator.js.map +1 -1
- package/dist/prefix-manager.d.ts +13 -94
- package/dist/prefix-manager.d.ts.map +1 -1
- package/dist/prefix-manager.js +65 -102
- package/dist/prefix-manager.js.map +1 -1
- package/dist/serializable-numeric-identifier-creator.d.ts +3 -31
- package/dist/serializable-numeric-identifier-creator.d.ts.map +1 -1
- package/dist/serializable-numeric-identifier-creator.js +7 -21
- package/dist/serializable-numeric-identifier-creator.js.map +1 -1
- package/dist/serializable-numeric-identifier-descriptor.d.ts +1 -1
- package/dist/serializable-numeric-identifier-descriptor.d.ts.map +1 -1
- package/dist/serializable-numeric-identifier-type.d.ts +22 -2
- package/dist/serializable-numeric-identifier-type.d.ts.map +1 -1
- package/dist/serializable-numeric-identifier-type.js +7 -1
- package/dist/serializable-numeric-identifier-type.js.map +1 -1
- package/dist/serializable-numeric-identifier-validator.d.ts +3 -18
- package/dist/serializable-numeric-identifier-validator.d.ts.map +1 -1
- package/dist/serializable-numeric-identifier-validator.js +17 -16
- package/dist/serializable-numeric-identifier-validator.js.map +1 -1
- package/package.json +4 -5
- package/src/abstract-identifier-creator.ts +104 -75
- package/src/abstract-non-gtin-numeric-identifier-creator.ts +81 -0
- package/src/abstract-numeric-identifier-creator.ts +185 -133
- package/src/content-character-set-creators.ts +9 -0
- package/src/gtin-creator.ts +15 -16
- package/src/gtin-descriptor.ts +9 -3
- package/src/gtin-length.ts +61 -0
- package/src/gtin-type.ts +6 -37
- package/src/gtin-validator.ts +34 -41
- package/src/identifier-creator.ts +4 -4
- package/src/identifier-creators.ts +177 -0
- package/src/{descriptors.ts → identifier-descriptors.ts} +56 -54
- package/src/identifier-extension.ts +155 -0
- package/src/identifier-validator.ts +93 -10
- package/src/{validators.ts → identifier-validators.ts} +98 -36
- package/src/index.ts +15 -9
- package/src/leader-type.ts +29 -0
- package/src/non-gtin-numeric-identifier-creator.ts +7 -22
- package/src/non-gtin-numeric-identifier-descriptor.ts +1 -1
- package/src/non-gtin-numeric-identifier-type.ts +14 -3
- package/src/non-gtin-numeric-identifier-validator.ts +5 -13
- package/src/non-numeric-identifier-creator.ts +15 -12
- package/src/non-numeric-identifier-type.ts +14 -3
- package/src/non-numeric-identifier-validator.ts +8 -9
- package/src/non-serializable-numeric-identifier-creator.ts +11 -0
- package/src/non-serializable-numeric-identifier-descriptor.ts +12 -0
- package/src/non-serializable-numeric-identifier-type.ts +22 -0
- package/src/non-serializable-numeric-identifier-validator.ts +19 -0
- package/src/numeric-identifier-creator.ts +7 -6
- package/src/numeric-identifier-descriptor.ts +2 -1
- package/src/numeric-identifier-type.ts +17 -35
- package/src/numeric-identifier-validator.ts +61 -6
- package/src/prefix-manager.ts +76 -112
- package/src/serializable-numeric-identifier-creator.ts +10 -25
- package/src/serializable-numeric-identifier-descriptor.ts +1 -1
- package/src/serializable-numeric-identifier-type.ts +14 -5
- package/src/serializable-numeric-identifier-validator.ts +17 -16
- package/test/gtin-creator.ts +9 -2
- package/test/gtin-validator.test.ts +8 -10
- package/test/identifier-creator.ts +7 -7
- package/test/mixin.test.ts +35 -0
- package/test/non-gtin-numeric-identifier-validator.ts +7 -2
- package/test/non-numeric-identifier-validator.ts +2 -2
- package/test/non-serializable-numeric-identifier-creator.ts +64 -0
- package/test/non-serializable-numeric-identifier-validator.ts +6 -0
- package/test/numeric-identifier-creator.ts +7 -2
- package/test/serializable-numeric-identifier-validator.ts +2 -2
- package/test/utility.ts +6 -6
- package/test/validator.test.ts +11 -10
- package/test/variable-measure-rcn.test.ts +23 -23
- package/dist/abstract-identifier-validator.d.ts +0 -95
- package/dist/abstract-identifier-validator.d.ts.map +0 -1
- package/dist/abstract-identifier-validator.js +0 -123
- package/dist/abstract-identifier-validator.js.map +0 -1
- package/dist/abstract-numeric-identifier-validator.d.ts +0 -35
- package/dist/abstract-numeric-identifier-validator.d.ts.map +0 -1
- package/dist/abstract-numeric-identifier-validator.js +0 -61
- package/dist/abstract-numeric-identifier-validator.js.map +0 -1
- package/dist/creators.d.ts.map +0 -1
- package/dist/creators.js +0 -62
- package/dist/creators.js.map +0 -1
- package/dist/descriptors.d.ts.map +0 -1
- package/dist/descriptors.js.map +0 -1
- package/dist/validators.d.ts.map +0 -1
- package/dist/validators.js.map +0 -1
- package/src/abstract-identifier-validator.ts +0 -140
- package/src/abstract-numeric-identifier-validator.ts +0 -69
- package/src/creators.ts +0 -113
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { exclude } from "@aidc-toolkit/core";
|
|
2
|
+
import { GTINTypes } from "./gtin-type.js";
|
|
3
|
+
import { NumericIdentifierTypes } from "./numeric-identifier-type.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Non-GTIN numeric identifier types.
|
|
7
|
+
*/
|
|
8
|
+
export const NonGTINNumericIdentifierTypes = exclude(NumericIdentifierTypes, GTINTypes);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Non-GTIN numeric identifier type key.
|
|
12
|
+
*/
|
|
13
|
+
export type NonGTINNumericIdentifierTypeKey = keyof typeof NonGTINNumericIdentifierTypes;
|
|
3
14
|
|
|
4
15
|
/**
|
|
5
16
|
* Non-GTIN numeric identifier type.
|
|
6
17
|
*/
|
|
7
|
-
export type NonGTINNumericIdentifierType =
|
|
18
|
+
export type NonGTINNumericIdentifierType = typeof NonGTINNumericIdentifierTypes[NonGTINNumericIdentifierTypeKey];
|
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
import { AbstractNumericIdentifierValidator } from "./abstract-numeric-identifier-validator.js";
|
|
2
|
-
import { IdentifierDescriptors } from "./descriptors.js";
|
|
3
1
|
import type { NonGTINNumericIdentifierDescriptor } from "./non-gtin-numeric-identifier-descriptor.js";
|
|
4
2
|
import type { NonGTINNumericIdentifierType } from "./non-gtin-numeric-identifier-type.js";
|
|
5
|
-
import
|
|
3
|
+
import { NumericIdentifierValidator } from "./numeric-identifier-validator.js";
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* Non-GTIN numeric identifier validator.
|
|
7
|
+
*
|
|
8
|
+
* @template TNonGTINNumericIdentifierType
|
|
9
|
+
* Non-GTIN numeric identifier type type.
|
|
9
10
|
*/
|
|
10
|
-
export class NonGTINNumericIdentifierValidator extends
|
|
11
|
-
/**
|
|
12
|
-
* Constructor.
|
|
13
|
-
*
|
|
14
|
-
* @param identifierType
|
|
15
|
-
* Identifier type.
|
|
16
|
-
*/
|
|
17
|
-
constructor(identifierType: Exclude<NonGTINNumericIdentifierType, SerializableNumericIdentifierType>) {
|
|
18
|
-
super(IdentifierDescriptors[identifierType]);
|
|
19
|
-
}
|
|
11
|
+
export abstract class NonGTINNumericIdentifierValidator<TNonGTINNumericIdentifierType extends NonGTINNumericIdentifierType = NonGTINNumericIdentifierType> extends NumericIdentifierValidator<TNonGTINNumericIdentifierType> implements NonGTINNumericIdentifierDescriptor {
|
|
20
12
|
}
|
|
@@ -4,26 +4,31 @@ import {
|
|
|
4
4
|
type TransformerInput,
|
|
5
5
|
type TransformerOutput
|
|
6
6
|
} from "@aidc-toolkit/utility";
|
|
7
|
-
import {
|
|
8
|
-
import { AbstractIdentifierCreator } from "./abstract-identifier-creator.js";
|
|
7
|
+
import { MixinAbstractIdentifierCreator } from "./abstract-identifier-creator.js";
|
|
9
8
|
import { checkCharacterPair } from "./check.js";
|
|
9
|
+
import { IdentifierDescriptors } from "./identifier-descriptors.js";
|
|
10
10
|
import { i18nextGS1 } from "./locale/i18n.js";
|
|
11
11
|
import type { NonNumericIdentifierType } from "./non-numeric-identifier-type.js";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
type NonNumericIdentifierValidation,
|
|
14
|
+
NonNumericIdentifierValidator
|
|
15
|
+
} from "./non-numeric-identifier-validator.js";
|
|
13
16
|
import type { PrefixProvider } from "./prefix-provider.js";
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
19
|
* Non-numeric identifier creator.
|
|
17
20
|
*/
|
|
18
|
-
export class NonNumericIdentifierCreator extends
|
|
21
|
+
export class NonNumericIdentifierCreator extends MixinAbstractIdentifierCreator<
|
|
22
|
+
NonNumericIdentifierType,
|
|
23
|
+
NonNumericIdentifierValidation
|
|
24
|
+
>(NonNumericIdentifierValidator) {
|
|
19
25
|
/**
|
|
20
26
|
* Reference validation parameters.
|
|
21
27
|
*/
|
|
22
|
-
|
|
28
|
+
readonly #referenceValidation: CharacterSetValidation;
|
|
23
29
|
|
|
24
30
|
/**
|
|
25
|
-
* Constructor.
|
|
26
|
-
* provider type.
|
|
31
|
+
* Constructor.
|
|
27
32
|
*
|
|
28
33
|
* @param prefixProvider
|
|
29
34
|
* Prefix provider.
|
|
@@ -32,11 +37,9 @@ export class NonNumericIdentifierCreator extends Mixin(NonNumericIdentifierValid
|
|
|
32
37
|
* Identifier type.
|
|
33
38
|
*/
|
|
34
39
|
constructor(prefixProvider: PrefixProvider, identifierType: NonNumericIdentifierType) {
|
|
35
|
-
super(identifierType);
|
|
36
|
-
|
|
37
|
-
this.init(prefixProvider, prefixProvider.gs1CompanyPrefix, 2 * Number(this.requiresCheckCharacterPair));
|
|
40
|
+
super(prefixProvider, prefixProvider.gs1CompanyPrefix, 2 * Number(IdentifierDescriptors[identifierType].requiresCheckCharacterPair), identifierType);
|
|
38
41
|
|
|
39
|
-
this
|
|
42
|
+
this.#referenceValidation = {
|
|
40
43
|
minimumLength: 1,
|
|
41
44
|
// Maximum reference length has to account for prefix and check character pair.
|
|
42
45
|
maximumLength: this.referenceLength,
|
|
@@ -48,7 +51,7 @@ export class NonNumericIdentifierCreator extends Mixin(NonNumericIdentifierValid
|
|
|
48
51
|
* Get the reference validation parameters.
|
|
49
52
|
*/
|
|
50
53
|
protected get referenceValidation(): CharacterSetValidation {
|
|
51
|
-
return this
|
|
54
|
+
return this.#referenceValidation;
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
/**
|
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { exclude } from "@aidc-toolkit/core";
|
|
2
|
+
import { IdentifierTypes } from "./identifier-type.js";
|
|
3
|
+
import { NumericIdentifierTypes } from "./numeric-identifier-type.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Non-numeric identifier types.
|
|
7
|
+
*/
|
|
8
|
+
export const NonNumericIdentifierTypes = exclude(IdentifierTypes, NumericIdentifierTypes);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Non-numeric identifier type key.
|
|
12
|
+
*/
|
|
13
|
+
export type NonNumericIdentifierTypeKey = keyof typeof NonNumericIdentifierTypes;
|
|
3
14
|
|
|
4
15
|
/**
|
|
5
16
|
* Non-numeric identifier type.
|
|
6
17
|
*/
|
|
7
|
-
export type NonNumericIdentifierType =
|
|
18
|
+
export type NonNumericIdentifierType = typeof NonNumericIdentifierTypes[NonNumericIdentifierTypeKey];
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Exclusions, RegExpValidator } from "@aidc-toolkit/utility";
|
|
2
|
-
import { AbstractIdentifierValidator } from "./abstract-identifier-validator.js";
|
|
3
2
|
import { hasValidCheckCharacterPair } from "./check.js";
|
|
4
|
-
import { IdentifierDescriptors } from "./descriptors.js";
|
|
5
|
-
import type
|
|
3
|
+
import { IdentifierDescriptors } from "./identifier-descriptors.js";
|
|
4
|
+
import { type IdentifierValidation, IdentifierValidator } from "./identifier-validator.js";
|
|
6
5
|
import { i18nextGS1 } from "./locale/i18n.js";
|
|
7
6
|
import type { NonNumericIdentifierDescriptor } from "./non-numeric-identifier-descriptor.js";
|
|
8
7
|
import type { NonNumericIdentifierType } from "./non-numeric-identifier-type.js";
|
|
@@ -20,11 +19,11 @@ export interface NonNumericIdentifierValidation extends IdentifierValidation {
|
|
|
20
19
|
/**
|
|
21
20
|
* Non-numeric identifier validator.
|
|
22
21
|
*/
|
|
23
|
-
export class NonNumericIdentifierValidator extends
|
|
22
|
+
export class NonNumericIdentifierValidator extends IdentifierValidator<NonNumericIdentifierType, NonNumericIdentifierValidation> implements NonNumericIdentifierDescriptor {
|
|
24
23
|
/**
|
|
25
24
|
* Validator to ensure that an identifier (minus check character pair) is not all numeric.
|
|
26
25
|
*/
|
|
27
|
-
|
|
26
|
+
static readonly #NOT_ALL_NUMERIC_VALIDATOR = new class extends RegExpValidator {
|
|
28
27
|
/**
|
|
29
28
|
* @inheritDoc
|
|
30
29
|
*/
|
|
@@ -36,7 +35,7 @@ export class NonNumericIdentifierValidator extends AbstractIdentifierValidator<N
|
|
|
36
35
|
/**
|
|
37
36
|
* True if the identifier requires a check character pair.
|
|
38
37
|
*/
|
|
39
|
-
|
|
38
|
+
readonly #requiresCheckCharacterPair: boolean;
|
|
40
39
|
|
|
41
40
|
/**
|
|
42
41
|
* Constructor.
|
|
@@ -49,14 +48,14 @@ export class NonNumericIdentifierValidator extends AbstractIdentifierValidator<N
|
|
|
49
48
|
|
|
50
49
|
super(identifierDescriptor);
|
|
51
50
|
|
|
52
|
-
this
|
|
51
|
+
this.#requiresCheckCharacterPair = identifierDescriptor.requiresCheckCharacterPair;
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
/**
|
|
56
55
|
* Determine if the identifier requires a check character pair.
|
|
57
56
|
*/
|
|
58
57
|
get requiresCheckCharacterPair(): boolean {
|
|
59
|
-
return this
|
|
58
|
+
return this.#requiresCheckCharacterPair;
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
/**
|
|
@@ -84,7 +83,7 @@ export class NonNumericIdentifierValidator extends AbstractIdentifierValidator<N
|
|
|
84
83
|
|
|
85
84
|
// Check for all-numeric identifier (minus check character pair) if excluded.
|
|
86
85
|
if (validation?.exclusion === Exclusions.AllNumeric) {
|
|
87
|
-
NonNumericIdentifierValidator
|
|
86
|
+
NonNumericIdentifierValidator.#NOT_ALL_NUMERIC_VALIDATOR.validate(partialIdentifier);
|
|
88
87
|
}
|
|
89
88
|
}
|
|
90
89
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MixinAbstractNonGTINNumericIdentifierCreator } from "./abstract-non-gtin-numeric-identifier-creator.js";
|
|
2
|
+
import type { NonSerializableNumericIdentifierType } from "./non-serializable-numeric-identifier-type.js";
|
|
3
|
+
import { NonSerializableNumericIdentifierValidator } from "./non-serializable-numeric-identifier-validator.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Non-serializable numeric identifier creator.
|
|
7
|
+
*/
|
|
8
|
+
export class NonSerializableNumericIdentifierCreator extends MixinAbstractNonGTINNumericIdentifierCreator<
|
|
9
|
+
NonSerializableNumericIdentifierType
|
|
10
|
+
>(NonSerializableNumericIdentifierValidator) {
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LeaderTypes } from "./leader-type.js";
|
|
2
|
+
import type { NonGTINNumericIdentifierDescriptor } from "./non-gtin-numeric-identifier-descriptor.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Non-serializable numeric identifier descriptor.
|
|
6
|
+
*/
|
|
7
|
+
export interface NonSerializableNumericIdentifierDescriptor extends NonGTINNumericIdentifierDescriptor {
|
|
8
|
+
/**
|
|
9
|
+
* @inheritDoc
|
|
10
|
+
*/
|
|
11
|
+
readonly leaderType: typeof LeaderTypes.None | typeof LeaderTypes.ExtensionDigit;
|
|
12
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { pick } from "@aidc-toolkit/core";
|
|
2
|
+
import { NonGTINNumericIdentifierTypes } from "./non-gtin-numeric-identifier-type.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Non-serializable numeric identifier types.
|
|
6
|
+
*/
|
|
7
|
+
export const NonSerializableNumericIdentifierTypes = pick(NonGTINNumericIdentifierTypes,
|
|
8
|
+
NonGTINNumericIdentifierTypes.GLN,
|
|
9
|
+
NonGTINNumericIdentifierTypes.SSCC,
|
|
10
|
+
NonGTINNumericIdentifierTypes.GSRN,
|
|
11
|
+
NonGTINNumericIdentifierTypes.GSIN
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Non-serializable numeric identifier type key.
|
|
16
|
+
*/
|
|
17
|
+
export type NonSerializableNumericIdentifierTypeKey = keyof typeof NonSerializableNumericIdentifierTypes;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Non-serializable numeric identifier type.
|
|
21
|
+
*/
|
|
22
|
+
export type NonSerializableNumericIdentifierType = typeof NonSerializableNumericIdentifierTypes[NonSerializableNumericIdentifierTypeKey];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IdentifierDescriptors } from "./identifier-descriptors.js";
|
|
2
|
+
import { NonGTINNumericIdentifierValidator } from "./non-gtin-numeric-identifier-validator.js";
|
|
3
|
+
import type { NonSerializableNumericIdentifierDescriptor } from "./non-serializable-numeric-identifier-descriptor.js";
|
|
4
|
+
import type { NonSerializableNumericIdentifierType } from "./non-serializable-numeric-identifier-type.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Non-serializable numeric identifier validator.
|
|
8
|
+
*/
|
|
9
|
+
export class NonSerializableNumericIdentifierValidator extends NonGTINNumericIdentifierValidator<NonSerializableNumericIdentifierType> implements NonSerializableNumericIdentifierDescriptor {
|
|
10
|
+
/**
|
|
11
|
+
* Constructor.
|
|
12
|
+
*
|
|
13
|
+
* @param identifierType
|
|
14
|
+
* Identifier type.
|
|
15
|
+
*/
|
|
16
|
+
constructor(identifierType: NonSerializableNumericIdentifierType) {
|
|
17
|
+
super(IdentifierDescriptors[identifierType]);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,15 +1,16 @@
|
|
|
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
3
|
import type { IdentifierCreator } from "./identifier-creator.js";
|
|
3
|
-
import type {
|
|
4
|
+
import type { NumericIdentifierType } from "./numeric-identifier-type.js";
|
|
4
5
|
import type { NumericIdentifierValidation, NumericIdentifierValidator } from "./numeric-identifier-validator.js";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Numeric identifier creator. Creates one or many numeric identifiers.
|
|
8
9
|
*
|
|
9
|
-
* @template
|
|
10
|
-
* Numeric identifier
|
|
10
|
+
* @template TNumericIdentifierType
|
|
11
|
+
* Numeric identifier type type.
|
|
11
12
|
*/
|
|
12
|
-
export interface NumericIdentifierCreator<
|
|
13
|
+
export interface NumericIdentifierCreator<TNumericIdentifierType extends NumericIdentifierType = NumericIdentifierType> extends NumericIdentifierValidator<TNumericIdentifierType>, IdentifierCreator<TNumericIdentifierType, NumericIdentifierValidation> {
|
|
13
14
|
/**
|
|
14
15
|
* Get the capacity (`10**referenceLength`).
|
|
15
16
|
*/
|
|
@@ -27,7 +28,7 @@ export interface NumericIdentifierCreator<TNumericIdentifierDescriptor extends N
|
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Create identifier(s) with reference(s) based on numeric value(s). The value(s) is/are converted to references of
|
|
30
|
-
* the appropriate length using
|
|
31
|
+
* the appropriate length using {@linkcode NUMERIC_CREATOR}.
|
|
31
32
|
*
|
|
32
33
|
* @template TTransformerInput
|
|
33
34
|
* Transformer input type.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ContentCharacterSets } from "./content-character-set.js";
|
|
2
2
|
import type { IdentifierDescriptor } from "./identifier-descriptor.js";
|
|
3
|
-
import type { LeaderType
|
|
3
|
+
import type { LeaderType } from "./leader-type.js";
|
|
4
|
+
import type { NumericIdentifierType } from "./numeric-identifier-type.js";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Numeric identifier descriptor.
|
|
@@ -1,44 +1,26 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { pick } from "@aidc-toolkit/core";
|
|
2
|
+
import { IdentifierTypes } from "./identifier-type.js";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
* Numeric identifier
|
|
5
|
+
* Numeric identifier types.
|
|
5
6
|
*/
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
export const NumericIdentifierTypes = pick(IdentifierTypes,
|
|
8
|
+
IdentifierTypes.GTIN,
|
|
9
|
+
IdentifierTypes.GLN,
|
|
10
|
+
IdentifierTypes.SSCC,
|
|
11
|
+
IdentifierTypes.GRAI,
|
|
12
|
+
IdentifierTypes.GSRN,
|
|
13
|
+
IdentifierTypes.GDTI,
|
|
14
|
+
IdentifierTypes.GSIN,
|
|
15
|
+
IdentifierTypes.GCN
|
|
16
|
+
);
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
|
-
*
|
|
19
|
+
* Numeric identifier type key.
|
|
18
20
|
*/
|
|
19
|
-
export
|
|
20
|
-
/**
|
|
21
|
-
* No leader.
|
|
22
|
-
*/
|
|
23
|
-
None: "None",
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Indicator digit (GTIN only).
|
|
27
|
-
*/
|
|
28
|
-
IndicatorDigit: "Indicator digit",
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Extension digit (SSCC only).
|
|
32
|
-
*/
|
|
33
|
-
ExtensionDigit: "Extension digit"
|
|
34
|
-
} as const;
|
|
21
|
+
export type NumericIdentifierTypeKey = keyof typeof NumericIdentifierTypes;
|
|
35
22
|
|
|
36
23
|
/**
|
|
37
|
-
*
|
|
38
|
-
*/
|
|
39
|
-
export type LeaderTypeKey = keyof typeof LeaderTypes;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Leader type.
|
|
24
|
+
* Numeric identifier type.
|
|
43
25
|
*/
|
|
44
|
-
export type
|
|
26
|
+
export type NumericIdentifierType = typeof NumericIdentifierTypes[NumericIdentifierTypeKey];
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { hasValidCheckDigit } from "./check.js";
|
|
2
|
+
import type { IdentifierTypeDescriptor } from "./identifier-descriptors.js";
|
|
3
|
+
import { type IdentifierValidation, IdentifierValidator } from "./identifier-validator.js";
|
|
4
|
+
import { LeaderTypes } from "./leader-type.js";
|
|
5
|
+
import { i18nextGS1 } from "./locale/i18n.js";
|
|
2
6
|
import type { NumericIdentifierDescriptor } from "./numeric-identifier-descriptor.js";
|
|
7
|
+
import type { NumericIdentifierType } from "./numeric-identifier-type.js";
|
|
3
8
|
|
|
4
9
|
/**
|
|
5
10
|
* Numeric identifier validation parameters.
|
|
@@ -14,12 +19,62 @@ export interface NumericIdentifierValidation extends IdentifierValidation {
|
|
|
14
19
|
/**
|
|
15
20
|
* Numeric identifier validator.
|
|
16
21
|
*
|
|
17
|
-
* @template
|
|
18
|
-
* Numeric identifier
|
|
22
|
+
* @template TNumericIdentifierType
|
|
23
|
+
* Numeric identifier type type.
|
|
19
24
|
*/
|
|
20
|
-
export
|
|
25
|
+
export abstract class NumericIdentifierValidator<TNumericIdentifierType extends NumericIdentifierType = NumericIdentifierType> extends IdentifierValidator<TNumericIdentifierType, NumericIdentifierValidation> implements NumericIdentifierDescriptor {
|
|
21
26
|
/**
|
|
22
|
-
*
|
|
27
|
+
* Leader type.
|
|
23
28
|
*/
|
|
24
|
-
|
|
29
|
+
readonly #leaderType: IdentifierTypeDescriptor<TNumericIdentifierType>["leaderType"];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Prefix position, determined by the leader type.
|
|
33
|
+
*/
|
|
34
|
+
readonly #prefixPosition: number;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Constructor.
|
|
38
|
+
*
|
|
39
|
+
* @param identifierDescriptor
|
|
40
|
+
* Identifier descriptor.
|
|
41
|
+
*/
|
|
42
|
+
constructor(identifierDescriptor: IdentifierTypeDescriptor<TNumericIdentifierType>) {
|
|
43
|
+
super(identifierDescriptor);
|
|
44
|
+
|
|
45
|
+
this.#leaderType = identifierDescriptor.leaderType;
|
|
46
|
+
this.#prefixPosition = Number(this.leaderType === LeaderTypes.ExtensionDigit);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @inheritDoc
|
|
51
|
+
*/
|
|
52
|
+
get leaderType(): IdentifierTypeDescriptor<TNumericIdentifierType>["leaderType"] {
|
|
53
|
+
return this.#leaderType;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @inheritDoc
|
|
58
|
+
*/
|
|
59
|
+
validate(identifier: string, validation?: NumericIdentifierValidation): void {
|
|
60
|
+
// Validate the prefix, with care taken for its position within the identifier.
|
|
61
|
+
if (this.#prefixPosition === 0) {
|
|
62
|
+
super.validatePrefix(identifier, validation?.positionOffset);
|
|
63
|
+
} else {
|
|
64
|
+
super.validatePrefix(identifier.substring(this.#prefixPosition), validation?.positionOffset === undefined ? this.#prefixPosition : validation.positionOffset + this.#prefixPosition);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Validate the length.
|
|
68
|
+
if (identifier.length !== this.length) {
|
|
69
|
+
throw new RangeError(i18nextGS1.t("Identifier.identifierTypeLength", {
|
|
70
|
+
identifierType: this.identifierType,
|
|
71
|
+
length: this.length
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Validating the check digit will also validate the characters.
|
|
76
|
+
if (!hasValidCheckDigit(this.padIdentifier(identifier, validation?.positionOffset))) {
|
|
77
|
+
throw new RangeError(i18nextGS1.t("Identifier.invalidCheckDigit"));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
25
80
|
}
|