@aidc-toolkit/gs1 1.0.24-beta → 1.0.26-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 (240) hide show
  1. package/dist/abstract-identifier-creator.d.ts +75 -0
  2. package/dist/abstract-identifier-creator.d.ts.map +1 -0
  3. package/dist/abstract-identifier-creator.js +56 -0
  4. package/dist/abstract-identifier-creator.js.map +1 -0
  5. package/dist/abstract-identifier-validator.d.ts +95 -0
  6. package/dist/abstract-identifier-validator.d.ts.map +1 -0
  7. package/dist/abstract-identifier-validator.js +123 -0
  8. package/dist/abstract-identifier-validator.js.map +1 -0
  9. package/dist/abstract-numeric-identifier-creator.d.ts +92 -0
  10. package/dist/abstract-numeric-identifier-creator.d.ts.map +1 -0
  11. package/dist/abstract-numeric-identifier-creator.js +137 -0
  12. package/dist/abstract-numeric-identifier-creator.js.map +1 -0
  13. package/dist/abstract-numeric-identifier-validator.d.ts +35 -0
  14. package/dist/abstract-numeric-identifier-validator.d.ts.map +1 -0
  15. package/dist/abstract-numeric-identifier-validator.js +61 -0
  16. package/dist/abstract-numeric-identifier-validator.js.map +1 -0
  17. package/dist/character-set.d.ts +27 -0
  18. package/dist/character-set.d.ts.map +1 -0
  19. package/dist/character-set.js +50 -0
  20. package/dist/character-set.js.map +1 -0
  21. package/dist/check.d.ts +81 -0
  22. package/dist/check.d.ts.map +1 -0
  23. package/dist/check.js +218 -0
  24. package/dist/check.js.map +1 -0
  25. package/dist/content-character-set.d.ts +26 -0
  26. package/dist/content-character-set.d.ts.map +1 -0
  27. package/dist/content-character-set.js +18 -0
  28. package/dist/content-character-set.js.map +1 -0
  29. package/dist/creators.d.ts +81 -0
  30. package/dist/creators.d.ts.map +1 -0
  31. package/dist/creators.js +62 -0
  32. package/dist/creators.js.map +1 -0
  33. package/dist/descriptors.d.ts +96 -0
  34. package/dist/descriptors.d.ts.map +1 -0
  35. package/dist/descriptors.js +266 -0
  36. package/dist/descriptors.js.map +1 -0
  37. package/dist/gtin-creator.d.ts +69 -0
  38. package/dist/gtin-creator.d.ts.map +1 -0
  39. package/dist/gtin-creator.js +159 -0
  40. package/dist/gtin-creator.js.map +1 -0
  41. package/dist/gtin-descriptor.d.ts +17 -0
  42. package/dist/gtin-descriptor.d.ts.map +1 -0
  43. package/dist/gtin-descriptor.js +2 -0
  44. package/dist/gtin-descriptor.js.map +1 -0
  45. package/dist/gtin-type.d.ts +39 -0
  46. package/dist/gtin-type.d.ts.map +1 -0
  47. package/dist/gtin-type.js +31 -0
  48. package/dist/gtin-type.js.map +1 -0
  49. package/dist/gtin-validator.d.ts +191 -0
  50. package/dist/gtin-validator.d.ts.map +1 -0
  51. package/dist/gtin-validator.js +450 -0
  52. package/dist/gtin-validator.js.map +1 -0
  53. package/dist/identifier-creator.d.ts +31 -0
  54. package/dist/identifier-creator.d.ts.map +1 -0
  55. package/dist/identifier-creator.js +2 -0
  56. package/dist/identifier-creator.js.map +1 -0
  57. package/dist/identifier-descriptor.d.ts +27 -0
  58. package/dist/identifier-descriptor.d.ts.map +1 -0
  59. package/dist/identifier-descriptor.js +2 -0
  60. package/dist/identifier-descriptor.js.map +1 -0
  61. package/dist/identifier-type.d.ts +62 -0
  62. package/dist/identifier-type.d.ts.map +1 -0
  63. package/dist/identifier-type.js +54 -0
  64. package/dist/identifier-type.js.map +1 -0
  65. package/dist/identifier-validator.d.ts +53 -0
  66. package/dist/identifier-validator.d.ts.map +1 -0
  67. package/dist/identifier-validator.js +2 -0
  68. package/dist/identifier-validator.js.map +1 -0
  69. package/dist/index.d.ts +52 -1588
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +21 -4541
  72. package/dist/index.js.map +1 -1
  73. package/dist/locale/en/locale-resources.d.ts +42 -0
  74. package/dist/locale/en/locale-resources.d.ts.map +1 -0
  75. package/dist/locale/en/locale-resources.js +41 -0
  76. package/dist/locale/en/locale-resources.js.map +1 -0
  77. package/dist/locale/fr/locale-resources.d.ts +42 -0
  78. package/dist/locale/fr/locale-resources.d.ts.map +1 -0
  79. package/dist/locale/fr/locale-resources.js +41 -0
  80. package/dist/locale/fr/locale-resources.js.map +1 -0
  81. package/dist/locale/i18n.d.ts +27 -0
  82. package/dist/locale/i18n.d.ts.map +1 -0
  83. package/dist/locale/i18n.js +36 -0
  84. package/dist/locale/i18n.js.map +1 -0
  85. package/dist/non-gtin-numeric-identifier-creator.d.ts +24 -0
  86. package/dist/non-gtin-numeric-identifier-creator.d.ts.map +1 -0
  87. package/dist/non-gtin-numeric-identifier-creator.js +23 -0
  88. package/dist/non-gtin-numeric-identifier-creator.js.map +1 -0
  89. package/dist/non-gtin-numeric-identifier-descriptor.d.ts +22 -0
  90. package/dist/non-gtin-numeric-identifier-descriptor.d.ts.map +1 -0
  91. package/dist/non-gtin-numeric-identifier-descriptor.js +2 -0
  92. package/dist/non-gtin-numeric-identifier-descriptor.js.map +1 -0
  93. package/dist/non-gtin-numeric-identifier-type.d.ts +7 -0
  94. package/dist/non-gtin-numeric-identifier-type.d.ts.map +1 -0
  95. package/dist/non-gtin-numeric-identifier-type.js +2 -0
  96. package/dist/non-gtin-numeric-identifier-type.js.map +1 -0
  97. package/dist/non-gtin-numeric-identifier-validator.d.ts +17 -0
  98. package/dist/non-gtin-numeric-identifier-validator.d.ts.map +1 -0
  99. package/dist/non-gtin-numeric-identifier-validator.js +17 -0
  100. package/dist/non-gtin-numeric-identifier-validator.js.map +1 -0
  101. package/dist/non-numeric-identifier-creator.d.ts +45 -0
  102. package/dist/non-numeric-identifier-creator.d.ts.map +1 -0
  103. package/dist/non-numeric-identifier-creator.js +84 -0
  104. package/dist/non-numeric-identifier-creator.js.map +1 -0
  105. package/dist/non-numeric-identifier-descriptor.d.ts +26 -0
  106. package/dist/non-numeric-identifier-descriptor.d.ts.map +1 -0
  107. package/dist/non-numeric-identifier-descriptor.js +2 -0
  108. package/dist/non-numeric-identifier-descriptor.js.map +1 -0
  109. package/dist/non-numeric-identifier-type.d.ts +7 -0
  110. package/dist/non-numeric-identifier-type.d.ts.map +1 -0
  111. package/dist/non-numeric-identifier-type.js +2 -0
  112. package/dist/non-numeric-identifier-type.js.map +1 -0
  113. package/dist/non-numeric-identifier-validator.d.ts +49 -0
  114. package/dist/non-numeric-identifier-validator.d.ts.map +1 -0
  115. package/dist/non-numeric-identifier-validator.js +69 -0
  116. package/dist/non-numeric-identifier-validator.js.map +1 -0
  117. package/dist/numeric-identifier-creator.d.ts +53 -0
  118. package/dist/numeric-identifier-creator.d.ts.map +1 -0
  119. package/dist/numeric-identifier-creator.js +2 -0
  120. package/dist/numeric-identifier-creator.js.map +1 -0
  121. package/dist/numeric-identifier-descriptor.d.ts +21 -0
  122. package/dist/numeric-identifier-descriptor.d.ts.map +1 -0
  123. package/dist/numeric-identifier-descriptor.js +2 -0
  124. package/dist/numeric-identifier-descriptor.js.map +1 -0
  125. package/dist/numeric-identifier-type.d.ts +31 -0
  126. package/dist/numeric-identifier-type.d.ts.map +1 -0
  127. package/dist/numeric-identifier-type.js +18 -0
  128. package/dist/numeric-identifier-type.js.map +1 -0
  129. package/dist/numeric-identifier-validator.d.ts +24 -0
  130. package/dist/numeric-identifier-validator.d.ts.map +1 -0
  131. package/dist/numeric-identifier-validator.js +2 -0
  132. package/dist/numeric-identifier-validator.js.map +1 -0
  133. package/dist/prefix-manager.d.ts +232 -0
  134. package/dist/prefix-manager.d.ts.map +1 -0
  135. package/dist/prefix-manager.js +334 -0
  136. package/dist/prefix-manager.js.map +1 -0
  137. package/dist/prefix-provider.d.ts +27 -0
  138. package/dist/prefix-provider.d.ts.map +1 -0
  139. package/dist/prefix-provider.js +2 -0
  140. package/dist/prefix-provider.js.map +1 -0
  141. package/dist/prefix-type.d.ts +26 -0
  142. package/dist/prefix-type.d.ts.map +1 -0
  143. package/dist/prefix-type.js +18 -0
  144. package/dist/prefix-type.js.map +1 -0
  145. package/dist/prefix-validator.d.ts +70 -0
  146. package/dist/prefix-validator.d.ts.map +1 -0
  147. package/dist/prefix-validator.js +208 -0
  148. package/dist/prefix-validator.js.map +1 -0
  149. package/dist/serializable-numeric-identifier-creator.d.ts +76 -0
  150. package/dist/serializable-numeric-identifier-creator.d.ts.map +1 -0
  151. package/dist/serializable-numeric-identifier-creator.js +107 -0
  152. package/dist/serializable-numeric-identifier-creator.js.map +1 -0
  153. package/dist/serializable-numeric-identifier-descriptor.d.ts +26 -0
  154. package/dist/serializable-numeric-identifier-descriptor.d.ts.map +1 -0
  155. package/dist/serializable-numeric-identifier-descriptor.js +2 -0
  156. package/dist/serializable-numeric-identifier-descriptor.js.map +1 -0
  157. package/dist/serializable-numeric-identifier-type.d.ts +6 -0
  158. package/dist/serializable-numeric-identifier-type.d.ts.map +1 -0
  159. package/dist/serializable-numeric-identifier-type.js +2 -0
  160. package/dist/serializable-numeric-identifier-type.js.map +1 -0
  161. package/dist/serializable-numeric-identifier-validator.d.ts +56 -0
  162. package/dist/serializable-numeric-identifier-validator.d.ts.map +1 -0
  163. package/dist/serializable-numeric-identifier-validator.js +77 -0
  164. package/dist/serializable-numeric-identifier-validator.js.map +1 -0
  165. package/dist/validators.d.ts +96 -0
  166. package/dist/validators.d.ts.map +1 -0
  167. package/dist/validators.js +140 -0
  168. package/dist/validators.js.map +1 -0
  169. package/package.json +12 -8
  170. package/src/abstract-identifier-creator.ts +97 -0
  171. package/src/abstract-identifier-validator.ts +140 -0
  172. package/src/abstract-numeric-identifier-creator.ts +168 -0
  173. package/src/abstract-numeric-identifier-validator.ts +69 -0
  174. package/src/character-set.ts +10 -10
  175. package/src/check.ts +9 -9
  176. package/src/content-character-set.ts +29 -0
  177. package/src/creators.ts +113 -0
  178. package/src/descriptors.ts +332 -0
  179. package/src/gtin-creator.ts +10 -9
  180. package/src/gtin-descriptor.ts +18 -0
  181. package/src/gtin-type.ts +50 -0
  182. package/src/gtin-validator.ts +40 -64
  183. package/src/identifier-creator.ts +12 -76
  184. package/src/identifier-descriptor.ts +30 -0
  185. package/src/identifier-type.ts +6 -1
  186. package/src/identifier-validator.ts +12 -188
  187. package/src/index.ts +44 -19
  188. package/src/locale/en/locale-resources.ts +0 -1
  189. package/src/locale/fr/locale-resources.ts +0 -1
  190. package/src/locale/i18n.ts +3 -3
  191. package/src/locale/i18next.d.ts +1 -1
  192. package/src/non-gtin-numeric-identifier-creator.ts +7 -13
  193. package/src/non-gtin-numeric-identifier-descriptor.ts +24 -0
  194. package/src/non-gtin-numeric-identifier-type.ts +7 -0
  195. package/src/non-gtin-numeric-identifier-validator.ts +8 -42
  196. package/src/non-numeric-identifier-creator.ts +9 -19
  197. package/src/non-numeric-identifier-descriptor.ts +29 -0
  198. package/src/non-numeric-identifier-type.ts +7 -0
  199. package/src/non-numeric-identifier-validator.ts +17 -55
  200. package/src/numeric-identifier-creator.ts +20 -163
  201. package/src/numeric-identifier-descriptor.ts +23 -0
  202. package/src/numeric-identifier-type.ts +44 -0
  203. package/src/numeric-identifier-validator.ts +13 -116
  204. package/src/prefix-manager.ts +94 -152
  205. package/src/prefix-provider.ts +3 -3
  206. package/src/prefix-type.ts +6 -1
  207. package/src/prefix-validator.ts +143 -81
  208. package/src/serializable-numeric-identifier-creator.ts +6 -16
  209. package/src/serializable-numeric-identifier-descriptor.ts +29 -0
  210. package/src/serializable-numeric-identifier-type.ts +9 -0
  211. package/src/serializable-numeric-identifier-validator.ts +18 -46
  212. package/src/validators.ts +203 -0
  213. package/test/check.test.ts +1 -1
  214. package/test/creator.test.ts +5 -7
  215. package/test/gtin-creator.ts +6 -2
  216. package/test/gtin-validator.test.ts +7 -10
  217. package/test/identifier-creator.ts +6 -5
  218. package/test/identifier-validator.ts +2 -2
  219. package/test/non-gtin-numeric-identifier-creator.ts +9 -93
  220. package/test/non-gtin-numeric-identifier-validator.ts +3 -3
  221. package/test/non-numeric-identifier-creator.ts +93 -0
  222. package/test/non-numeric-identifier-validator.ts +3 -3
  223. package/test/numeric-identifier-creator.ts +11 -5
  224. package/test/numeric-identifier-validator.ts +5 -9
  225. package/test/prefix-manager.test.ts +2 -2
  226. package/test/serializable-numeric-identifier-creator.ts +11 -3
  227. package/test/serializable-numeric-identifier-validator.ts +3 -3
  228. package/test/setup.ts +1 -1
  229. package/test/sparse.test.ts +1 -1
  230. package/test/utility.ts +1 -1
  231. package/test/validator.test.ts +64 -40
  232. package/test/variable-measure-rcn.test.ts +1 -1
  233. package/tsconfig-config.json +4 -0
  234. package/tsconfig-src.json +8 -0
  235. package/tsconfig-test.json +9 -0
  236. package/tsconfig.json +12 -1
  237. package/tsup.config.ts +3 -2
  238. package/dist/index.cjs +0 -4624
  239. package/dist/index.cjs.map +0 -1
  240. package/dist/index.d.cts +0 -1588
