@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,332 @@
1
+ import { ContentCharacterSets } from "./content-character-set.js";
2
+ import type { GTINDescriptor } from "./gtin-descriptor.js";
3
+ import { type GTINBaseType, GTINTypes } from "./gtin-type.js";
4
+ import type { IdentifierDescriptor } from "./identifier-descriptor.js";
5
+ import { type IdentifierType, IdentifierTypes } from "./identifier-type.js";
6
+ import type { NonGTINNumericIdentifierDescriptor } from "./non-gtin-numeric-identifier-descriptor.js";
7
+ import type { NonGTINNumericIdentifierType } from "./non-gtin-numeric-identifier-type.js";
8
+ import type { NonNumericIdentifierDescriptor } from "./non-numeric-identifier-descriptor.js";
9
+ import type { NonNumericIdentifierType } from "./non-numeric-identifier-type.js";
10
+ import type { NumericIdentifierDescriptor } from "./numeric-identifier-descriptor.js";
11
+ import { LeaderTypes, type NumericIdentifierType } from "./numeric-identifier-type.js";
12
+ import { PrefixTypes } from "./prefix-type.js";
13
+ import type { SerializableNumericIdentifierDescriptor } from "./serializable-numeric-identifier-descriptor.js";
14
+ import type { SerializableNumericIdentifierType } from "./serializable-numeric-identifier-type.js";
15
+
16
+ /**
17
+ * GTIN-13 descriptor.
18
+ */
19
+ const GTIN13_DESCRIPTOR: GTINDescriptor = {
20
+ identifierType: IdentifierTypes.GTIN,
21
+ prefixType: PrefixTypes.GS1CompanyPrefix,
22
+ length: GTINTypes.GTIN13,
23
+ referenceCharacterSet: ContentCharacterSets.Numeric,
24
+ leaderType: LeaderTypes.IndicatorDigit
25
+ };
26
+
27
+ /**
28
+ * GTIN-12 descriptor.
29
+ */
30
+ const GTIN12_DESCRIPTOR: GTINDescriptor = {
31
+ identifierType: IdentifierTypes.GTIN,
32
+ prefixType: PrefixTypes.UPCCompanyPrefix,
33
+ length: GTINTypes.GTIN12,
34
+ referenceCharacterSet: ContentCharacterSets.Numeric,
35
+ leaderType: LeaderTypes.IndicatorDigit
36
+ };
37
+
38
+ /**
39
+ * GTIN-8 descriptor.
40
+ */
41
+ const GTIN8_DESCRIPTOR: GTINDescriptor = {
42
+ identifierType: IdentifierTypes.GTIN,
43
+ prefixType: PrefixTypes.GS18Prefix,
44
+ length: GTINTypes.GTIN8,
45
+ referenceCharacterSet: ContentCharacterSets.Numeric,
46
+ leaderType: LeaderTypes.IndicatorDigit
47
+ };
48
+
49
+ /**
50
+ * GTIN descriptors indexed by prefix type.
51
+ */
52
+ const GTIN_DESCRIPTORS: Readonly<Record<GTINBaseType, GTINDescriptor>> = {
53
+ [GTINTypes.GTIN13]: GTIN13_DESCRIPTOR,
54
+ [GTINTypes.GTIN12]: GTIN12_DESCRIPTOR,
55
+ [GTINTypes.GTIN8]: GTIN8_DESCRIPTOR
56
+ };
57
+
58
+ /**
59
+ * GLN descriptor.
60
+ */
61
+ const GLN_DESCRIPTOR: NonGTINNumericIdentifierDescriptor = {
62
+ identifierType: IdentifierTypes.GLN,
63
+ prefixType: PrefixTypes.GS1CompanyPrefix,
64
+ length: 13,
65
+ referenceCharacterSet: ContentCharacterSets.Numeric,
66
+ leaderType: LeaderTypes.None
67
+ };
68
+
69
+ /**
70
+ * SSCC descriptor.
71
+ */
72
+ const SSCC_DESCRIPTOR: NonGTINNumericIdentifierDescriptor = {
73
+ identifierType: IdentifierTypes.SSCC,
74
+ prefixType: PrefixTypes.GS1CompanyPrefix,
75
+ length: 18,
76
+ referenceCharacterSet: ContentCharacterSets.Numeric,
77
+ leaderType: LeaderTypes.ExtensionDigit
78
+ };
79
+
80
+ /**
81
+ * GRAI descriptor.
82
+ */
83
+ const GRAI_DESCRIPTOR: SerializableNumericIdentifierDescriptor = {
84
+ identifierType: IdentifierTypes.GRAI,
85
+ prefixType: PrefixTypes.GS1CompanyPrefix,
86
+ length: 13,
87
+ referenceCharacterSet: ContentCharacterSets.Numeric,
88
+ leaderType: LeaderTypes.None,
89
+ serialComponentLength: 16,
90
+ serialComponentCharacterSet: ContentCharacterSets.AI82
91
+ };
92
+
93
+ /**
94
+ * GIAI descriptor.
95
+ */
96
+ const GIAI_DESCRIPTOR: NonNumericIdentifierDescriptor = {
97
+ identifierType: IdentifierTypes.GIAI,
98
+ prefixType: PrefixTypes.GS1CompanyPrefix,
99
+ length: 30,
100
+ referenceCharacterSet: ContentCharacterSets.AI82,
101
+ requiresCheckCharacterPair: false
102
+ };
103
+
104
+ /**
105
+ * GSRN descriptor.
106
+ */
107
+ const GSRN_DESCRIPTOR: NonGTINNumericIdentifierDescriptor = {
108
+ identifierType: IdentifierTypes.GSRN,
109
+ prefixType: PrefixTypes.GS1CompanyPrefix,
110
+ length: 18,
111
+ referenceCharacterSet: ContentCharacterSets.Numeric,
112
+ leaderType: LeaderTypes.None
113
+ };
114
+
115
+ /**
116
+ * GDTI descriptor.
117
+ */
118
+ const GDTI_DESCRIPTOR: SerializableNumericIdentifierDescriptor = {
119
+ identifierType: IdentifierTypes.GDTI,
120
+ prefixType: PrefixTypes.GS1CompanyPrefix,
121
+ length: 13,
122
+ referenceCharacterSet: ContentCharacterSets.Numeric,
123
+ leaderType: LeaderTypes.None,
124
+ serialComponentLength: 17,
125
+ serialComponentCharacterSet: ContentCharacterSets.AI82
126
+ };
127
+
128
+ /**
129
+ * GINC descriptor.
130
+ */
131
+ const GINC_DESCRIPTOR: NonNumericIdentifierDescriptor = {
132
+ identifierType: IdentifierTypes.GINC,
133
+ prefixType: PrefixTypes.GS1CompanyPrefix,
134
+ length: 30,
135
+ referenceCharacterSet: ContentCharacterSets.AI82,
136
+ requiresCheckCharacterPair: false
137
+ };
138
+
139
+ /**
140
+ * GSIN descriptor.
141
+ */
142
+ const GSIN_DESCRIPTOR: NonGTINNumericIdentifierDescriptor = {
143
+ identifierType: IdentifierTypes.GSIN,
144
+ prefixType: PrefixTypes.GS1CompanyPrefix,
145
+ length: 17,
146
+ referenceCharacterSet: ContentCharacterSets.Numeric,
147
+ leaderType: LeaderTypes.None
148
+ };
149
+
150
+ /**
151
+ * GCN descriptor.
152
+ */
153
+ const GCN_DESCRIPTOR: SerializableNumericIdentifierDescriptor = {
154
+ identifierType: IdentifierTypes.GCN,
155
+ prefixType: PrefixTypes.GS1CompanyPrefix,
156
+ length: 13,
157
+ referenceCharacterSet: ContentCharacterSets.Numeric,
158
+ leaderType: LeaderTypes.None,
159
+ serialComponentLength: 12,
160
+ serialComponentCharacterSet: ContentCharacterSets.Numeric
161
+ };
162
+
163
+ /**
164
+ * CPID descriptor.
165
+ */
166
+ const CPID_DESCRIPTOR: NonNumericIdentifierDescriptor = {
167
+ identifierType: IdentifierTypes.CPID,
168
+ prefixType: PrefixTypes.GS1CompanyPrefix,
169
+ length: 30,
170
+ referenceCharacterSet: ContentCharacterSets.AI39,
171
+ requiresCheckCharacterPair: false
172
+ };
173
+
174
+ /**
175
+ * GMN descriptor.
176
+ */
177
+ const GMN_DESCRIPTOR: NonNumericIdentifierDescriptor = {
178
+ identifierType: IdentifierTypes.GMN,
179
+ prefixType: PrefixTypes.GS1CompanyPrefix,
180
+ length: 25,
181
+ referenceCharacterSet: ContentCharacterSets.AI82,
182
+ requiresCheckCharacterPair: true
183
+ };
184
+
185
+ /**
186
+ * Identifier descriptor type based on identifier type type.
187
+ *
188
+ * @template TIdentifierType
189
+ * Identifier type type.
190
+ */
191
+ export type IdentifierTypeDescriptor<TIdentifierType extends IdentifierType> = TIdentifierType extends NonNumericIdentifierType ?
192
+ NonNumericIdentifierDescriptor :
193
+ TIdentifierType extends SerializableNumericIdentifierType ?
194
+ SerializableNumericIdentifierDescriptor :
195
+ TIdentifierType extends NonGTINNumericIdentifierType ?
196
+ NonGTINNumericIdentifierDescriptor :
197
+ TIdentifierType extends typeof IdentifierTypes.GTIN ?
198
+ GTINDescriptor :
199
+ IdentifierDescriptor;
200
+
201
+ /**
202
+ * Identifier descriptors entry type based on identifier type type.
203
+ *
204
+ * @template TIdentifierType
205
+ * Identifier type type.
206
+ */
207
+ export type IdentifierDescriptorsEntry<TIdentifierType extends IdentifierType> = TIdentifierType extends typeof IdentifierTypes.GTIN ?
208
+ Readonly<Record<GTINBaseType, GTINDescriptor>> :
209
+ IdentifierTypeDescriptor<TIdentifierType>;
210
+
211
+ /**
212
+ * Identifier descriptors record type.
213
+ */
214
+ export type IdentifierDescriptorsRecord = {
215
+ [TIdentifierType in IdentifierType]: IdentifierDescriptorsEntry<TIdentifierType>;
216
+ };
217
+
218
+ /**
219
+ * Identifier descriptors for all identifier types.
220
+ */
221
+ export const IdentifierDescriptors: IdentifierDescriptorsRecord = {
222
+ [IdentifierTypes.GTIN]: GTIN_DESCRIPTORS,
223
+ [IdentifierTypes.GLN]: GLN_DESCRIPTOR,
224
+ [IdentifierTypes.SSCC]: SSCC_DESCRIPTOR,
225
+ [IdentifierTypes.GRAI]: GRAI_DESCRIPTOR,
226
+ [IdentifierTypes.GIAI]: GIAI_DESCRIPTOR,
227
+ [IdentifierTypes.GSRN]: GSRN_DESCRIPTOR,
228
+ [IdentifierTypes.GDTI]: GDTI_DESCRIPTOR,
229
+ [IdentifierTypes.GINC]: GINC_DESCRIPTOR,
230
+ [IdentifierTypes.GSIN]: GSIN_DESCRIPTOR,
231
+ [IdentifierTypes.GCN]: GCN_DESCRIPTOR,
232
+ [IdentifierTypes.CPID]: CPID_DESCRIPTOR,
233
+ [IdentifierTypes.GMN]: GMN_DESCRIPTOR
234
+ } as const;
235
+
236
+ /**
237
+ * Determine if identifier descriptors or descriptor is GTIN descriptors.
238
+ *
239
+ * @param identifierDescriptorsOrDescriptor
240
+ * Identifier descriptors or descriptor.
241
+ *
242
+ * @returns
243
+ * True if GTIN descriptors.
244
+ */
245
+ export function isGTINDescriptors(identifierDescriptorsOrDescriptor: IdentifierDescriptorsEntry<IdentifierType>): identifierDescriptorsOrDescriptor is Readonly<Record<GTINBaseType, GTINDescriptor>> {
246
+ return !("identifierType" in identifierDescriptorsOrDescriptor);
247
+ }
248
+
249
+ /**
250
+ * Determine if an array of identifier types includes a given identifier type.
251
+ *
252
+ * @param identifierTypes
253
+ * Identifier types.
254
+ *
255
+ * @param identifierType
256
+ * Identifier type.
257
+ *
258
+ * @returns
259
+ * True if element is included in the array.
260
+ */
261
+ function identifierTypesIncludes(identifierTypes: readonly IdentifierType[], identifierType: IdentifierType): boolean {
262
+ return identifierTypes.includes(identifierType);
263
+ }
264
+
265
+ const NUMERIC_IDENTIFIER_TYPES: readonly NumericIdentifierType[] = [IdentifierTypes.GTIN, IdentifierTypes.GLN, IdentifierTypes.SSCC, IdentifierTypes.GRAI, IdentifierTypes.GSRN, IdentifierTypes.GDTI, IdentifierTypes.GSIN, IdentifierTypes.GCN];
266
+
267
+ /**
268
+ * Determine if identifier descriptor is a numeric identifier descriptor.
269
+ *
270
+ * @param identifierDescriptor
271
+ * Identifier descriptor.
272
+ *
273
+ * @returns
274
+ * True if identifier descriptor is a numeric identifier descriptor.
275
+ */
276
+ export function isNumericIdentifierDescriptor(identifierDescriptor: IdentifierDescriptor): identifierDescriptor is NumericIdentifierDescriptor {
277
+ return identifierTypesIncludes(NUMERIC_IDENTIFIER_TYPES, identifierDescriptor.identifierType);
278
+ }
279
+
280
+ /**
281
+ * Determine if identifier descriptor is a GTIN descriptor.
282
+ *
283
+ * @param identifierDescriptor
284
+ * Identifier descriptor.
285
+ *
286
+ * @returns
287
+ * True if identifier descriptor is a GTIN descriptor.
288
+ */
289
+ export function isGTINDescriptor(identifierDescriptor: IdentifierDescriptor): identifierDescriptor is GTINDescriptor {
290
+ return identifierDescriptor.identifierType === IdentifierTypes.GTIN;
291
+ }
292
+
293
+ /**
294
+ * Determine if identifier descriptor is a non-GTIN numeric identifier descriptor.
295
+ *
296
+ * @param identifierDescriptor
297
+ * Identifier descriptor.
298
+ *
299
+ * @returns
300
+ * True if identifier descriptor is a non-GTIN numeric identifier descriptor.
301
+ */
302
+ export function isNonGTINNumericIdentifierDescriptor(identifierDescriptor: IdentifierDescriptor): identifierDescriptor is NonGTINNumericIdentifierDescriptor {
303
+ return isNumericIdentifierDescriptor(identifierDescriptor) && !isGTINDescriptor(identifierDescriptor);
304
+ }
305
+
306
+ const SERIALIZABLE_NUMERIC_IDENTIFIER_TYPES: readonly SerializableNumericIdentifierType[] = [IdentifierTypes.GRAI, IdentifierTypes.GDTI, IdentifierTypes.GCN];
307
+
308
+ /**
309
+ * Determine if identifier descriptor is a serializable numeric identifier descriptor.
310
+ *
311
+ * @param identifierDescriptor
312
+ * Identifier descriptor.
313
+ *
314
+ * @returns
315
+ * True if identifier descriptor is a serializable numeric identifier descriptor.
316
+ */
317
+ export function isSerializableNumericIdentifierDescriptor(identifierDescriptor: IdentifierDescriptor): identifierDescriptor is SerializableNumericIdentifierDescriptor {
318
+ return identifierTypesIncludes(SERIALIZABLE_NUMERIC_IDENTIFIER_TYPES, identifierDescriptor.identifierType);
319
+ }
320
+
321
+ /**
322
+ * Determine if identifier descriptor is a non-numeric identifier descriptor.
323
+ *
324
+ * @param identifierDescriptor
325
+ * Identifier descriptor.
326
+ *
327
+ * @returns
328
+ * True if identifier descriptor is a non-numeric identifier descriptor.
329
+ */
330
+ export function isNonNumericIdentifierDescriptor(identifierDescriptor: IdentifierDescriptor): identifierDescriptor is NonNumericIdentifierDescriptor {
331
+ return !isNumericIdentifierDescriptor(identifierDescriptor);
332
+ }
@@ -6,11 +6,12 @@ import {
6
6
  type TransformerOutput
7
7
  } from "@aidc-toolkit/utility";
