@aidc-toolkit/gs1 1.0.23-beta → 1.0.25-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.
Files changed (155) hide show
  1. package/dist/index.cjs +4813 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +1949 -0
  4. package/dist/index.d.ts +1949 -36
  5. package/dist/index.js +4727 -19
  6. package/dist/index.js.map +1 -1
  7. package/package.json +8 -12
  8. package/src/abstract-identifier-creator.ts +97 -0
  9. package/src/abstract-identifier-validator.ts +140 -0
  10. package/{dist/numeric-identifier-creator.js → src/abstract-numeric-identifier-creator.ts} +61 -28
  11. package/src/abstract-numeric-identifier-validator.ts +69 -0
  12. package/src/character-set.ts +24 -9
  13. package/src/check.ts +9 -9
  14. package/src/content-character-set.ts +29 -0
  15. package/src/creators.ts +113 -0
  16. package/src/descriptors.ts +332 -0
  17. package/src/gtin-creator.ts +9 -8
  18. package/src/gtin-descriptor.ts +18 -0
  19. package/src/gtin-type.ts +50 -0
  20. package/src/gtin-validator.ts +40 -64
  21. package/src/identifier-creator.ts +11 -75
  22. package/src/identifier-descriptor.ts +30 -0
  23. package/src/identifier-type.ts +6 -1
  24. package/src/identifier-validator.ts +12 -188
  25. package/src/index.ts +43 -19
  26. package/src/locale/en/locale-resources.ts +0 -1
  27. package/src/locale/fr/locale-resources.ts +0 -1
  28. package/src/locale/i18n.ts +3 -5
  29. package/src/locale/i18next.d.ts +1 -1
  30. package/src/non-gtin-numeric-identifier-creator.ts +6 -12
  31. package/src/non-gtin-numeric-identifier-descriptor.ts +24 -0
  32. package/src/non-gtin-numeric-identifier-type.ts +7 -0
  33. package/src/non-gtin-numeric-identifier-validator.ts +8 -42
  34. package/src/non-numeric-identifier-creator.ts +8 -18
  35. package/src/non-numeric-identifier-descriptor.ts +29 -0
  36. package/src/non-numeric-identifier-type.ts +7 -0
  37. package/src/non-numeric-identifier-validator.ts +17 -55
  38. package/src/numeric-identifier-creator.ts +20 -163
  39. package/src/numeric-identifier-descriptor.ts +23 -0
  40. package/src/numeric-identifier-type.ts +44 -0
  41. package/src/numeric-identifier-validator.ts +13 -116
  42. package/src/prefix-manager.ts +94 -152
  43. package/src/prefix-provider.ts +3 -3
  44. package/src/prefix-type.ts +6 -1
  45. package/src/prefix-validator.ts +143 -81
  46. package/src/serializable-numeric-identifier-creator.ts +5 -15
  47. package/src/serializable-numeric-identifier-descriptor.ts +29 -0
  48. package/src/serializable-numeric-identifier-type.ts +9 -0
  49. package/src/serializable-numeric-identifier-validator.ts +18 -46
  50. package/src/validators.ts +203 -0
  51. package/test/creator.test.ts +4 -6
  52. package/test/gtin-creator.ts +6 -2
  53. package/test/gtin-validator.test.ts +6 -9
  54. package/test/identifier-creator.ts +5 -4
  55. package/test/identifier-validator.ts +2 -2
  56. package/test/non-gtin-numeric-identifier-creator.ts +9 -93
  57. package/test/non-gtin-numeric-identifier-validator.ts +2 -2
  58. package/test/non-numeric-identifier-creator.ts +93 -0
  59. package/test/non-numeric-identifier-validator.ts +2 -2
  60. package/test/numeric-identifier-creator.ts +11 -5
  61. package/test/numeric-identifier-validator.ts +4 -8
  62. package/test/prefix-manager.test.ts +1 -1
  63. package/test/serializable-numeric-identifier-creator.ts +11 -3
  64. package/test/serializable-numeric-identifier-validator.ts +2 -2
  65. package/test/validator.test.ts +63 -39
  66. package/tsup.config.ts +3 -0
  67. package/typedoc.json +1 -3
  68. package/dist/character-set.d.ts +0 -22
  69. package/dist/character-set.d.ts.map +0 -1
  70. package/dist/character-set.js +0 -36
  71. package/dist/character-set.js.map +0 -1
  72. package/dist/check.d.ts +0 -81
  73. package/dist/check.d.ts.map +0 -1
  74. package/dist/check.js +0 -218
  75. package/dist/check.js.map +0 -1
  76. package/dist/gtin-creator.d.ts +0 -68
  77. package/dist/gtin-creator.d.ts.map +0 -1
  78. package/dist/gtin-creator.js +0 -158
  79. package/dist/gtin-creator.js.map +0 -1
  80. package/dist/gtin-validator.d.ts +0 -202
  81. package/dist/gtin-validator.d.ts.map +0 -1
  82. package/dist/gtin-validator.js +0 -470
  83. package/dist/gtin-validator.js.map +0 -1
  84. package/dist/identifier-creator.d.ts +0 -72
  85. package/dist/identifier-creator.d.ts.map +0 -1
  86. package/dist/identifier-creator.js +0 -50
  87. package/dist/identifier-creator.js.map +0 -1
  88. package/dist/identifier-type.d.ts +0 -58
  89. package/dist/identifier-type.d.ts.map +0 -1
  90. package/dist/identifier-type.js +0 -54
  91. package/dist/identifier-type.js.map +0 -1
  92. package/dist/identifier-validator.d.ts +0 -174
  93. package/dist/identifier-validator.d.ts.map +0 -1
  94. package/dist/identifier-validator.js +0 -145
  95. package/dist/identifier-validator.js.map +0 -1
  96. package/dist/index.d.ts.map +0 -1
  97. package/dist/locale/en/locale-resources.d.ts +0 -43
  98. package/dist/locale/en/locale-resources.d.ts.map +0 -1
  99. package/dist/locale/en/locale-resources.js +0 -42
  100. package/dist/locale/en/locale-resources.js.map +0 -1
  101. package/dist/locale/fr/locale-resources.d.ts +0 -43
  102. package/dist/locale/fr/locale-resources.d.ts.map +0 -1
  103. package/dist/locale/fr/locale-resources.js +0 -42
  104. package/dist/locale/fr/locale-resources.js.map +0 -1
  105. package/dist/locale/i18n.d.ts +0 -27
  106. package/dist/locale/i18n.d.ts.map +0 -1
  107. package/dist/locale/i18n.js +0 -37
  108. package/dist/locale/i18n.js.map +0 -1
  109. package/dist/non-gtin-numeric-identifier-creator.d.ts +0 -30
  110. package/dist/non-gtin-numeric-identifier-creator.d.ts.map +0 -1
  111. package/dist/non-gtin-numeric-identifier-creator.js +0 -30
  112. package/dist/non-gtin-numeric-identifier-creator.js.map +0 -1
  113. package/dist/non-gtin-numeric-identifier-validator.d.ts +0 -41
  114. package/dist/non-gtin-numeric-identifier-validator.d.ts.map +0 -1
  115. package/dist/non-gtin-numeric-identifier-validator.js +0 -40
  116. package/dist/non-gtin-numeric-identifier-validator.js.map +0 -1
  117. package/dist/non-numeric-identifier-creator.d.ts +0 -55
  118. package/dist/non-numeric-identifier-creator.d.ts.map +0 -1
  119. package/dist/non-numeric-identifier-creator.js +0 -93
  120. package/dist/non-numeric-identifier-creator.js.map +0 -1
  121. package/dist/non-numeric-identifier-validator.d.ts +0 -78
  122. package/dist/non-numeric-identifier-validator.d.ts.map +0 -1
  123. package/dist/non-numeric-identifier-validator.js +0 -95
  124. package/dist/non-numeric-identifier-validator.js.map +0 -1
  125. package/dist/numeric-identifier-creator.d.ts +0 -121
  126. package/dist/numeric-identifier-creator.d.ts.map +0 -1
  127. package/dist/numeric-identifier-creator.js.map +0 -1
  128. package/dist/numeric-identifier-validator.d.ts +0 -76
  129. package/dist/numeric-identifier-validator.d.ts.map +0 -1
  130. package/dist/numeric-identifier-validator.js +0 -84
  131. package/dist/numeric-identifier-validator.js.map +0 -1
  132. package/dist/prefix-manager.d.ts +0 -224
  133. package/dist/prefix-manager.d.ts.map +0 -1
  134. package/dist/prefix-manager.js +0 -369
  135. package/dist/prefix-manager.js.map +0 -1
  136. package/dist/prefix-provider.d.ts +0 -27
  137. package/dist/prefix-provider.d.ts.map +0 -1
  138. package/dist/prefix-provider.js +0 -2
  139. package/dist/prefix-provider.js.map +0 -1
  140. package/dist/prefix-type.d.ts +0 -22
  141. package/dist/prefix-type.d.ts.map +0 -1
  142. package/dist/prefix-type.js +0 -18
  143. package/dist/prefix-type.js.map +0 -1
  144. package/dist/prefix-validator.d.ts +0 -58
  145. package/dist/prefix-validator.d.ts.map +0 -1
  146. package/dist/prefix-validator.js +0 -154
  147. package/dist/prefix-validator.js.map +0 -1
  148. package/dist/serializable-numeric-identifier-creator.d.ts +0 -86
  149. package/dist/serializable-numeric-identifier-creator.d.ts.map +0 -1
  150. package/dist/serializable-numeric-identifier-creator.js +0 -116
  151. package/dist/serializable-numeric-identifier-creator.js.map +0 -1
  152. package/dist/serializable-numeric-identifier-validator.d.ts +0 -79
  153. package/dist/serializable-numeric-identifier-validator.d.ts.map +0 -1
  154. package/dist/serializable-numeric-identifier-validator.js +0 -99
  155. package/dist/serializable-numeric-identifier-validator.js.map +0 -1