@@ -0,0 +1,30 @@
1
+ import type { ContentCharacterSet } from "./content-character-set.js";
2
+ import type { IdentifierType } from "./identifier-type.js";
3
+ import type { PrefixType } from "./prefix-type.js";
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";
8
- import type { IdentifierType } from "./identifier-type";
9
- import type { PrefixType } from "./prefix-type";
10
- import { PrefixValidator } from "./prefix-validator";
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.js";
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,47 @@
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";
18
- export * from "./character-set";
19
- export * from "./check";
20
- export * from "./prefix-type";
21
- export * from "./prefix-validator";
22
- export * from "./identifier-type";
23
- export * from "./identifier-validator";
24
- export * from "./numeric-identifier-validator";
25
- export * from "./gtin-validator";
26
- export * from "./non-gtin-numeric-identifier-validator";
27
- export * from "./serializable-numeric-identifier-validator";
28
- export * from "./non-numeric-identifier-validator";
29
- export * from "./identifier-creator";
30
- export * from "./numeric-identifier-creator";
31
- export * from "./gtin-creator";
32
- export * from "./non-gtin-numeric-identifier-creator";
33
- export * from "./serializable-numeric-identifier-creator";
34
- export * from "./non-numeric-identifier-creator";
35
- export * from "./prefix-manager";
17
+ export * from "./locale/i18n.js";
18
+
19
+ export * from "./character-set.js";
20
+
21
+ export * from "./check.js";
22
+
23
+ export * from "./prefix-type.js";
24
+ export type * from "./prefix-provider.js";
25
+ export * from "./prefix-validator.js";
26
+
27
+ export * from "./content-character-set.js";
28
+
29
+ export * from "./identifier-type.js";
30
+ export * from "./numeric-identifier-type.js";
31
+ export * from "./gtin-type.js";
32
+ export type * from "./non-gtin-numeric-identifier-type.js";
33
+ export type * from "./serializable-numeric-identifier-type.js";
34
+ export type * from "./non-numeric-identifier-type.js";
35
+
36
+ export type * from "./identifier-descriptor.js";
37
+ export type * from "./numeric-identifier-descriptor.js";
38
+ export type * from "./gtin-descriptor.js";
39
+ export type * from "./non-gtin-numeric-identifier-descriptor.js";
40
+ export type * from "./serializable-numeric-identifier-descriptor.js";
41
+ export type * from "./non-numeric-identifier-descriptor.js";
42
+ export * from "./descriptors.js";
43
+
44
+ export type * from "./identifier-validator.js";
45
+ export type * from "./numeric-identifier-validator.js";
46
+ export { GTINLevels, type GTINLevelKey, type GTINLevel, type RCNReference, GTINValidator } from "./gtin-validator.js";
47
+ export * from "./non-gtin-numeric-identifier-validator.js";
48
+ export * from "./serializable-numeric-identifier-validator.js";
49
+ export * from "./non-numeric-identifier-validator.js";
50
+ export * from "./validators.js";
51
+
52
+ export type * from "./identifier-creator.js";
53
+ export type * from "./numeric-identifier-creator.js";
54
+ export * from "./gtin-creator.js";
55
+ export * from "./non-gtin-numeric-identifier-creator.js";
56
+ export * from "./serializable-numeric-identifier-creator.js";
57
+ export * from "./non-numeric-identifier-creator.js";
58
+ export * from "./creators.js";
59
+
60
+ export * from "./prefix-manager.js";
@@ -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
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";
5
- import frLocaleResources from "./fr/locale-resources";
4
+ import enLocaleResources from "./en/locale-resources.js";
5
+ import frLocaleResources from "./fr/locale-resources.js";
6
6
 