8
8
  import { Mixin } from "ts-mixer";
9
- import { checkDigit, priceOrWeightCheckDigit } from "./check";
10
- import { type GTINType, GTINTypes, GTINValidator } from "./gtin-validator";
11
- import { i18nextGS1 } from "./locale/i18n";
12
- import { AbstractNumericIdentifierCreator } from "./numeric-identifier-creator";
13
- import type { PrefixProvider } from "./prefix-provider";
9
+ import { AbstractNumericIdentifierCreator } from "./abstract-numeric-identifier-creator.js";
10
+ import { checkDigit, priceOrWeightCheckDigit } from "./check.js";
11
+ import { type GTINBaseType, GTINTypes } from "./gtin-type.js";
12
+ import { GTINValidator } from "./gtin-validator.js";
13
+ import { i18nextGS1 } from "./locale/i18n.js";
14
+ import type { PrefixProvider } from "./prefix-provider.js";
14
15
 
15
16
  /**
16
17
  * GTIN creator. Applicable to GTIN-13, GTIN-12, and GTIN-8 types; no applicable to GTIN-14 type.
@@ -32,11 +33,11 @@ export class GTINCreator extends Mixin(GTINValidator, AbstractNumericIdentifierC
32
33
  * @param prefixProvider
33
34
  * Prefix provider.
34
35
  *
35
- * @param gtinType
36
- * GTIN type.
36
+ * @param gtinBaseType
37
+ * GTIN base type (all except GTIN-14).
37
38
  */
