@aidc-toolkit/gs1 1.0.46 → 1.0.47-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. package/dist/abstract-identifier-creator.d.ts +41 -0
  2. package/dist/abstract-identifier-creator.d.ts.map +1 -0
  3. package/dist/abstract-identifier-creator.js +73 -0
  4. package/dist/abstract-identifier-creator.js.map +1 -0
  5. package/dist/abstract-non-gtin-numeric-identifier-creator.d.ts +36 -0
  6. package/dist/abstract-non-gtin-numeric-identifier-creator.d.ts.map +1 -0
  7. package/dist/abstract-non-gtin-numeric-identifier-creator.js +37 -0
  8. package/dist/abstract-non-gtin-numeric-identifier-creator.js.map +1 -0
  9. package/dist/abstract-numeric-identifier-creator.d.ts +34 -0
  10. package/dist/abstract-numeric-identifier-creator.d.ts.map +1 -0
  11. package/dist/abstract-numeric-identifier-creator.js +152 -0
  12. package/dist/abstract-numeric-identifier-creator.js.map +1 -0
  13. package/dist/character-set.d.ts +27 -0
  14. package/dist/character-set.d.ts.map +1 -0
  15. package/dist/character-set.js +83 -0
  16. package/dist/character-set.js.map +1 -0
  17. package/dist/check.d.ts +81 -0
  18. package/dist/check.d.ts.map +1 -0
  19. package/dist/check.js +218 -0
  20. package/dist/check.js.map +1 -0
  21. package/dist/content-character-set-creators.d.ts +4 -0
  22. package/dist/content-character-set-creators.d.ts.map +1 -0
  23. package/dist/content-character-set-creators.js +9 -0
  24. package/dist/content-character-set-creators.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/gcp-length-cache.d.ts +89 -0
  30. package/dist/gcp-length-cache.d.ts.map +1 -0
  31. package/dist/gcp-length-cache.js +240 -0
  32. package/dist/gcp-length-cache.js.map +1 -0
  33. package/dist/gcp-length-data.d.ts +108 -0
  34. package/dist/gcp-length-data.d.ts.map +1 -0
  35. package/dist/gcp-length-data.js +53 -0
  36. package/dist/gcp-length-data.js.map +1 -0
  37. package/dist/gcp-length.d.ts +97 -0
  38. package/dist/gcp-length.d.ts.map +1 -0
  39. package/dist/gcp-length.js +368 -0
  40. package/dist/gcp-length.js.map +1 -0
  41. package/dist/gtin-creator.d.ts +60 -0
  42. package/dist/gtin-creator.d.ts.map +1 -0
  43. package/dist/gtin-creator.js +46 -0
  44. package/dist/gtin-creator.js.map +1 -0
  45. package/dist/gtin-descriptor.d.ts +22 -0
  46. package/dist/gtin-descriptor.d.ts.map +1 -0
  47. package/dist/gtin-descriptor.js +2 -0
  48. package/dist/gtin-descriptor.js.map +1 -0
  49. package/dist/gtin-length.d.ts +64 -0
  50. package/dist/gtin-length.d.ts.map +1 -0
  51. package/dist/gtin-length.js +36 -0
  52. package/dist/gtin-length.js.map +1 -0
  53. package/dist/gtin-type.d.ts +26 -0
  54. package/dist/gtin-type.d.ts.map +1 -0
  55. package/dist/gtin-type.js +7 -0
  56. package/dist/gtin-type.js.map +1 -0
  57. package/dist/gtin-validator.d.ts +132 -0
  58. package/dist/gtin-validator.d.ts.map +1 -0
  59. package/dist/gtin-validator.js +349 -0
  60. package/dist/gtin-validator.js.map +1 -0
  61. package/dist/identifier-creator.d.ts +31 -0
  62. package/dist/identifier-creator.d.ts.map +1 -0
  63. package/dist/identifier-creator.js +2 -0
  64. package/dist/identifier-creator.js.map +1 -0
  65. package/dist/identifier-creators.d.ts +118 -0
  66. package/dist/identifier-creators.d.ts.map +1 -0
  67. package/dist/identifier-creators.js +92 -0
  68. package/dist/identifier-creators.js.map +1 -0
  69. package/dist/identifier-descriptor.d.ts +27 -0
  70. package/dist/identifier-descriptor.d.ts.map +1 -0
  71. package/dist/identifier-descriptor.js +2 -0
  72. package/dist/identifier-descriptor.js.map +1 -0
  73. package/dist/identifier-descriptors.d.ts +106 -0
  74. package/dist/identifier-descriptors.d.ts.map +1 -0
  75. package/dist/identifier-descriptors.js +262 -0
  76. package/dist/identifier-descriptors.js.map +1 -0
  77. package/dist/identifier-extension.d.ts +82 -0
  78. package/dist/identifier-extension.d.ts.map +1 -0
  79. package/dist/identifier-extension.js +79 -0
  80. package/dist/identifier-extension.js.map +1 -0
  81. package/dist/identifier-type.d.ts +62 -0
  82. package/dist/identifier-type.d.ts.map +1 -0
  83. package/dist/identifier-type.js +54 -0
  84. package/dist/identifier-type.js.map +1 -0
  85. package/dist/identifier-validator.d.ts +85 -0
  86. package/dist/identifier-validator.d.ts.map +1 -0
  87. package/dist/identifier-validator.js +107 -0
  88. package/dist/identifier-validator.js.map +1 -0
  89. package/dist/identifier-validators.d.ts +131 -0
  90. package/dist/identifier-validators.d.ts.map +1 -0
  91. package/dist/identifier-validators.js +167 -0
  92. package/dist/identifier-validators.js.map +1 -0
  93. package/dist/index.d.ts +63 -2208
  94. package/dist/index.d.ts.map +1 -0
  95. package/dist/index.js +36 -3
  96. package/dist/index.js.map +1 -0
  97. package/dist/leader-type.d.ts +26 -0
  98. package/dist/leader-type.d.ts.map +1 -0
  99. package/dist/leader-type.js +18 -0
  100. package/dist/leader-type.js.map +1 -0
  101. package/dist/locale/en/locale-resources.d.ts +48 -0
  102. package/dist/locale/en/locale-resources.d.ts.map +1 -0
  103. package/dist/locale/en/locale-resources.js +47 -0
  104. package/dist/locale/en/locale-resources.js.map +1 -0
  105. package/dist/locale/fr/locale-resources.d.ts +48 -0
  106. package/dist/locale/fr/locale-resources.d.ts.map +1 -0
  107. package/dist/locale/fr/locale-resources.js +47 -0
  108. package/dist/locale/fr/locale-resources.js.map +1 -0
  109. package/dist/locale/i18n.d.ts +27 -0
  110. package/dist/locale/i18n.d.ts.map +1 -0
  111. package/dist/locale/i18n.js +35 -0
  112. package/dist/locale/i18n.js.map +1 -0
  113. package/dist/non-gtin-numeric-identifier-creator.d.ts +12 -0
  114. package/dist/non-gtin-numeric-identifier-creator.d.ts.map +1 -0
  115. package/dist/non-gtin-numeric-identifier-creator.js +2 -0
  116. package/dist/non-gtin-numeric-identifier-creator.js.map +1 -0
  117. package/dist/non-gtin-numeric-identifier-descriptor.d.ts +22 -0
  118. package/dist/non-gtin-numeric-identifier-descriptor.d.ts.map +1 -0
  119. package/dist/non-gtin-numeric-identifier-descriptor.js +2 -0
  120. package/dist/non-gtin-numeric-identifier-descriptor.js.map +1 -0
  121. package/dist/non-gtin-numeric-identifier-type.d.ts +26 -0
  122. package/dist/non-gtin-numeric-identifier-type.d.ts.map +1 -0
  123. package/dist/non-gtin-numeric-identifier-type.js +8 -0
  124. package/dist/non-gtin-numeric-identifier-type.js.map +1 -0
  125. package/dist/non-gtin-numeric-identifier-validator.d.ts +12 -0
  126. package/dist/non-gtin-numeric-identifier-validator.d.ts.map +1 -0
  127. package/dist/non-gtin-numeric-identifier-validator.js +10 -0
  128. package/dist/non-gtin-numeric-identifier-validator.js.map +1 -0
  129. package/dist/non-numeric-identifier-creator.d.ts +47 -0
  130. package/dist/non-numeric-identifier-creator.d.ts.map +1 -0
  131. package/dist/non-numeric-identifier-creator.js +64 -0
  132. package/dist/non-numeric-identifier-creator.js.map +1 -0
  133. package/dist/non-numeric-identifier-descriptor.d.ts +26 -0
  134. package/dist/non-numeric-identifier-descriptor.d.ts.map +1 -0
  135. package/dist/non-numeric-identifier-descriptor.js +2 -0
  136. package/dist/non-numeric-identifier-descriptor.js.map +1 -0
  137. package/dist/non-numeric-identifier-type.d.ts +26 -0
  138. package/dist/non-numeric-identifier-type.d.ts.map +1 -0
  139. package/dist/non-numeric-identifier-type.js +8 -0
  140. package/dist/non-numeric-identifier-type.js.map +1 -0
  141. package/dist/non-numeric-identifier-validator.d.ts +41 -0
  142. package/dist/non-numeric-identifier-validator.d.ts.map +1 -0
  143. package/dist/non-numeric-identifier-validator.js +69 -0
  144. package/dist/non-numeric-identifier-validator.js.map +1 -0
  145. package/dist/non-serializable-numeric-identifier-creator.d.ts +10 -0
  146. package/dist/non-serializable-numeric-identifier-creator.d.ts.map +1 -0
  147. package/dist/non-serializable-numeric-identifier-creator.js +8 -0
  148. package/dist/non-serializable-numeric-identifier-creator.js.map +1 -0
  149. package/dist/non-serializable-numeric-identifier-descriptor.d.ts +12 -0
  150. package/dist/non-serializable-numeric-identifier-descriptor.d.ts.map +1 -0
  151. package/dist/non-serializable-numeric-identifier-descriptor.js +2 -0
  152. package/dist/non-serializable-numeric-identifier-descriptor.js.map +1 -0
  153. package/dist/non-serializable-numeric-identifier-type.d.ts +26 -0
  154. package/dist/non-serializable-numeric-identifier-type.d.ts.map +1 -0
  155. package/dist/non-serializable-numeric-identifier-type.js +7 -0
  156. package/dist/non-serializable-numeric-identifier-type.js.map +1 -0
  157. package/dist/non-serializable-numeric-identifier-validator.d.ts +16 -0
  158. package/dist/non-serializable-numeric-identifier-validator.d.ts.map +1 -0
  159. package/dist/non-serializable-numeric-identifier-validator.js +17 -0
  160. package/dist/non-serializable-numeric-identifier-validator.js.map +1 -0
  161. package/dist/numeric-identifier-creator.d.ts +65 -0
  162. package/dist/numeric-identifier-creator.d.ts.map +1 -0
  163. package/dist/numeric-identifier-creator.js +2 -0
  164. package/dist/numeric-identifier-creator.js.map +1 -0
  165. package/dist/numeric-identifier-descriptor.d.ts +22 -0
  166. package/dist/numeric-identifier-descriptor.d.ts.map +1 -0
  167. package/dist/numeric-identifier-descriptor.js +2 -0
  168. package/dist/numeric-identifier-descriptor.js.map +1 -0
  169. package/dist/numeric-identifier-type.d.ts +26 -0
  170. package/dist/numeric-identifier-type.d.ts.map +1 -0
  171. package/dist/numeric-identifier-type.js +7 -0
  172. package/dist/numeric-identifier-type.js.map +1 -0
  173. package/dist/numeric-identifier-validator.d.ts +38 -0
  174. package/dist/numeric-identifier-validator.d.ts.map +1 -0
  175. package/dist/numeric-identifier-validator.js +61 -0
  176. package/dist/numeric-identifier-validator.js.map +1 -0
  177. package/dist/prefix-manager.d.ts +151 -0
  178. package/dist/prefix-manager.d.ts.map +1 -0
  179. package/dist/prefix-manager.js +297 -0
  180. package/dist/prefix-manager.js.map +1 -0
  181. package/dist/prefix-provider.d.ts +27 -0
  182. package/dist/prefix-provider.d.ts.map +1 -0
  183. package/dist/prefix-provider.js +2 -0
  184. package/dist/prefix-provider.js.map +1 -0
  185. package/dist/prefix-type.d.ts +26 -0
  186. package/dist/prefix-type.d.ts.map +1 -0
  187. package/dist/prefix-type.js +18 -0
  188. package/dist/prefix-type.js.map +1 -0
  189. package/dist/prefix-validator.d.ts +71 -0
  190. package/dist/prefix-validator.d.ts.map +1 -0
  191. package/dist/prefix-validator.js +204 -0
  192. package/dist/prefix-validator.js.map +1 -0
  193. package/dist/serializable-numeric-identifier-creator.d.ts +71 -0
  194. package/dist/serializable-numeric-identifier-creator.d.ts.map +1 -0
  195. package/dist/serializable-numeric-identifier-creator.js +40 -0
  196. package/dist/serializable-numeric-identifier-creator.js.map +1 -0
  197. package/dist/serializable-numeric-identifier-descriptor.d.ts +26 -0
  198. package/dist/serializable-numeric-identifier-descriptor.d.ts.map +1 -0
  199. package/dist/serializable-numeric-identifier-descriptor.js +2 -0
  200. package/dist/serializable-numeric-identifier-descriptor.js.map +1 -0
  201. package/dist/serializable-numeric-identifier-type.d.ts +26 -0
  202. package/dist/serializable-numeric-identifier-type.d.ts.map +1 -0
  203. package/dist/serializable-numeric-identifier-type.js +8 -0
  204. package/dist/serializable-numeric-identifier-type.js.map +1 -0
  205. package/dist/serializable-numeric-identifier-validator.d.ts +67 -0
  206. package/dist/serializable-numeric-identifier-validator.d.ts.map +1 -0
  207. package/dist/serializable-numeric-identifier-validator.js +97 -0
  208. package/dist/serializable-numeric-identifier-validator.js.map +1 -0
  209. package/dist/variable-measure.d.ts +68 -0
  210. package/dist/variable-measure.d.ts.map +1 -0
  211. package/dist/variable-measure.js +210 -0
  212. package/dist/variable-measure.js.map +1 -0
  213. package/dist/verified-by-gs1.d.ts +22 -0
  214. package/dist/verified-by-gs1.d.ts.map +1 -0
  215. package/dist/verified-by-gs1.js +46 -0
  216. package/dist/verified-by-gs1.js.map +1 -0
  217. package/dist/version.d.ts +5 -0
  218. package/dist/version.d.ts.map +1 -0
  219. package/dist/version.js +5 -0
  220. package/dist/version.js.map +1 -0
  221. package/package.json +4 -4
  222. package/src/abstract-numeric-identifier-creator.ts +11 -9
  223. package/src/gtin-creator.ts +29 -17
  224. package/src/non-numeric-identifier-creator.ts +21 -23
  225. package/src/numeric-identifier-creator.ts +32 -18
  226. package/src/serializable-numeric-identifier-creator.ts +70 -32
  227. package/src/version.ts +1 -1
  228. package/tsconfig-src.tsbuildinfo +1 -1
  229. package/dist/index.cjs +0 -19
  230. package/dist/index.d.cts +0 -2208