7
7
  export const gs1NS = "aidct_gs1";
8
8
 
@@ -23,7 +23,7 @@ export const gs1Resources: Resource = {
23
23
  }
24
24
  };
25
25
 
26
- // Explicit type is necessary to work around bug in type discovery with linked packages.
26
+ // Explicit type is necessary because type can't be inferred without additional references.
27
27
  export const i18nextGS1: i18n = i18next.createInstance();
28
28
 
29
29
  /**
@@ -1,5 +1,5 @@
1
1
  import type { UtilityLocaleResources } from "@aidc-toolkit/utility";
2
- import type { GS1LocaleResources } from "./i18n";
2
+ import type { GS1LocaleResources } from "./i18n.js";
3
3
 
4
4
  /**
5
5
  * Internationalization module.
@@ -1,9 +1,9 @@
1
1
  import { Mixin } from "ts-mixer";
2
- import type { IdentifierType } from "./identifier-type";
3
- import { NonGTINNumericIdentifierValidator } from "./non-gtin-numeric-identifier-validator";
4
- import { AbstractNumericIdentifierCreator } from "./numeric-identifier-creator";
5
- import { type LeaderType, LeaderTypes } from "./numeric-identifier-validator";
6
- import type { PrefixProvider } from "./prefix-provider";
2
+ import { AbstractNumericIdentifierCreator } from "./abstract-numeric-identifier-creator.js";
3
+ import type { NonGTINNumericIdentifierType } from "./non-gtin-numeric-identifier-type.js";
4
+ import { NonGTINNumericIdentifierValidator } from "./non-gtin-numeric-identifier-validator.js";
5
+ import type { PrefixProvider } from "./prefix-provider.js";
6
+ import type { SerializableNumericIdentifierType } from "./serializable-numeric-identifier-type.js";
7
7
 
8
8
  /**
9
9
  * Non-GTIN numeric identifier creator.
@@ -18,15 +18,9 @@ export class NonGTINNumericIdentifierCreator extends Mixin(NonGTINNumericIdentif
18
18
  *
19
19
  * @param identifierType
20
20
  * Identifier type.
21
- *
22
- * @param length
23
- * Length.
24
- *
25
- * @param leaderType
26
- * Leader type.
27
21
  */