@@ -1,40 +1,12 @@
1
1
  import { type CharacterSetValidation, NUMERIC_CREATOR } from "@aidc-toolkit/utility";
2
- import { checkDigit, hasValidCheckDigit, isValidPriceOrWeightCheckDigit } from "./check.js";
3
- import { IdentifierTypes } from "./identifier-type.js";
4
- import { i18nextGS1 } from "./locale/i18n.js";
5
- import { AbstractNumericIdentifierValidator, LeaderTypes } from "./numeric-identifier-validator.js";
6
- import { type PrefixType, PrefixTypes } from "./prefix-type.js";
7
- import { PrefixValidator } from "./prefix-validator.js";
8
-
9
- /**
10
- * GTIN types. The numeric values are equal to the lengths of the GTIN types.
11
- */
12
- export const GTINTypes = {
13
- /**
14
- * GTIN-13.
15
- */
16
- GTIN13: 13,
17
-
18
- /**
19
- * GTIN-12.
20
- */
21
- GTIN12: 12,
22
-
23
- /**
24
- * GTIN-8.
25
- */
26
- GTIN8: 8,
27
-
28
- /**
29
- * GTIN-14.
30
- */
31
- GTIN14: 14
32
- } as const;
33
-
34
- /**
35
- * GTIN type.
36
- */
37
- export type GTINType = typeof GTINTypes[keyof typeof GTINTypes];
2
+ import { AbstractNumericIdentifierValidator } from "./abstract-numeric-identifier-validator";
3
+ import { checkDigit, hasValidCheckDigit, isValidPriceOrWeightCheckDigit } from "./check";
4
+ import { IdentifierDescriptors } from "./descriptors";
5
+ import type { GTINDescriptor } from "./gtin-descriptor";
6
+ import { type GTINBaseType, type GTINType, GTINTypes } from "./gtin-type";
7
+ import { i18nextGS1 } from "./locale/i18n";
8
+ import { type PrefixType, PrefixTypes } from "./prefix-type";
9
+ import { PrefixValidator } from "./prefix-validator";
38
10
 