@@ -0,0 +1,210 @@
1
+ import { NUMERIC_CREATOR } from "@aidc-toolkit/utility";
2
+ import { checkDigit, hasValidCheckDigit, isValidPriceOrWeightCheckDigit, priceOrWeightCheckDigit } from "./check.js";
3
+ import { i18nextGS1 } from "./locale/i18n.js";
4
+ /**
5
+ * Variable measure trade item support functions.
6
+ */
7
+ // eslint-disable-next-line @typescript-eslint/no-extraneous-class -- Wrapper for future functionality.
8
+ export class VariableMeasure {
9
+ /**
10
+ * Parse a Restricted Circulation Number (RCN) using a variable measure trade item format. The format is a 12- or
11
+ * 13-character string (for RCN-12 or RCN-13 respectively), containing the following:
12
+ *
13
+ * - '2' - The first character of the RCN.
14
+ * - '0'-'9' - The second character of the RCN (RCN-13 only).
15
+ * - 'I' - One or more, in sequence, for the item reference.
16
+ * - 'P' - One or more, in sequence, for the price or weight.
17
+ * - 'V' - Zero or one, for the price or weight check digit.
18
+ * - 'C' - The check digit of the entire RCN.
19
+ *
20
+ * The 'I', 'P', and 'V' formats may be in any order.
21
+ *
22
+ * Some examples:
23
+ *
24
+ * - `2IIIIIVPPPPC` - RCN-12 with a five-digit item reference, a price or weight check digit, and a four-digit price
25
+ * or weight.
26
+ * - `23IIIIVPPPPPC` - RCN-13 with a four-digit item reference, a price or weight check digit, and a five-digit price
27
+ * or weight.
28
+ * - `2IIIIIIPPPPC` - RCN-12 with a six-digit item reference and a four-digit price or eight.
29
+ * - `29IIIIIPPPPPC` - RCN-13 with a five-digit item reference and a five-digit price or weight.
30
+ *
31
+ * @param format
32
+ * Format.
33
+ *
34
+ * @param rcn
35
+ * RCN.
36
+ *
37
+ * @returns
38
+ * RCN reference.
39
+ */
40
+ static parseRCN(format, rcn) {
41
+ const formatLength = format.length;
42
+ if (rcn.length !== formatLength) {
43
+ throw new RangeError(i18nextGS1.t("Identifier.invalidRCNLength"));
44
+ }
45
+ let validFormat = formatLength === 12 || formatLength === 13;
46
+ let validRCNPrefix = true;
47
+ let buildingItemReference = false;
48
+ let itemReference = "";
49
+ let buildingPriceOrWeight = false;
50
+ let priceOrWeight = "";
51
+ let priceOrWeightCheckDigit = "";
52
+ for (let index = 0; validFormat && index < formatLength; index++) {
53
+ const formatChar = format.charAt(index);
54
+ const rcnChar = rcn.charAt(index);
55
+ if (index === 0) {
56
+ validFormat = formatChar === "2";
57
+ validRCNPrefix = rcnChar === "2";
58
+ }
59
+ else if (formatLength === 13 && index === 1) {
60
+ validFormat = NUMERIC_CREATOR.characterIndex(formatChar) !== undefined;
61
+ validRCNPrefix = rcnChar === formatChar;
62
+ }
63
+ else if (index === formatLength - 1) {
64
+ validFormat = formatChar === "C";
65
+ }
66
+ else {
67
+ switch (formatChar) {
68
+ case "I":
69
+ if (!buildingItemReference) {
70
+ // Item reference can't appear more than once.
71
+ validFormat = itemReference === "";
72
+ buildingItemReference = true;
73
+ buildingPriceOrWeight = false;
74
+ }
75
+ itemReference += rcnChar;
76
+ break;
77
+ case "P":
78
+ if (!buildingPriceOrWeight) {
79
+ // Price or weight can't appear more than once.
80
+ validFormat = priceOrWeight === "";
81
+ buildingPriceOrWeight = true;
82
+ buildingItemReference = false;
83
+ }
84
+ priceOrWeight += rcnChar;
85
+ break;
86
+ case "V":
87
+ // Price or weight check digit can't appear more than once.
88
+ validFormat = priceOrWeightCheckDigit === "";
89
+ buildingItemReference = false;
90
+ buildingPriceOrWeight = false;
91
+ priceOrWeightCheckDigit = rcnChar;
92
+ break;
93
+ default:
94
+ validFormat = false;
95
+ break;
96
+ }
97
+ }
98
+ }
99
+ validFormat &&= itemReference !== "" && priceOrWeight !== "";
100
+ if (!validFormat) {
101
+ throw new RangeError(i18nextGS1.t("Identifier.invalidVariableMeasureRCNFormat"));
102
+ }
103
+ if (!validRCNPrefix) {
104
+ throw new RangeError(i18nextGS1.t("Identifier.invalidVariableMeasureRCNPrefix"));
105
+ }
106
+ if (priceOrWeightCheckDigit !== "" && !isValidPriceOrWeightCheckDigit(priceOrWeight, priceOrWeightCheckDigit)) {
107
+ throw new RangeError(i18nextGS1.t("Identifier.invalidVariableMeasurePriceOrWeight"));
108
+ }
109
+ if (!hasValidCheckDigit(rcn)) {
110
+ throw new RangeError(i18nextGS1.t("Identifier.invalidCheckDigit"));
111
+ }
112
+ return {
113
+ itemReference: Number(itemReference),
114
+ priceOrWeight: Number(priceOrWeight)
115
+ };
116
+ }
117
+ /**
118
+ * Create a Restricted Circulation Number (RCN) using a variable measure trade item format. See {@linkcode parseRCN}
119
+ * for format details.
120
+ *
121
+ * @param format
122
+ * Format.
123
+ *
124
+ * @param itemReference
125
+ * Item reference.
126
+ *
127
+ * @param priceOrWeight
128
+ * Price or weight (whole number only).
129
+ *
130
+ * @returns
131
+ * RCN-12 or RCN-13.
132
+ */
133
+ static createRCN(format, itemReference, priceOrWeight) {
134
+ const formatLength = format.length;
135
+ let validFormat = formatLength === 12 || formatLength === 13;
136
+ let rcnPrefix = "";
137
+ let buildingItemReference = false;
138
+ let itemReferenceString = "";
139
+ let itemReferenceLength = 0;
140
+ let buildingPriceOrWeight = false;
141
+ let priceOrWeightString = "";
142
+ let priceOrWeightLength = 0;
143
+ let calculatePriceOrWeightCheckDigit = false;
144
+ // RCN may be built in almost any order, so defer to builders that will be in ordered array.
145
+ const rcnPrefixBuilder = (partialRCN) => partialRCN + rcnPrefix;
146
+ const itemReferenceBuilder = (partialRCN) => partialRCN + itemReferenceString;
147
+ const priceOrWeightBuilder = (partialRCN) => partialRCN + priceOrWeightString;
148
+ const priceOrWeightCheckDigitBuilder = (partialRCN) => partialRCN + priceOrWeightCheckDigit(priceOrWeightString);
149
+ const checkDigitBuilder = (partialRCN) => partialRCN + checkDigit(partialRCN);
150
+ const rcnBuilders = [rcnPrefixBuilder];
151
+ for (let index = 0; validFormat && index < formatLength; index++) {
152
+ const formatChar = format.charAt(index);
153
+ if (index === 0) {
154
+ validFormat = formatChar === "2";
155
+ rcnPrefix = formatChar;
156
+ }
157
+ else if (formatLength === 13 && index === 1) {
158
+ validFormat = NUMERIC_CREATOR.characterIndex(formatChar) !== undefined;
159
+ rcnPrefix += formatChar;
160
+ }
161
+ else if (index === formatLength - 1) {
162
+ validFormat = formatChar === "C";
163
+ }
164
+ else {
165
+ switch (formatChar) {
166
+ case "I":
167
+ if (!buildingItemReference) {
168
+ // Item reference can't appear more than once.
169
+ validFormat = itemReferenceLength === 0;
170
+ buildingItemReference = true;
171
+ buildingPriceOrWeight = false;
172
+ rcnBuilders.push(itemReferenceBuilder);
173
+ }
174
+ itemReferenceLength++;
175
+ break;
176
+ case "P":
177
+ if (!buildingPriceOrWeight) {
178
+ // Price or weight can't appear more than once.
179
+ validFormat = priceOrWeightLength === 0;
180
+ buildingPriceOrWeight = true;
181
+ buildingItemReference = false;
182
+ rcnBuilders.push(priceOrWeightBuilder);
183
+ }
184
+ priceOrWeightLength++;
185
+ break;
186
+ case "V":
187
+ // Price or weight check digit can't appear more than once.
188
+ validFormat = !calculatePriceOrWeightCheckDigit;
189
+ buildingItemReference = false;
190
+ buildingPriceOrWeight = false;
191
+ calculatePriceOrWeightCheckDigit = true;
192
+ rcnBuilders.push(priceOrWeightCheckDigitBuilder);
193
+ break;
194
+ default:
195
+ validFormat = false;
196
+ break;
197
+ }
198
+ }
199
+ }
200
+ validFormat &&= itemReferenceLength !== 0 && priceOrWeightLength !== 0;
201
+ if (!validFormat) {
202
+ throw new RangeError(i18nextGS1.t("Identifier.invalidVariableMeasureRCNFormat"));
203
+ }
204
+ itemReferenceString = NUMERIC_CREATOR.create(itemReferenceLength, itemReference);
205
+ priceOrWeightString = NUMERIC_CREATOR.create(priceOrWeightLength, priceOrWeight);
206
+ rcnBuilders.push(checkDigitBuilder);
207
+ return rcnBuilders.reduce((partialRCN, rcnBuilder) => rcnBuilder(partialRCN), "");
208
+ }
209
+ }
210
+ //# sourceMappingURL=variable-measure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variable-measure.js","sourceRoot":"","sources":["../src/variable-measure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,8BAA8B,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACrH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAiB9C;;GAEG;AACH,uGAAuG;AACvG,MAAM,OAAO,eAAe;IACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,MAAM,CAAC,QAAQ,CAAC,MAAc,EAAE,GAAW;QACvC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;QAEnC,IAAI,GAAG,CAAC,MAAM,KAAK,YAAY,EAAE,CAAC;YAC9B,MAAM,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,6BAA6B,CAAC,CAAC,CAAC;QACtE,CAAC;QAED,IAAI,WAAW,GAAG,YAAY,KAAK,EAAE,IAAI,YAAY,KAAK,EAAE,CAAC;QAC7D,IAAI,cAAc,GAAG,IAAI,CAAC;QAE1B,IAAI,qBAAqB,GAAG,KAAK,CAAC;QAClC,IAAI,aAAa,GAAG,EAAE,CAAC;QAEvB,IAAI,qBAAqB,GAAG,KAAK,CAAC;QAClC,IAAI,aAAa,GAAG,EAAE,CAAC;QAEvB,IAAI,uBAAuB,GAAG,EAAE,CAAC;QAEjC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,WAAW,IAAI,KAAK,GAA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,EAAE,CAAC;YACf,MAAM,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,4CAA4C,CAAC,CAAC,CAAC;QACrF,CAAC;QAED,mBAAmB,GAAG,eAAe,CAAC,MAAM,CAAC,mBAAmB,EAAE,aAAa,CAAC,CAAC;QACjF,mBAAmB,GAAG,eAAe,CAAC,MAAM,CAAC,mBAAmB,EAAE,aAAa,CAAC,CAAC;QAEjF,WAAW,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAEpC,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC;IACtF,CAAC;CACJ"}
@@ -0,0 +1,22 @@
1
+ import type { Hyperlink } from "@aidc-toolkit/core";
2
+ import { type IdentifierType } from "./identifier-type.js";
3
+ /**
4
+ * Create a Verified by GS1 hyperlink.
5
+ *
6
+ * @param identifierType
7
+ * Identifier type.
8
+ *
9
+ * @param identifier
10
+ * Identifier.
11
+ *
12
+ * @param text
13
+ * Text for hyperlink. If not provided, the identifier is used.
14
+ *
15
+ * @param details
16
+ * Details to display when hovering over hyperlink.
17
+ *
18
+ * @returns
19
+ * Verified by GS1 hyperlink.
20
+ */
21
+ export declare function verifiedByGS1(identifierType: IdentifierType, identifier: string, text?: string | undefined, details?: string): Hyperlink;
22
+ //# sourceMappingURL=verified-by-gs1.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verified-by-gs1.d.ts","sourceRoot":"","sources":["../src/verified-by-gs1.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,KAAK,cAAc,EAAmB,MAAM,sBAAsB,CAAC;AAK5E;;;;;;;;;;;;;;;;;GAiBG;AAEH,wBAAgB,aAAa,CAAC,cAAc,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,GAAG,SAAqB,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CA2BnJ"}
@@ -0,0 +1,46 @@
1
+ import { GTINValidator } from "./gtin-validator.js";
2
+ import { IdentifierTypes } from "./identifier-type.js";
3
+ import { IdentifierValidators } from "./identifier-validators.js";
4
+ const VERIFIED_BY_GS1_REFERENCE_BASE = "https://www.gs1.org/services/verified-by-gs1/results?";
5
+ /**
6
+ * Create a Verified by GS1 hyperlink.
7
+ *
8
+ * @param identifierType
9
+ * Identifier type.
10
+ *
11
+ * @param identifier
12
+ * Identifier.
13
+ *
14
+ * @param text
15
+ * Text for hyperlink. If not provided, the identifier is used.
16
+ *
17
+ * @param details
18
+ * Details to display when hovering over hyperlink.
19
+ *
20
+ * @returns
21
+ * Verified by GS1 hyperlink.
22
+ */
23
+ // eslint-disable-next-line @typescript-eslint/no-useless-default-assignment -- Undefined is necessary to allow bypass of text.
24
+ export function verifiedByGS1(identifierType, identifier, text = undefined, details) {
25
+ let normalizedIdentifier;
26
+ let useKeyTypeParameter;
27
+ if (identifierType === IdentifierTypes.GTIN) {
28
+ // Normalization will validate resulting GTIN.
29
+ normalizedIdentifier = GTINValidator.normalize(identifier);
30
+ useKeyTypeParameter = true;
31
+ }
32
+ else {
33
+ const identifierValidator = IdentifierValidators[identifierType];
34
+ identifierValidator.validate(identifier);
35
+ normalizedIdentifier = identifier;
36
+ useKeyTypeParameter = identifierType === IdentifierTypes.GLN;
37
+ }
38
+ const lowerCaseIdentifierType = identifierType.toLowerCase();
39
+ const reference = useKeyTypeParameter ? `${VERIFIED_BY_GS1_REFERENCE_BASE}${lowerCaseIdentifierType}=${normalizedIdentifier}` : `${VERIFIED_BY_GS1_REFERENCE_BASE}key=${normalizedIdentifier}&key_type=${lowerCaseIdentifierType}`;
40
+ return {
41
+ reference,
42
+ text: text ?? identifier,
43
+ details
44
+ };
45
+ }
46
+ //# sourceMappingURL=verified-by-gs1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verified-by-gs1.js","sourceRoot":"","sources":["../src/verified-by-gs1.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAuB,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE,MAAM,8BAA8B,GAAG,uDAAuD,CAAC;AAE/F;;;;;;;;;;;;;;;;;GAiBG;AACH,+HAA+H;AAC/H,MAAM,UAAU,aAAa,CAAC,cAA8B,EAAE,UAAkB,EAAE,OAA2B,SAAS,EAAE,OAAgB;IACpI,IAAI,oBAA4B,CAAC;IACjC,IAAI,mBAA4B,CAAC;IAEjC,IAAI,cAAc,KAAK,eAAe,CAAC,IAAI,EAAE,CAAC;QAC1C,8CAA8C;QAC9C,oBAAoB,GAAG,aAAa,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAE3D,mBAAmB,GAAG,IAAI,CAAC;IAC/B,CAAC;SAAM,CAAC;QACJ,MAAM,mBAAmB,GAAG,oBAAoB,CAAC,cAAc,CAAC,CAAC;QAEjE,mBAAmB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;QAEzC,oBAAoB,GAAG,UAAU,CAAC;QAClC,mBAAmB,GAAG,cAAc,KAAK,eAAe,CAAC,GAAG,CAAC;IACjE,CAAC;IAED,MAAM,uBAAuB,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC;IAE7D,MAAM,SAAS,GAAG,mBAAmB,CAAC,CAAC,CAAC,GAAG,8BAA8B,GAAG,uBAAuB,IAAI,oBAAoB,EAAE,CAAC,CAAC,CAAC,GAAG,8BAA8B,OAAO,oBAAoB,aAAa,uBAAuB,EAAE,CAAC;IAEnO,OAAO;QACH,SAAS;QACT,IAAI,EAAE,IAAI,IAAI,UAAU;QACxB,OAAO;KACV,CAAC;AACN,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Repository version, updated automatically during publication.
3
+ */
4
+ export declare const VERSION = "1.0.47-beta";
5
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,OAAO,gBAAgB,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Repository version, updated automatically during publication.
3
+ */
4
+ export const VERSION = "1.0.47-beta";
5
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aidc-toolkit/gs1",
3
- "version": "1.0.46",
3
+ "version": "1.0.47-beta",
4
4
  "description": "GS1 AIDC Toolkit",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -29,11 +29,11 @@