28
- constructor(prefixProvider: PrefixProvider, identifierType: IdentifierType, length: number, leaderType: LeaderType = LeaderTypes.None) {
29
- super(identifierType, length, leaderType);
22
+ constructor(prefixProvider: PrefixProvider, identifierType: Exclude<NonGTINNumericIdentifierType, SerializableNumericIdentifierType>) {
23
+ super(identifierType);
30
24
 
31
25
  this.init(prefixProvider, prefixProvider.gs1CompanyPrefix);
32
26
  }
@@ -0,0 +1,24 @@
1
+ import type { NonGTINNumericIdentifierType } from "./non-gtin-numeric-identifier-type.js";
2
+ import type { NumericIdentifierDescriptor } from "./numeric-identifier-descriptor.js";
3
+ import type { LeaderType, LeaderTypes } from "./numeric-identifier-type.js";
4
+ import type { PrefixTypes } from "./prefix-type.js";
5
+
6
+ /**
7
+ * Non-GTIN numeric identifier descriptor.
8
+ */
9
+ export interface NonGTINNumericIdentifierDescriptor extends NumericIdentifierDescriptor {
10
+ /**
11
+ * @inheritDoc
12
+ */
13
+ readonly identifierType: NonGTINNumericIdentifierType;
14
+
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ readonly prefixType: typeof PrefixTypes.GS1CompanyPrefix;
19
+
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ readonly leaderType: Exclude<LeaderType, typeof LeaderTypes.IndicatorDigit>;
24
+ }
@@ -0,0 +1,7 @@
1
+ import type { IdentifierTypes } from "./identifier-type.js";
2
+ import type { NumericIdentifierType } from "./numeric-identifier-type.js";
3
+
4
+ /**
5
+ * Non-GTIN numeric identifier type.
6
+ */
7
+ export type NonGTINNumericIdentifierType = Exclude<NumericIdentifierType, typeof IdentifierTypes.GTIN>;
@@ -1,54 +1,20 @@
1
- import { type IdentifierType, IdentifierTypes } from "./identifier-type";
2
- import {
3
- AbstractNumericIdentifierValidator,
4
- type LeaderType,
5
- LeaderTypes,
6
- type NumericIdentifierType
7
- } from "./numeric-identifier-validator";
8
- import { PrefixTypes } from "./prefix-type";
9
-
10
- /**
11
- * Non-GTIN numeric identifier type.
12
- */
13
- export type NonGTINNumericIdentifierType = Exclude<NumericIdentifierType, typeof IdentifierTypes.GTIN>;
1
+ import { AbstractNumericIdentifierValidator } from "./abstract-numeric-identifier-validator.js";
2
+ import { IdentifierDescriptors } from "./descriptors.js";
3
+ import type { NonGTINNumericIdentifierDescriptor } from "./non-gtin-numeric-identifier-descriptor.js";
4
+ import type { NonGTINNumericIdentifierType } from "./non-gtin-numeric-identifier-type.js";
5
+ import type { SerializableNumericIdentifierType } from "./serializable-numeric-identifier-type.js";
14
6
 
15
7
  /**
16
8
  * Non-GTIN numeric identifier validator.
17
9
  */
18
- export class NonGTINNumericIdentifierValidator extends AbstractNumericIdentifierValidator {
10
+ export class NonGTINNumericIdentifierValidator extends AbstractNumericIdentifierValidator<NonGTINNumericIdentifierDescriptor> {
19
11
  /**
20
12
  * Constructor.
21
13
  *
22
14
  * @param identifierType
23
15
  * Identifier type.
24
- *
25
- * @param length
26
- * Length.
27
- *
28
- * @param leaderType
29
- * Leader type.
30
16
  */
31
- constructor(identifierType: IdentifierType, length: number, leaderType: LeaderType = LeaderTypes.None) {
32
- super(identifierType, PrefixTypes.GS1CompanyPrefix, length, leaderType);
17
+ constructor(identifierType: Exclude<NonGTINNumericIdentifierType, SerializableNumericIdentifierType>) {
18
+ super(IdentifierDescriptors[identifierType]);
33
19
  }
34
20
  }
35
-
36
- /**
37
- * GLN validator.
38
- */
39
- export const GLN_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.GLN, 13);
40
-
41
- /**
42
- * SSCC validator.
43
- */
44
- export const SSCC_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.SSCC, 18, LeaderTypes.ExtensionDigit);
45
-
46
- /**
47
- * GSRN validator.
48
- */
49
- export const GSRN_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.GSRN, 18);
50
-
51
- /**
52
- * GSIN validator.
53
- */
54
- export const GSIN_VALIDATOR = new NonGTINNumericIdentifierValidator(IdentifierTypes.GSIN, 17);
@@ -5,13 +5,12 @@ import {
5
5
  type TransformerOutput
6
6
  } from "@aidc-toolkit/utility";