38
- constructor(prefixProvider: PrefixProvider, gtinType: GTINType) {
39
- super(gtinType);
39
+ constructor(prefixProvider: PrefixProvider, gtinBaseType: GTINBaseType) {
40
+ super(gtinBaseType);
40
41
 
41
42
  this.init(prefixProvider, prefixProvider.prefix);
42
43
  }
@@ -0,0 +1,18 @@
1
+ import type { IdentifierTypes } from "./identifier-type.js";
2
+ import type { NumericIdentifierDescriptor } from "./numeric-identifier-descriptor.js";
3
+ import type { LeaderTypes } from "./numeric-identifier-type.js";
4
+
5
+ /**
6
+ * GTIN descriptor.
7
+ */
8
+ export interface GTINDescriptor extends NumericIdentifierDescriptor {
9
+ /**
10
+ * @inheritDoc
11
+ */
12
+ readonly identifierType: typeof IdentifierTypes.GTIN;
13
+
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ readonly leaderType: typeof LeaderTypes.IndicatorDigit;
18
+ }
@@ -0,0 +1,50 @@
1
+ import { type PrefixType, PrefixTypes } from "./prefix-type.js";
2
+
3
+ /**
4
+ * GTIN types. The numeric values are equal to the lengths of the GTIN types.
5
+ */
6
+ export const GTINTypes = {
7
+ /**
8
+ * GTIN-13.
9
+ */
10
+ GTIN13: 13,
11
+
12
+ /**
13
+ * GTIN-12.
14
+ */
15
+ GTIN12: 12,
16
+
17
+ /**
18
+ * GTIN-8.
19
+ */
20
+ GTIN8: 8,
21
+
22
+ /**
23
+ * GTIN-14.
24
+ */
25
+ GTIN14: 14
26
+ } as const;
27
+
28
+ /**
29
+ * GTIN type key.
30
+ */
31
+ export type GTINTypeKey = keyof typeof GTINTypes;
32
+
33
+ /**
34
+ * GTIN type.
35
+ */
36
+ export type GTINType = typeof GTINTypes[GTINTypeKey];
37
+
38
+ /**
39
+ * GTIN base type (all except GTIN-14).
40
+ */
41
+ export type GTINBaseType = Exclude<GTINType, typeof GTINTypes.GTIN14>;
42
+
43
+ /**
44
+ * GTIN base types by prefix type. Used to determine the GTIN type supported by a prefix type.
45
+ */
46
+ export const GTIN_BASE_TYPES: Readonly<Record<PrefixType, GTINBaseType>> = {
47
+ [PrefixTypes.GS1CompanyPrefix]: GTINTypes.GTIN13,
48
+ [PrefixTypes.UPCCompanyPrefix]: GTINTypes.GTIN12,
49
+ [PrefixTypes.GS18Prefix]: GTINTypes.GTIN8
50
+ };
@@ -1,40 +1,12 @@
1
1
  import { type CharacterSetValidation, NUMERIC_CREATOR } from "@aidc-toolkit/utility";
2
- import { checkDigit, hasValidCheckDigit, isValidPriceOrWeightCheckDigit } from "./check";
3
- import { IdentifierTypes } from "./identifier-type";
4
- import { i18nextGS1 } from "./locale/i18n";
5
- import { AbstractNumericIdentifierValidator, LeaderTypes } from "./numeric-identifier-validator";
6
- import { type PrefixType, PrefixTypes } from "./prefix-type";
7
- import { PrefixValidator } from "./prefix-validator";
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.js";
3
+ import { checkDigit, hasValidCheckDigit, isValidPriceOrWeightCheckDigit } from "./check.js";
4
+ import { IdentifierDescriptors } from "./descriptors.js";
5
+ import type { GTINDescriptor } from "./gtin-descriptor.js";
6
+ import { type GTINBaseType, type GTINType, GTINTypes } from "./gtin-type.js";
7
+ import { i18nextGS1 } from "./locale/i18n.js";
8
+ import { type PrefixType, PrefixTypes } from "./prefix-type.js";
9
+ import { PrefixValidator } from "./prefix-validator.js";
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";
3
- import type { ContentCharacterSet, IdentifierValidation, IdentifierValidator } from "./identifier-validator";
4
- import type { PrefixProvider } from "./prefix-provider";
5
- import type { PrefixType } from "./prefix-type";
1
+ import type { IdentifierDescriptor } from "./identifier-descriptor.js";
2
+ import type { IdentifierValidation, IdentifierValidator } from "./identifier-validator.js";
3
+ import type { PrefixProvider } from "./prefix-provider.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
- }