29
29
  "test": "tsc --project tsconfig-test.json --noEmit && vitest run"
30
30
  },
31
31
  "devDependencies": {
32
- "@aidc-toolkit/dev": "^1.0.43",
32
+ "@aidc-toolkit/dev": "1.0.44-beta",
33
33
  "vitest": "^4.0.18"
34
34
  },
35
35
  "dependencies": {
36
- "@aidc-toolkit/core": "^1.0.44",
37
- "@aidc-toolkit/utility": "^1.0.45"
36
+ "@aidc-toolkit/core": "1.0.45-beta",
37
+ "@aidc-toolkit/utility": "1.0.46-beta"
38
38
  }
39
39
  }
@@ -1,11 +1,5 @@
1
1
  import type { AbstractConstructor } from "@aidc-toolkit/core";
2
- import {
3
- CharacterSetCreator,
4
- Exclusions,
5
- NUMERIC_CREATOR,
6
- type TransformerInput,
7
- type TransformerOutput
8
- } from "@aidc-toolkit/utility";
2
+ import { CharacterSetCreator, Exclusions, NUMERIC_CREATOR } from "@aidc-toolkit/utility";
9
3
  import { type IdentifierCreatorConstructor, MixinAbstractIdentifierCreator } from "./abstract-identifier-creator.js";