7
7
  import { Mixin } from "ts-mixer";
8
- import { checkCharacterPair } from "./check";
9
- import { AbstractIdentifierCreator } from "./identifier-creator";
10
- import type { IdentifierType } from "./identifier-type";
11
- import type { ContentCharacterSet } from "./identifier-validator";
12
- import { i18nextGS1 } from "./locale/i18n";
13
- import { NonNumericIdentifierValidator } from "./non-numeric-identifier-validator";
14
- import type { PrefixProvider } from "./prefix-provider";
8
+ import { AbstractIdentifierCreator } from "./abstract-identifier-creator.js";
9
+ import { checkCharacterPair } from "./check.js";
10
+ import { i18nextGS1 } from "./locale/i18n.js";
11
+ import type { NonNumericIdentifierType } from "./non-numeric-identifier-type.js";
12
+ import { NonNumericIdentifierValidator } from "./non-numeric-identifier-validator.js";
13
+ import type { PrefixProvider } from "./prefix-provider.js";
15
14
 
16
15
  /**
17
16
  * Non-numeric identifier creator.
@@ -31,20 +30,11 @@ export class NonNumericIdentifierCreator extends Mixin(NonNumericIdentifierValid
31
30
  *
32
31
  * @param identifierType
33
32
  * Identifier type.
34
- *
35
- * @param length
36
- * Length.
37
- *
38
- * @param referenceCharacterSet
39
- * Reference character set.
40
- *
41
- * @param requiresCheckCharacterPair
42
- * True if the identifier requires a check character pair.
43
33
  */