39
11
  /**
40
12
  * Levels at which GTIN is to be validated.
@@ -56,10 +28,15 @@ export const GTINLevels = {
56
28
  OtherThanRetailConsumer: 2
57
29
  } as const;
58
30
 
31
+ /**
32
+ * GTIN level key.
33
+ */
34
+ export type GTINLevelKey = keyof typeof GTINLevels;
35
+
59
36
  /**
60
37
  * GTIN level.
61
38
  */
62
- export type GTINLevel = typeof GTINLevels[keyof typeof GTINLevels];
39
+ export type GTINLevel = typeof GTINLevels[GTINLevelKey];
63
40
 
64
41
  /**
65
42
  * Restricted Circulation Number reference.
@@ -79,7 +56,7 @@ export interface RCNReference {
79
56
  /**
80
57
  * GTIN validator.
81
58
  */
82
- export class GTINValidator extends AbstractNumericIdentifierValidator {
59
+ export class GTINValidator extends AbstractNumericIdentifierValidator<GTINDescriptor> {
83
60
  /**
84
61
  * Validation parameters for optional indicator digit.
85
62
  */
@@ -97,35 +74,30 @@ export class GTINValidator extends AbstractNumericIdentifierValidator {
97
74
  maximumLength: 8
98
75
  };
99
76
 
77
+ /**
78
+ * Prefix type.
79
+ */
80
+ private readonly _prefixType: PrefixType;
81
+
100
82
  /**
101
83
  * Constructor.
102
84
  *
103
- * @param gtinType
104
- * GTIN type.
85
+ * @param gtinBaseType
86
+ * GTIN base type (all except GTIN-14).
105
87
  */
106
- constructor(gtinType: GTINType) {
107
- let prefixType: PrefixType;
108
-
109
- // Determine the prefix type based on the GTIN type.
110
- switch (gtinType) {
111
- case GTINTypes.GTIN13:
112
- prefixType = PrefixTypes.GS1CompanyPrefix;
113
- break;
88
+ constructor(gtinBaseType: GTINBaseType) {
89
+ const identifierDescriptor = IdentifierDescriptors.GTIN[gtinBaseType];
114
90
 
115
- case GTINTypes.GTIN12:
116
- prefixType = PrefixTypes.UPCCompanyPrefix;
117
- break;
118
-
119
- case GTINTypes.GTIN8:
120
- prefixType = PrefixTypes.GS18Prefix;
121
- break;
91
+ super(identifierDescriptor);
122
92
 
123
- default:
124
- // Should never get here.
125
- throw new Error("Not supported");
126
- }
93
+ this._prefixType = identifierDescriptor.prefixType;
94
+ }
127
95
 
128
- super(IdentifierTypes.GTIN, prefixType, gtinType, LeaderTypes.IndicatorDigit);
96
+ /**
97
+ * @inheritDoc
98
+ */
99
+ override get prefixType(): PrefixType {
100
+ return this._prefixType;
129
101
  }
130
102
 
131
103
  /**
@@ -542,23 +514,27 @@ export class GTINValidator extends AbstractNumericIdentifierValidator {
542
514
  /**
543
515
  * GTIN-13 validator.
544
516
  */
517
+ // Defined here because of circular reference.
545
518
  export const GTIN13_VALIDATOR = new GTINValidator(GTINTypes.GTIN13);
546
519
 
547
520
  /**
548
521
  * GTIN-12 validator.
549
522
  */
523
+ // Defined here because of circular reference.
550
524
  export const GTIN12_VALIDATOR = new GTINValidator(GTINTypes.GTIN12);
551
525
 
552
526
  /**
553
527
  * GTIN-8 validator.
554
528
  */
529
+ // Defined here because of circular reference.
555
530
  export const GTIN8_VALIDATOR = new GTINValidator(GTINTypes.GTIN8);
556
531
 
557
532
  /**
558
533
  * GTIN validators indexed by prefix type.
559
534
  */
560
- export const GTIN_VALIDATORS: Record<PrefixType, GTINValidator> = {
561
- [PrefixTypes.GS1CompanyPrefix]: GTIN13_VALIDATOR,
562
- [PrefixTypes.UPCCompanyPrefix]: GTIN12_VALIDATOR,
563
- [PrefixTypes.GS18Prefix]: GTIN8_VALIDATOR
535
+ // Defined here because of circular reference.
536
+ export const GTIN_VALIDATORS: Readonly<Record<GTINBaseType, GTINValidator>> = {
537
+ [GTINTypes.GTIN13]: GTIN13_VALIDATOR,
538
+ [GTINTypes.GTIN12]: GTIN12_VALIDATOR,
539
+ [GTINTypes.GTIN8]: GTIN8_VALIDATOR
564
540
  };
@@ -1,16 +1,20 @@
1
- import type { CharacterSetCreator } from "@aidc-toolkit/utility";
2
- import type { IdentifierType } from "./identifier-type.js";
3
- import type { ContentCharacterSet, IdentifierValidation, IdentifierValidator } from "./identifier-validator.js";
1
+ import type { IdentifierDescriptor } from "./identifier-descriptor";
2
+ import type { IdentifierValidation, IdentifierValidator } from "./identifier-validator";
4
3
  import type { PrefixProvider } from "./prefix-provider";
5
- import type { PrefixType } from "./prefix-type.js";
6
4
 
7
5
  /**
8
6
  * Identifier creator. Creates an identifier based on its definition in section 3 of the {@link
9
- * https://www.gs1.org/genspecs | GS1 General Specifications}.
7
+ * https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}.
10
8
  *
11
- * Keys are created based on a prefix defined in a prefix manager to which the identifier creator is bound.
9
+ * Keys are created based on a prefix defined in a prefix provider to which the identifier creator is bound.
10
+ *
11
+ * @template TIdentifierDescriptor
12
+ * Identifier descriptor type.
13
+ *
14
+ * @template TIdentifierValidation
15
+ * Identifier validation type.
12
16
  */
13
- export interface IdentifierCreator extends IdentifierValidator {
17
+ export interface IdentifierCreator<TIdentifierDescriptor extends IdentifierDescriptor = IdentifierDescriptor, TIdentifierValidation extends IdentifierValidation = IdentifierValidation> extends IdentifierValidator<TIdentifierDescriptor, TIdentifierValidation> {
14
18
  /**
15
19
  * Get the prefix provider to which this identifier creator is bound.
16
20
  */
@@ -27,71 +31,3 @@ export interface IdentifierCreator extends IdentifierValidator {
27
31
  */
28
32
  get referenceLength(): number;
29
33
  }
30
-
31
- /**
32
- * Abstract identifier creator. Implements common functionality for an identifier creator, bound to a
33
- * {@link PrefixProvider}.
34
- */
35
- export abstract class AbstractIdentifierCreator implements IdentifierCreator {
36
- /**
37
- * Prefix provider.
38
- */
39
- private _prefixProvider!: PrefixProvider;
40
-
41
- /**
42
- * Reference length.
43
- */
44
- private _referenceLength!: number;
45
-
46
- /**
47
- * Initialize the prefix manager. This method is in lieu of a constructor due to the mixin architecture.
48
- *
49
- * @param prefixProvider
50
- * Prefix provider.
51
- *
52
- * @param prefix
53
- * Prefix within prefix manager to use to calculate reference length.
54
- *
55
- * @param checkAllowance
56
- * Number of characters to allow for check digit or check character pair.
57
- */
58
- protected init(prefixProvider: PrefixProvider, prefix: string, checkAllowance: number): void {
59
- this._prefixProvider = prefixProvider;
60
-
61
- // Reference length allows for prefix and optionally check digit or check character pair.
62
- this._referenceLength = this.length - prefix.length - checkAllowance;
63
- }
64
-
65
- abstract get identifierType(): IdentifierType;
66
-
67
- abstract get prefixType(): PrefixType;
68
-
69
- abstract get length(): number;
70
-
71
- abstract get referenceCharacterSet(): ContentCharacterSet;
72
-
73
- abstract get referenceCreator(): CharacterSetCreator;
74
-
75
- /**
76
- * @inheritDoc
77
- */
78
- get prefixProvider(): PrefixProvider {
79
- return this._prefixProvider;
80
- }
81
-
82
- /**
83
- * @inheritDoc
84
- */
85
- get prefix(): string {
86
- return this.prefixProvider.gs1CompanyPrefix;
87
- }
88
-
89
- /**
90
- * @inheritDoc
91
- */
92
- get referenceLength(): number {
93
- return this._referenceLength;
94
- }
95
-
96
- abstract validate(identifier: string, validation?: IdentifierValidation): void;
97
- }
@@ -0,0 +1,30 @@
1
+ import type { ContentCharacterSet } from "./content-character-set";
2
+ import type { IdentifierType } from "./identifier-type";
3
+ import type { PrefixType } from "./prefix-type";
4
+
5
+ /**
6
+ * Identifier descriptor. Instantiations of this type are used to parameterize validators and creators.
7
+ */
8
+ export interface IdentifierDescriptor {
9
+ /**
10
+ * Identifier type. Per the GS1 General Specifications, the identifier type determines the remaining properties.
11
+ */
12
+ readonly identifierType: IdentifierType;
13
+
14
+ /**
15
+ * Prefix type supported by the identifier type. For all identifier types except the GTIN, this is a GS1 Company
16
+ * Prefix. For the GTIN, the prefix type determines the length.
17
+ */
18
+ readonly prefixType: PrefixType;
19
+
20
+ /**
21
+ * Length. For numeric identifier types, the length is fixed; for non-numeric identifier types, the length is the
22
+ * maximum.
23
+ */
24
+ readonly length: number;
25
+
26
+ /**
27
+ * Reference character set.
28
+ */
29
+ readonly referenceCharacterSet: ContentCharacterSet;
30
+ }
@@ -63,7 +63,12 @@ export const IdentifierTypes = {
63
63
  GMN: "GMN"
64
64
  } as const;
65
65
 
66
+ /**
67
+ * Identifier type key.
68
+ */
69
+ export type IdentifierTypeKey = keyof typeof IdentifierTypes;
70
+
66
71
  /**
67
72
  * Identifier type.
68
73
  */
69
- export type IdentifierType = typeof IdentifierTypes[keyof typeof IdentifierTypes];
74
+ export type IdentifierType = typeof IdentifierTypes[IdentifierTypeKey];
@@ -1,69 +1,34 @@
1
- import {
2
- type CharacterSetCreator,
3
- NUMERIC_CREATOR,
4
- type StringValidation,
5
- type StringValidator
6
- } from "@aidc-toolkit/utility";
7
- import { AI39_CREATOR, AI82_CREATOR } from "./character-set.js";
8
- import type { IdentifierType } from "./identifier-type.js";
9
- import type { PrefixType } from "./prefix-type.js";
10
- import { PrefixValidator } from "./prefix-validator.js";
11
-
12
- /**
13
- * Character sets supported by the reference portion of an identifier or the serial component of a numeric identifier.
14
- */
15
- export const ContentCharacterSets = {
16
- /**
17
- * Numeric.
18
- */
19
- Numeric: "Numeric",
20
-
21
- /**
22
- * GS1 AI encodable character set 82.
23
- */
24
- AI82: "AI82",
25
-
26
- /**
27
- * GS1 AI encodable character set 39.
28
- */
29
- AI39: "AI39"
30
- } as const;
31
-
32
- /**
33
- * Content character set.
34
- */
35
- export type ContentCharacterSet = typeof ContentCharacterSets[keyof typeof ContentCharacterSets];
1
+ import type { CharacterSetCreator, StringValidation, StringValidator } from "@aidc-toolkit/utility";
2
+ import type { IdentifierDescriptor } from "./identifier-descriptor";
36
3
 
37
4
  /**
38
5
  * Identifier validation parameters.
39
6
  */
40
7
  export interface IdentifierValidation extends StringValidation {
41
- /**
42
- * Position offset within a larger string. Strings are sometimes composed of multiple substrings; this parameter
43
- * ensures that the error notes the proper position in the string.
44
- */
45
- positionOffset?: number | undefined;
46
8
  }
47
9
 
48
10
  /**
49
11
  * Identifier validator. Validates an identifier against its definition in section 3 of the {@link
50
- * https://www.gs1.org/genspecs | GS1 General Specifications}.
12
+ * https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}.
13
+ *
14
+ * @template TIdentifierDescriptor
15
+ * Identifier descriptor type.
51
16
  *
52
17
  * @template TIdentifierValidation
53
18
  * Identifier validation type.
54
19
  */
55
- export interface IdentifierValidator<TIdentifierValidation extends IdentifierValidation = IdentifierValidation> extends StringValidator<TIdentifierValidation> {
20
+ export interface IdentifierValidator<TIdentifierDescriptor extends IdentifierDescriptor = IdentifierDescriptor, TIdentifierValidation extends IdentifierValidation = IdentifierValidation> extends StringValidator<TIdentifierValidation> {
56
21
  /**
57
22
  * Get the identifier type. Per the GS1 General Specifications, the identifier type determines the remaining
58
23
  * properties.
59
24
  */
60
- get identifierType(): IdentifierType;
25
+ get identifierType(): TIdentifierDescriptor["identifierType"];
61
26
 
62
27
  /**
63
- * Get the prefix type supported by the identifier type. For all identifier types except the GTIN, this is
64
- * {@linkcode PrefixTypes.GS1CompanyPrefix}. For the GTIN, the prefix type determines the length.
28
+ * Get the prefix type supported by the identifier type. For all identifier types except the GTIN, this is a GS1
29
+ * Company Prefix. For the GTIN, the prefix type determines the length.
65
30
  */
66
- get prefixType(): PrefixType;
31
+ get prefixType(): TIdentifierDescriptor["prefixType"];
67
32
 
68
33
  /**
69
34
  * Get the length. For numeric identifier types, the length is fixed; for alphanumeric identifier types, the length
@@ -74,7 +39,7 @@ export interface IdentifierValidator<TIdentifierValidation extends IdentifierVal
74
39
  /**
75
40
  * Get the reference character set.
76
41
  */
77
- get referenceCharacterSet(): ContentCharacterSet;
42
+ get referenceCharacterSet(): TIdentifierDescriptor["referenceCharacterSet"];
78
43
 
79
44
  /**
80
45
  * Get the reference creator.
@@ -92,144 +57,3 @@ export interface IdentifierValidator<TIdentifierValidation extends IdentifierVal
92
57
  */
93
58
  validate: (identifier: string, validation?: TIdentifierValidation) => void;
94
59
  }
95
-
96
- /**
97
- * Abstract identifier validator. Implements common functionality for an identifier validator.
98
- */
99
- export abstract class AbstractIdentifierValidator<TIdentifierValidation extends IdentifierValidation = IdentifierValidation> implements IdentifierValidator<TIdentifierValidation> {
100
- private static readonly CHARACTER_SET_CREATORS: Record<ContentCharacterSet, CharacterSetCreator> = {
101
- [ContentCharacterSets.Numeric]: NUMERIC_CREATOR,
102
- [ContentCharacterSets.AI82]: AI82_CREATOR,
103
- [ContentCharacterSets.AI39]: AI39_CREATOR
104
- };
105
-
106
- /**
107
- * Identifier type.
108
- */
109
- private readonly _identifierType: IdentifierType;
110
-
111
- /**
112
- * Prefix type.
113
- */
114
- private readonly _prefixType: PrefixType;
115
-
116
- /**
117
- * Length.
118
- */
119
- private readonly _length: number;
120
-
121
- /**
122
- * Reference character set.
123
- */
124
- private readonly _referenceCharacterSet: ContentCharacterSet;
125
-
126
- /**
127
- * Reference creator.
128
- */
129
- private readonly _referenceCreator: CharacterSetCreator;
130
-
131
- /**
132
- * Get the character set creator for a character set.
133
- *
134
- * @param characterSet
135
- * Character set.
136
- *
137
- * @returns
138
- * Character set creator.
139
- */
140
- protected static creatorFor(characterSet: ContentCharacterSet): CharacterSetCreator {
141
- return AbstractIdentifierValidator.CHARACTER_SET_CREATORS[characterSet];
142
- }
143
-
144
- /**
145
- * Constructor.
146
- *
147
- * @param identifierType
148
- * Identifier type.
149
- *
150
- * @param prefixType
151
- * Prefix type.
152
- *
153
- * @param length
154
- * Length.
155
- *
156
- * @param referenceCharacterSet
157
- * Reference character set.
158
- */
159
- protected constructor(identifierType: IdentifierType, prefixType: PrefixType, length: number, referenceCharacterSet: ContentCharacterSet) {
160
- this._identifierType = identifierType;
161
- this._prefixType = prefixType;
162
- this._length = length;
163
- this._referenceCharacterSet = referenceCharacterSet;
164
- this._referenceCreator = AbstractIdentifierValidator.creatorFor(referenceCharacterSet);
165
- }
166
-
167
- /**
168
- * @inheritDoc
169
- */
170
- get identifierType(): IdentifierType {
171
- return this._identifierType;
172
- }
173
-
174
- /**
175
- * @inheritDoc
176
- */
177
- get prefixType(): PrefixType {
178
- return this._prefixType;
179
- }
180
-
181
- /**
182
- * @inheritDoc
183
- */
184
- get length(): number {
185
- return this._length;
186
- }
187
-
188
- /**
189
- * @inheritDoc
190
- */
191
- get referenceCharacterSet(): ContentCharacterSet {
192
- return this._referenceCharacterSet;
193
- }
194
-
195
- /**
196
- * @inheritDoc
197
- */
198
- get referenceCreator(): CharacterSetCreator {
199
- return this._referenceCreator;
200
- }
201
-
202
- /**
203
- * Pad an identifier on the left with zero-value character for validation purposes. This is done to align an
204
- * identifier with a position offset for any error message that may be thrown by the reference validator.
205
- *
206
- * @param identifier
207
- * Identifier.
208
- *
209
- * @param validation
210
- * Identifier validation parameters.
211
- *
212
- * @returns
213
- * Padded identifier.
214
- */
215
- protected padIdentifier(identifier: string, validation: IdentifierValidation | undefined): string {
216
- // Identifier is returned as is if position offset is undefined.
217
- return validation?.positionOffset === undefined ? identifier : this.referenceCreator.character(0).repeat(validation.positionOffset).concat(identifier);
218
- }
219
-
220
- /**
221
- * Validate the prefix within an identifier.
222
- *
223
- * @param partialIdentifier
224
- * Partial identifier.
225
- *
226
- * @param positionOffset
227
- * Position offset within a larger string.
228
- */
229
- protected validatePrefix(partialIdentifier: string, positionOffset?: number): void {
230
- // Delegate to prefix validator with support for U.P.C. Company Prefix but not GS1-8 Prefix.
231
- PrefixValidator.validate(this.prefixType, true, false, partialIdentifier, true, this.referenceCharacterSet === ContentCharacterSets.Numeric, positionOffset);
232
- }
233
-
234
- abstract validate(identifier: string, validation?: TIdentifierValidation): void;
235
- }
package/src/index.ts CHANGED
@@ -14,22 +14,46 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- export * from "./locale/i18n.js";
18
- export * from "./character-set.js";
19
- export * from "./check.js";
20
- export * from "./prefix-type.js";
21
- export * from "./prefix-validator.js";
22
- export * from "./identifier-type.js";
23
- export * from "./identifier-validator.js";
24
- export * from "./numeric-identifier-validator.js";
25
- export * from "./gtin-validator.js";
26
- export * from "./non-gtin-numeric-identifier-validator.js";
27
- export * from "./serializable-numeric-identifier-validator.js";
28
- export * from "./non-numeric-identifier-validator.js";
29
- export * from "./identifier-creator.js";
30
- export * from "./numeric-identifier-creator.js";
31
- export * from "./gtin-creator.js";
32
- export * from "./non-gtin-numeric-identifier-creator.js";
33
- export * from "./serializable-numeric-identifier-creator.js";
34
- export * from "./non-numeric-identifier-creator.js";
35
- export * from "./prefix-manager.js";
17
+ export * from "./locale/i18n";
18
+
19
+ export * from "./character-set";
20
+
21
+ export * from "./check";
22
+
23
+ export * from "./prefix-type";
24
+ export * from "./prefix-validator";
25
+
26
+ export * from "./content-character-set";
27
+
28
+ export * from "./identifier-type";
29
+ export * from "./numeric-identifier-type";
30
+ export * from "./gtin-type";
31
+ export type * from "./non-gtin-numeric-identifier-type";
32
+ export type * from "./serializable-numeric-identifier-type";
33
+ export type * from "./non-numeric-identifier-type";
34
+
35
+ export type * from "./identifier-descriptor";
36
+ export type * from "./numeric-identifier-descriptor";
37
+ export type * from "./gtin-descriptor";
38
+ export type * from "./non-gtin-numeric-identifier-descriptor";
39
+ export type * from "./serializable-numeric-identifier-descriptor";
40
+ export type * from "./non-numeric-identifier-descriptor";
41
+ export * from "./descriptors";
42
+
43
+ export type * from "./identifier-validator";
44
+ export type * from "./numeric-identifier-validator";
45
+ export { GTINLevels, type GTINLevel, type RCNReference, GTINValidator } from "./gtin-validator";
46
+ export * from "./non-gtin-numeric-identifier-validator";
47
+ export * from "./serializable-numeric-identifier-validator";
48
+ export * from "./non-numeric-identifier-validator";
49
+ export * from "./validators";
50
+
51
+ export type * from "./identifier-creator";
52
+ export type * from "./numeric-identifier-creator";
53
+ export * from "./gtin-creator";
54
+ export * from "./non-gtin-numeric-identifier-creator";
55
+ export * from "./serializable-numeric-identifier-creator";
56
+ export * from "./non-numeric-identifier-creator";
57
+ export * from "./creators";
58
+
59
+ export * from "./prefix-manager";
@@ -30,7 +30,6 @@ export default {
30
30
  gs1CompanyPrefix: "GS1 Company Prefix",
31
31
  upcCompanyPrefix: "U.P.C. Company Prefix",
32
32
  gs18Prefix: "GS1-8 Prefix",
33
- invalidPrefixType: "Invalid prefix type",
34
33
  gs1CompanyPrefixCantStartWith0: "GS1 Company Prefix can't start with \"0\"",
35
34
  gs1CompanyPrefixCantStartWith00000: "GS1 Company Prefix can't start with \"00000\"",
36
35
  gs1CompanyPrefixCantStartWith000000: "GS1 Company Prefix can't start with \"000000\"",
@@ -30,7 +30,6 @@ export default {
30
30
  gs1CompanyPrefix: "Préfixe de l'entreprise GS1",
31
31
  upcCompanyPrefix: "Préfixe de l'entreprise U.P.C.",
32
32
  gs18Prefix: "Préfixe GS1-8",
33
- invalidPrefixType: "Type de préfixe invalide",
34
33
  gs1CompanyPrefixCantStartWith0: "Le préfixe de l'entreprise GS1 ne peut pas commencer par \"0\"",
35
34
  gs1CompanyPrefixCantStartWith00000: "Le préfixe de l'entreprise GS1 ne peut pas commencer par \"00000\"",
36
35
  gs1CompanyPrefixCantStartWith000000: "Le préfixe de l'entreprise GS1 ne peut pas commencer par \"000000\"",
@@ -1,8 +1,8 @@
1
- import { i18nAssertValidResources, i18nCoreInit, type I18nEnvironment } from "@aidc-toolkit/core";
1
+ import { i18nCoreInit, type I18nEnvironment } from "@aidc-toolkit/core";
2
2
  import { i18nUtilityInit, utilityResources } from "@aidc-toolkit/utility";
3
3
  import i18next, { type i18n, type Resource } from "i18next";
4
- import enLocaleResources from "./en/locale-resources.js";
5
- import frLocaleResources from "./fr/locale-resources.js";
4
+ import enLocaleResources from "./en/locale-resources";
5
+ import frLocaleResources from "./fr/locale-resources";
6
6
 
7
7
  export const gs1NS = "aidct_gs1";
8
8
 
@@ -11,8 +11,6 @@ export const gs1NS = "aidct_gs1";
11
11
  */
12
12
  export type GS1LocaleResources = typeof enLocaleResources;
13
13
 
14
- i18nAssertValidResources(enLocaleResources, "fr", frLocaleResources);
15
-
16
14
  /**
17
15
  * GS1 resources.
18
16
  */
@@ -1,5 +1,5 @@
1
1
  import type { UtilityLocaleResources } from "@aidc-toolkit/utility";
2
- import type { GS1LocaleResources } from "./i18n.js";
2
+ import type { GS1LocaleResources } from "./i18n";
3
3
 
4
4
  /**
5
5
  * Internationalization module.