10
4
  import { checkDigit, checkDigitSum } from "./check.js";
11
5
  import type { IdentifierTypeValidator, IdentifierValidatorConstructorsEntry } from "./identifier-validators.js";
@@ -132,8 +126,16 @@ export function MixinAbstractNumericIdentifierCreator<
132
126
  /**
133
127
  * @inheritDoc
134
128
  */
135
- create<TTransformerInput extends TransformerInput<number | bigint>>(valueOrValues: TTransformerInput, sparse = false): TransformerOutput<TTransformerInput, string> {
136
- return NUMERIC_CREATOR.create(this.referenceLength, valueOrValues, Exclusions.None, sparse ? this.tweak : undefined, reference => this.#buildIdentifier(reference));
129
+ create(value: number | bigint, sparse?: boolean): string;
130
+
131
+ /**
132
+ * @inheritDoc
133
+ */
134
+ create(values: Iterable<number | bigint>, sparse?: boolean): Iterable<string>;
135
+
136
+ // eslint-disable-next-line jsdoc/require-jsdoc -- Implementation of overloaded signatures.
137
+ create(valueOrValues: number | bigint | Iterable<number | bigint>, sparse?: boolean): string | Iterable<string> {
138
+ return NUMERIC_CREATOR.create(this.referenceLength, valueOrValues, Exclusions.None, sparse === true ? this.tweak : undefined, reference => this.#buildIdentifier(reference));
137
139
  }
138
140
 
139
141
  /**
@@ -1,10 +1,4 @@
1
- import {
2
- type CharacterSetValidation,
3
- Exclusions,
4
- NUMERIC_CREATOR,
5
- type TransformerInput,
6
- type TransformerOutput
7
- } from "@aidc-toolkit/utility";
1
+ import { type CharacterSetValidation, Exclusions, NUMERIC_CREATOR } from "@aidc-toolkit/utility";
8
2
  import { MixinAbstractNumericIdentifierCreator } from "./abstract-numeric-identifier-creator.js";
9
3
  import { checkDigit } from "./check.js";
10
4
  import { type GTINBaseLength, GTINLengths } from "./gtin-length.js";
@@ -49,28 +43,46 @@ export class GTINCreator extends MixinAbstractNumericIdentifierCreator<
49
43
  }
50
44
 
51
45
  /**
52
- * Create GTIN-14(s) with an indicator digit and reference(s) based on numeric value(s). The value(s) is/are
53
- * converted to reference(s) of the appropriate length using {@linkcode NUMERIC_CREATOR}.
46
+ * Create GTIN-14 with an indicator digit and reference based on a numeric value. The value is converted to a
47
+ * reference of the appropriate length using {@linkcode NUMERIC_CREATOR}.
54
48
  *
55
- * @template TTransformerInput
56
- * Transformer input type.
49
+ * @param indicatorDigit
50
+ * Indicator digit.
51
+ *
52
+ * @param value
53
+ * Numeric value.
54
+ *
55
+ * @param sparse
56
+ * If true, the value is mapped to a sparse sequence resistant to discovery.
57
+ *
58
+ * @returns
59
+ * GTIN-14.
60
+ */
61
+ createGTIN14(indicatorDigit: string, value: number | bigint, sparse?: boolean): string;
62
+
63
+ /**
64
+ * Create GTIN-14s with an indicator digit and references based on numeric values. The values are converted to
65
+ * references of the appropriate length using {@linkcode NUMERIC_CREATOR}.
57
66
  *
58
67
  * @param indicatorDigit
59
68
  * Indicator digit.
60
69
  *
61
- * @param valueOrValues
62
- * Numeric value(s).
70
+ * @param values
71
+ * Numeric values.
63
72
  *
64
73
  * @param sparse
65
- * If true, the value(s) is/are mapped to a sparse sequence resistant to discovery. Default is false.
74
+ * If true, the values are mapped to a sparse sequence resistant to discovery.
66
75
  *
67
76
  * @returns
68
- * GTIN-14(s).
77
+ * GTIN-14s.
69
78
  */
70
- createGTIN14<TTransformerInput extends TransformerInput<number | bigint>>(indicatorDigit: string, valueOrValues: TTransformerInput, sparse = false): TransformerOutput<TTransformerInput, string> {
79
+ createGTIN14(indicatorDigit: string, values: Iterable<number | bigint>, sparse?: boolean): Iterable<string>;
80
+
81
+ // eslint-disable-next-line jsdoc/require-jsdoc -- Implementation of overloaded signatures.
82
+ createGTIN14(indicatorDigit: string, valueOrValues: number | bigint | Iterable<number | bigint>, sparse?: boolean): string | Iterable<string> {
71
83
  NUMERIC_CREATOR.validate(indicatorDigit, GTINCreator.#REQUIRED_INDICATOR_DIGIT_VALIDATION);
72
84
 
73
- return NUMERIC_CREATOR.create(GTINLengths.GTIN13 - this.prefixProvider.gs1CompanyPrefix.length - 1, valueOrValues, Exclusions.None, sparse ? this.tweak : undefined, (reference) => {
85
+ return NUMERIC_CREATOR.create(GTINLengths.GTIN13 - this.prefixProvider.gs1CompanyPrefix.length - 1, valueOrValues, Exclusions.None, sparse === true ? this.tweak : undefined, (reference) => {
74
86
  const partialIdentifier = indicatorDigit + this.prefixProvider.gs1CompanyPrefix + reference;
75
87
 
76
88
  return partialIdentifier + checkDigit(partialIdentifier);
@@ -1,9 +1,4 @@
1
- import {
2
- type CharacterSetValidation,
3
- mapIterable,
4
- type TransformerInput,
5
- type TransformerOutput
6
- } from "@aidc-toolkit/utility";
1
+ import { type CharacterSetValidation, mapIterable } from "@aidc-toolkit/utility";
7
2
  import { MixinAbstractIdentifierCreator } from "./abstract-identifier-creator.js";
8
3
  import { checkCharacterPair } from "./check.js";
9
4
  import { IdentifierDescriptors } from "./identifier-descriptors.js";
@@ -55,21 +50,29 @@ export class NonNumericIdentifierCreator extends MixinAbstractIdentifierCreator<
55
50
  }
56
51
 
57
52
  /**
58
- * Create identifier(s) with reference(s).
53
+ * Create an identifier with a reference.
54
+ *
55
+ * @param reference
56
+ * Reference.
59
57
  *
60
- * @template TTransformerInput
61
- * Transformer input type.
58
+ * @returns
59
+ * Identifier.
60
+ */
61
+ create(reference: string): string;
62
+
63
+ /**
64
+ * Create identifiers with references.
62
65
  *
63
- * @param referenceOrReferences
64
- * Reference(s).
66
+ * @param references
67
+ * References.
65
68
  *
66
69
  * @returns
67
- * Identifier(s).
70
+ * Identifiers.
68
71
  */
69
- create<TTransformerInput extends TransformerInput<string>>(referenceOrReferences: TTransformerInput): TransformerOutput<TTransformerInput, string> {
70
- // TODO Refactor type when https://github.com/microsoft/TypeScript/pull/56941 released.
71
- let result: string | Iterable<string>;
72
+ create(references: Iterable<string>): Iterable<string>;
72
73
 
74
+ // eslint-disable-next-line jsdoc/require-jsdoc -- Implementation of overloaded signatures.
75
+ create(referenceOrReferences: string | Iterable<string>): string | Iterable<string> {
73
76
  const referenceCreator = this.referenceCreator;
74
77
  const referenceValidation = this.referenceValidation;
75
78
  const prefix = this.prefix;
@@ -92,13 +95,8 @@ export class NonNumericIdentifierCreator extends MixinAbstractIdentifierCreator<
92
95
  return requiresCheckCharacterPair ? partialIdentifier + checkCharacterPair(partialIdentifier) : partialIdentifier;
93
96
  }
94
97
 
95
- if (typeof referenceOrReferences !== "object") {
96
- result = validateAndCreate(referenceOrReferences);
97
- } else {
98
- result = mapIterable(referenceOrReferences, validateAndCreate);
99
- }
100
-
101
- // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type determination is handled above.
102
- return result as TransformerOutput<TTransformerInput, string>;
98
+ return typeof referenceOrReferences !== "object" ?
99
+ validateAndCreate(referenceOrReferences) :
100
+ mapIterable(referenceOrReferences, validateAndCreate);
103
101
  }
104
102
  }
@@ -1,5 +1,5 @@
1
1
  // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Used in JSDoc.
2
- import { NUMERIC_CREATOR, type TransformerInput, type TransformerOutput } from "@aidc-toolkit/utility";
2
+ import { NUMERIC_CREATOR } from "@aidc-toolkit/utility";
3
3
  import type { IdentifierCreator } from "./identifier-creator.js";
4
4
  import type { NumericIdentifierType } from "./numeric-identifier-type.js";
5
5
  import type { NumericIdentifierValidation, NumericIdentifierValidator } from "./numeric-identifier-validator.js";
@@ -26,23 +26,37 @@ export interface NumericIdentifierCreator<TNumericIdentifierType extends Numeric
26
26
  */
27
27
  set tweak(value: bigint);
28
28
 
29
- /**
30
- * Create identifier(s) with reference(s) based on numeric value(s). The value(s) is/are converted to references of
31
- * the appropriate length using {@linkcode NUMERIC_CREATOR}.
32
- *
33
- * @template TTransformerInput
34
- * Transformer input type.
35
- *
36
- * @param valueOrValues
37
- * Numeric value(s).
38
- *
39
- * @param sparse
40
- * If true, the value(s) are mapped to a sparse sequence resistant to discovery. Default is false.
41
- *
42
- * @returns
43
- * Identifier(s).
44
- */
45
- create: <TTransformerInput extends TransformerInput<number | bigint>>(valueOrValues: TTransformerInput, sparse?: boolean) => TransformerOutput<TTransformerInput, string>;
29
+ create: {
30
+ /**
31
+ * Create an identifier with a reference based on a numeric value. The value is converted to a reference of the
32
+ * appropriate length using {@linkcode NUMERIC_CREATOR}.
33
+ *
34
+ * @param value
35
+ * Numeric value.
36
+ *
37
+ * @param sparse
38
+ * If true, the value is mapped to a sparse sequence resistant to discovery.
39
+ *
40
+ * @returns
41
+ * Identifier.
42
+ */
43
+ (value: number | bigint, sparse?: boolean): string;
44
+
45
+ /**
46
+ * Create identifiers with references based on numeric values. The values are converted to references of the
47
+ * appropriate length using {@linkcode NUMERIC_CREATOR}.
48
+ *
49
+ * @param values
50
+ * Numeric values.
51
+ *
52
+ * @param sparse
53
+ * If true, the values are mapped to a sparse sequence resistant to discovery.
54
+ *
55
+ * @returns
56
+ * Identifiers.
57
+ */
58
+ (values: Iterable<number | bigint>, sparse?: boolean): Iterable<string>;
59
+ };
46
60
 
47
61
  /**
48
62
  * Create all identifiers for the prefix from `0` to `capacity - 1`.