44
- constructor(prefixProvider: PrefixProvider, identifierType: IdentifierType, length: number, referenceCharacterSet: ContentCharacterSet, requiresCheckCharacterPair = false) {
45
- super(identifierType, length, referenceCharacterSet, requiresCheckCharacterPair);
34
+ constructor(prefixProvider: PrefixProvider, identifierType: NonNumericIdentifierType) {
35
+ super(identifierType);
46
36
 
47
- this.init(prefixProvider, prefixProvider.gs1CompanyPrefix, 2 * Number(requiresCheckCharacterPair));
37
+ this.init(prefixProvider, prefixProvider.gs1CompanyPrefix, 2 * Number(this.requiresCheckCharacterPair));
48
38
 
49
39
  this._referenceValidation = {
50
40
  minimumLength: 1,
@@ -0,0 +1,29 @@
1
+ import type { ContentCharacterSet, ContentCharacterSets } from "./content-character-set.js";
2
+ import type { IdentifierDescriptor } from "./identifier-descriptor.js";
3
+ import type { NonNumericIdentifierType } from "./non-numeric-identifier-type.js";
4
+ import type { PrefixTypes } from "./prefix-type.js";
5
+
6
+ /**
7
+ * Non-numeric identifier descriptor.
8
+ */
9
+ export interface NonNumericIdentifierDescriptor extends IdentifierDescriptor {
10
+ /**
11
+ * @inheritDoc
12
+ */
13
+ readonly identifierType: NonNumericIdentifierType;
14
+
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ readonly prefixType: typeof PrefixTypes.GS1CompanyPrefix;
19
+
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ readonly referenceCharacterSet: Exclude<ContentCharacterSet, typeof ContentCharacterSets.Numeric>;
24
+
25
+ /**
26
+ * True if identifier requires a check character pair.
27
+ */
28
+ readonly requiresCheckCharacterPair: boolean;
29
+ }
@@ -0,0 +1,7 @@
1
+ import type { IdentifierType } from "./identifier-type.js";
2
+ import type { NumericIdentifierType } from "./numeric-identifier-type.js";
3
+
4
+ /**
5
+ * Non-numeric identifier type.
6
+ */
7
+ export type NonNumericIdentifierType = Exclude<IdentifierType, NumericIdentifierType>;