@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,168 @@
1
+ import {
2
+ CharacterSetCreator,
3
+ Exclusions,
4
+ NUMERIC_CREATOR,
5
+ type TransformerInput,
6
+ type TransformerOutput
7
+ } from "@aidc-toolkit/utility";
8
+ import { AbstractIdentifierCreator } from "./abstract-identifier-creator.js";
9
+ import { checkDigit, checkDigitSum } from "./check.js";
10
+ import type { NumericIdentifierCreator } from "./numeric-identifier-creator.js";
11
+ import type { NumericIdentifierDescriptor } from "./numeric-identifier-descriptor.js";
12
+ import { type LeaderType, LeaderTypes } from "./numeric-identifier-type.js";
13
+ import type { NumericIdentifierValidation } from "./numeric-identifier-validator.js";
14
+ import type { PrefixProvider } from "./prefix-provider.js";
15
+
16
+ /**
17
+ * Abstract numeric identifier creator. Implements common functionality for a numeric identifier creator.
18
+ *
19
+ * @template TNumericIdentifierDescriptor
20
+ * Numeric identifier descriptor type.
21
+ */
22
+ export abstract class AbstractNumericIdentifierCreator<TNumericIdentifierDescriptor extends NumericIdentifierDescriptor> extends AbstractIdentifierCreator<TNumericIdentifierDescriptor, NumericIdentifierValidation> implements NumericIdentifierCreator<TNumericIdentifierDescriptor> {
23
+ /**
24
+ * Capacity.
25
+ */
26
+ private _capacity!: number;
27
+
28
+ /**
29
+ * Tweak for sparse creation.
30
+ */
31
+ private _tweak = 0n;
32
+
33
+ /**
34
+ * Initialize the prefix provider. This method is in lieu of a constructor due to the mixin architecture.
35
+ *
36
+ * @param prefixProvider
37
+ * Prefix provider.
38
+ *
39
+ * @param prefix
40
+ * Prefix within prefix manager to use to calculate reference length.
41
+ */
42
+ protected override init(prefixProvider: PrefixProvider, prefix: string): void {
43
+ super.init(prefixProvider, prefix, 1);
44
+
45
+ // Capacity is always in number range.
46
+ this._capacity = Number(CharacterSetCreator.powerOf10(this.referenceLength));
47
+ }
48
+
49
+ /**
50
+ * Get the leader type.
51
+ */
52
+ abstract get leaderType(): LeaderType;
53
+
54
+ /**
55
+ * @inheritDoc
56
+ */
57
+ get capacity(): number {
58
+ return this._capacity;
59
+ }
60
+
61
+ /**
62
+ * @inheritDoc
63
+ */
64
+ get tweak(): bigint {
65
+ return this._tweak;
66
+ }
67
+
68
+ /**
69
+ * @inheritDoc
70
+ */
71
+ set tweak(value: bigint) {
72
+ this._tweak = value;
73
+ }
74
+
75
+ /**
76
+ * Build an identifier from a reference by merging it with the prefix and adding the check digit.
77
+ *
78
+ * @param reference
79
+ * Identifier reference.
80
+ *
81
+ * @returns
82
+ * Identifier.
83
+ */
84
+ private buildIdentifier(reference: string): string {
85
+ const partialIdentifier = this.leaderType === LeaderTypes.ExtensionDigit ? reference.substring(0, 1) + this.prefix + reference.substring(1) : this.prefix + reference;
86
+
87
+ return partialIdentifier + checkDigit(partialIdentifier);
88
+ }
89
+
90
+ /**
91
+ * @inheritDoc
92
+ */
93
+ create<TTransformerInput extends TransformerInput<number | bigint>>(valueOrValues: TTransformerInput, sparse = false): TransformerOutput<TTransformerInput, string> {
94
+ return NUMERIC_CREATOR.create(this.referenceLength, valueOrValues, Exclusions.None, sparse ? this.tweak : undefined, reference => this.buildIdentifier(reference));
95
+ }
96
+
97
+ /**
98
+ * Create all identifiers from a partial identifier. Call is recursive until remaining reference
99
+ * length is 0.
100
+ *
101
+ * @param partialIdentifier
102
+ * Partial identifier. Initial value is `this.prefix`.
103
+ *
104
+ * @param remainingReferenceLength
105
+ * Remaining reference length. Initial value is `this.referenceLength`.
106
+ *
107
+ * @param extensionWeight
108
+ * If this value is not zero, the identifier has an extension digit, this call is setting it, and this value is
109
+ * applied to the calculation of the check digit.
110
+ *
111
+ * @param weight
112
+ * If the extension weight is zero, this value is applied to the calculation of the check digit.
113
+ *
114
+ * @param partialCheckDigitSum
115
+ * Partial check digit sum for the partial identifier.
116
+ *
117
+ * @yields
118
+ * Identifier.
119
+ */
120
+ private static * createAllPartial(partialIdentifier: string, remainingReferenceLength: number, extensionWeight: number, weight: number, partialCheckDigitSum: number): Generator<string> {
121
+ if (remainingReferenceLength === 0) {
122
+ // Finalize check digit calculation and append.
123
+ yield partialIdentifier + NUMERIC_CREATOR.character(9 - (partialCheckDigitSum + 9) % 10);
124
+ } else {
125
+ const nextRemainingReferenceLength = remainingReferenceLength - 1;
126
+
127
+ let nextPartialCheckDigitSum = partialCheckDigitSum;
128
+
129
+ if (extensionWeight !== 0) {
130
+ // Apply every digit to the extension digit.
131
+ for (const c of NUMERIC_CREATOR.characterSet) {
132
+ yield * AbstractNumericIdentifierCreator.createAllPartial(c + partialIdentifier, nextRemainingReferenceLength, 0, weight, nextPartialCheckDigitSum);
133
+
134
+ nextPartialCheckDigitSum += extensionWeight;
135
+ }
136
+ } else {
137
+ const nextWeight = 4 - weight;
138
+
139
+ // Apply every digit to the current character in the identifier.
140
+ for (const c of NUMERIC_CREATOR.characterSet) {
141
+ yield * AbstractNumericIdentifierCreator.createAllPartial(partialIdentifier + c, nextRemainingReferenceLength, 0, nextWeight, nextPartialCheckDigitSum);
142
+
143
+ nextPartialCheckDigitSum += weight;
144
+ }
145
+ }
146
+ }
147
+ }
148
+
149
+ /**
150
+ * @inheritDoc
151
+ */
152
+ createAll(): Iterable<string> {
153
+ const hasExtensionDigit = this.leaderType === LeaderTypes.ExtensionDigit;
154
+ const prefix = this.prefix;
155
+ const length = this.length;
156
+ const referenceLength = this.referenceLength;
157
+
158
+ // Start weight is for reference excluding extension digit, which has its weight calculated separately.
159
+ const startWeight = 3 - 2 * ((referenceLength + 1 - Number(hasExtensionDigit)) % 2);
160
+
161
+ // Returning separate Iterable object makes iteration repeatable.
162
+ return {
163
+ [Symbol.iterator]() {
164
+ return AbstractNumericIdentifierCreator.createAllPartial(prefix, referenceLength, hasExtensionDigit ? 3 - 2 * length % 2 : 0, startWeight, checkDigitSum(startWeight === 3, prefix));
165
+ }
166
+ };
167
+ }
168
+ }
@@ -0,0 +1,69 @@
1
+ import { AbstractIdentifierValidator } from "./abstract-identifier-validator.js";
2
+ import { hasValidCheckDigit } from "./check.js";
3
+ import { i18nextGS1 } from "./locale/i18n.js";
4
+ import type { NumericIdentifierDescriptor } from "./numeric-identifier-descriptor.js";
5
+ import { LeaderTypes } from "./numeric-identifier-type.js";
6
+ import type { NumericIdentifierValidation, NumericIdentifierValidator } from "./numeric-identifier-validator.js";
7
+
8
+ /**
9
+ * Abstract numeric identifier validator.
10
+ *
11
+ * @template TNumericIdentifierDescriptor
12
+ * Numeric identifier descriptor type.
13
+ */
14
+ export abstract class AbstractNumericIdentifierValidator<TNumericIdentifierDescriptor extends NumericIdentifierDescriptor> extends AbstractIdentifierValidator<TNumericIdentifierDescriptor, NumericIdentifierValidation> implements NumericIdentifierValidator<TNumericIdentifierDescriptor> {
15
+ /**
16
+ * Leader type.
17
+ */
18
+ private readonly _leaderType: TNumericIdentifierDescriptor["leaderType"];
19
+
20
+ /**
21
+ * Prefix position, determined by the leader type.
22
+ */
23
+ private readonly _prefixPosition: number;
24
+
25
+ /**
26
+ * Constructor.
27
+ *
28
+ * @param identifierDescriptor
29
+ * Identifier descriptor.
30
+ */
31
+ constructor(identifierDescriptor: NumericIdentifierDescriptor) {
32
+ super(identifierDescriptor);
33
+
34
+ this._leaderType = identifierDescriptor.leaderType;
35
+ this._prefixPosition = Number(this.leaderType === LeaderTypes.ExtensionDigit);
36
+ }
37
+
38
+ /**
39
+ * @inheritDoc
40
+ */
41
+ get leaderType(): TNumericIdentifierDescriptor["leaderType"] {
42
+ return this._leaderType;
43
+ }
44
+
45
+ /**
46
+ * @inheritDoc
47
+ */
48
+ validate(identifier: string, validation?: NumericIdentifierValidation): void {
49
+ // Validate the prefix, with care taken for its position within the identifier.
50
+ if (this._prefixPosition === 0) {
51
+ super.validatePrefix(identifier, validation?.positionOffset);
52
+ } else {
53
+ super.validatePrefix(identifier.substring(this._prefixPosition), validation?.positionOffset === undefined ? this._prefixPosition : validation.positionOffset + this._prefixPosition);
54
+ }
55
+
56
+ // Validate the length.
57
+ if (identifier.length !== this.length) {
58
+ throw new RangeError(i18nextGS1.t("Identifier.identifierTypeLength", {
59
+ identifierType: this.identifierType,
60
+ length: this.length
61
+ }));
62
+ }
63
+
64
+ // Validating the check digit will also validate the characters.
65
+ if (!hasValidCheckDigit(this.padIdentifier(identifier, validation?.positionOffset))) {
66
+ throw new RangeError(i18nextGS1.t("Identifier.invalidCheckDigit"));
67
+ }
68
+ }
69
+ }
@@ -1,8 +1,8 @@
1
1
  import { CharacterSetCreator, CharacterSetValidator, Exclusions } from "@aidc-toolkit/utility";
2
2
 
3
3
  /**
4
- * GS1 AI encodable character set 82 creator as defined in section 7.11 of the {@link https://www.gs1.org/genspecs | GS1
5
- * General Specifications}. Supports {@linkcode Exclusions.AllNumeric}.
4
+ * GS1 AI encodable character set 82 creator as defined in section 7.11 of the {@link
5
+ * https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}. Supports {@linkcode Exclusions.AllNumeric}.
6
6
  */
7
7
  export const AI82_CREATOR = new CharacterSetCreator([
8
8
  "!", "\"", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/",
@@ -16,14 +16,14 @@ export const AI82_CREATOR = new CharacterSetCreator([
16
16
  ], Exclusions.AllNumeric);
17
17
 
18
18
  /**
19
- * GS1 AI encodable character set 82 validator as defined in section 7.11 of the {@link https://www.gs1.org/genspecs |
20
- * GS1 General Specifications}. Supports {@linkcode Exclusions.AllNumeric}.
19
+ * GS1 AI encodable character set 82 validator as defined in section 7.11 of the {@link
20
+ * https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}. Supports {@linkcode Exclusions.AllNumeric}.
21
21
  */
22
22
  export const AI82_VALIDATOR = AI82_CREATOR as CharacterSetValidator;
23
23
 
24
24
  /**
25
- * GS1 AI encodable character set 39 creator as defined in section 7.11 of the {@link https://www.gs1.org/genspecs | GS1
26
- * General Specifications}. Supports {@linkcode Exclusions.AllNumeric}.
25
+ * GS1 AI encodable character set 39 creator as defined in section 7.11 of the {@link
26
+ * https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}. Supports {@linkcode Exclusions.AllNumeric}.
27
27
  */
28
28
  export const AI39_CREATOR = new CharacterSetCreator([
29
29
  "#", "-", "/",
@@ -33,14 +33,14 @@ export const AI39_CREATOR = new CharacterSetCreator([
33
33
  ], Exclusions.AllNumeric);
34
34
 
35
35
  /**
36
- * GS1 AI encodable character set 39 validator as defined in section 7.11 of the {@link https://www.gs1.org/genspecs |
37
- * GS1 General Specifications}. Supports {@linkcode Exclusions.AllNumeric}.
36
+ * GS1 AI encodable character set 39 validator as defined in section 7.11 of the {@link
37
+ * https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}. Supports {@linkcode Exclusions.AllNumeric}.
38
38
  */
39
39
  export const AI39_VALIDATOR = AI39_CREATOR as CharacterSetValidator;
40
40
 
41
41
  /**
42
- * GS1 AI encodable character set 64 validator as defined in section 7.11 of the {@link https://www.gs1.org/genspecs |
43
- * GS1 General Specifications}. Doesn't support any exclusions.
42
+ * GS1 AI encodable character set 64 validator as defined in section 7.11 of the {@link
43
+ * https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}. Doesn't support any exclusions.
44
44
  */
45
45
  export const AI64_VALIDATOR = new CharacterSetValidator([
46
46
  "-",
package/src/check.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { NUMERIC_CREATOR, utilityNS } from "@aidc-toolkit/utility";
2
- import { AI82_CREATOR } from "./character-set";
3
- import { i18nextGS1 } from "./locale/i18n";
2
+ import { AI82_CREATOR } from "./character-set.js";
3
+ import { i18nextGS1 } from "./locale/i18n.js";
4
4
 
5
5
  /**
6
6
  * Results of multiplying digits by 3.
@@ -38,8 +38,8 @@ const INVERSE_FIVE_MINUS_WEIGHT_RESULTS: readonly number[] = [
38
38
  ];
39
39
 
40
40
  /**
41
- * Calculate the check digit sum for a numeric string as per section 7.9.1 of the {@link https://www.gs1.org/genspecs |
42
- * GS1 General Specifications}.
41
+ * Calculate the check digit sum for a numeric string as per section 7.9.1 of the {@link
42
+ * https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}.
43
43
  *
44
44
  * @param exchangeWeights
45
45
  * If true, start the weights at 1 instead of 3 on the right.
@@ -71,8 +71,8 @@ export function checkDigitSum(exchangeWeights: boolean, s: string): number {
71
71
  }
72
72
 
73
73
  /**
74
- * Calculate the check digit for a numeric string as per section 7.9.1 of the {@link https://www.gs1.org/genspecs | GS1
75
- * General Specifications}.
74
+ * Calculate the check digit for a numeric string as per section 7.9.1 of the {@link
75
+ * https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}.
76
76
  *
77
77
  * @param s
78
78
  * Numeric string.
@@ -129,8 +129,8 @@ function priceOrWeightSum(weightsResults: ReadonlyArray<readonly number[]>, s: s
129
129
  }
130
130
 
131
131
  /**
132
- * Calculate the price or weight check digit for a four-or five-digit numeric string as per section 7.9.3 of the {@link
133
- * https://www.gs1.org/genspecs | GS1 General Specifications}.
132
+ * Calculate the price or weight check digit for a four-or five-digit numeric string as per sections 7.9.2-7.9.4 of the
133
+ * {@link https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}.
134
134
  *
135
135
  * @param s
136
136
  * Numeric string exactly four or five characters long.
@@ -192,7 +192,7 @@ const CHECK_CHARACTERS = [
192
192
 
193
193
  /**
194
194
  * Calculate the check character for a GS1 AI encodable character set 82 string as per section 7.9.5 of the {@link
195
- * https://www.gs1.org/genspecs | GS1 General Specifications}.
195
+ * https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}.
196
196
  *
197
197
  * @param s
198
198
  * GS1 AI encodable character set 82 string.
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Character sets supported by the reference portion of an identifier or the serial component of a numeric identifier.
3
+ */
4
+ export const ContentCharacterSets = {
5
+ /**
6
+ * Numeric.
7
+ */
8
+ Numeric: "Numeric",
9
+
10
+ /**
11
+ * GS1 AI encodable character set 82.
12
+ */
13
+ AI82: "AI82",
14
+
15
+ /**
16
+ * GS1 AI encodable character set 39.
17
+ */
18
+ AI39: "AI39"
19
+ } as const;
20
+
21
+ /**
22
+ * Content character set key.
23
+ */
24
+ export type ContentCharacterSetKey = keyof typeof ContentCharacterSets;
25
+
26
+ /**
27
+ * Content character set.
28
+ */
29
+ export type ContentCharacterSet = typeof ContentCharacterSets[ContentCharacterSetKey];
@@ -0,0 +1,113 @@
1
+ import {
2
+ isGTINDescriptor,
3
+ isNonGTINNumericIdentifierDescriptor,
4
+ isNonNumericIdentifierDescriptor,
5
+ isNumericIdentifierDescriptor,
6
+ isSerializableNumericIdentifierDescriptor
7
+ } from "./descriptors.js";
8
+ import type { GTINCreator } from "./gtin-creator.js";
9
+ import type { IdentifierCreator } from "./identifier-creator.js";
10
+ import type { IdentifierType, IdentifierTypes } from "./identifier-type.js";
11
+ import type { NonGTINNumericIdentifierCreator } from "./non-gtin-numeric-identifier-creator.js";
12
+ import type { NonGTINNumericIdentifierType } from "./non-gtin-numeric-identifier-type.js";
13
+ import type { NonNumericIdentifierCreator } from "./non-numeric-identifier-creator.js";
14
+ import type { NonNumericIdentifierType } from "./non-numeric-identifier-type.js";
15
+ import type { NumericIdentifierCreator } from "./numeric-identifier-creator.js";
16
+ import type { SerializableNumericIdentifierCreator } from "./serializable-numeric-identifier-creator.js";
17
+ import type { SerializableNumericIdentifierType } from "./serializable-numeric-identifier-type.js";
18
+
19
+ /**
20
+ * Determine the identifier creator type for an identifier type.
21
+ *
22
+ * @template TIdentifierType
23
+ * Identifier type type.
24
+ */
25
+ export type IdentifierTypeCreator<TIdentifierType extends IdentifierType> = TIdentifierType extends NonNumericIdentifierType ?
26
+ NonNumericIdentifierCreator :
27
+ TIdentifierType extends SerializableNumericIdentifierType ?
28
+ SerializableNumericIdentifierCreator :
29
+ TIdentifierType extends NonGTINNumericIdentifierType ?
30
+ NonGTINNumericIdentifierCreator :
31
+ TIdentifierType extends typeof IdentifierTypes.GTIN ?
32
+ GTINCreator :
33
+ IdentifierCreator;
34
+
35
+ /**
36
+ * Identifier creators entry type based on identifier type type.
37
+ *
38
+ * @template TIdentifierType
39
+ * Identifier type type.
40
+ */
41
+ export type IdentifierCreatorsEntry<TIdentifierType extends IdentifierType> = IdentifierTypeCreator<TIdentifierType>;
42
+
43
+ /**
44
+ * Identifier creators record type.
45
+ */
46
+ export type IdentifierCreatorsRecord = {
47
+ [TIdentifierType in IdentifierType]: IdentifierCreatorsEntry<TIdentifierType>;
48
+ };
49
+
50
+ /**
51
+ * Determine if identifier creator is a numeric identifier creator.
52
+ *
53
+ * @param identifierCreator
54
+ * Identifier creator.
55
+ *
56
+ * @returns
57
+ * True if identifier creator is a numeric identifier creator.
58
+ */
59
+ export function isNumericIdentifierCreator(identifierCreator: IdentifierCreator): identifierCreator is NumericIdentifierCreator {
60
+ return isNumericIdentifierDescriptor(identifierCreator);
61
+ }
62
+
63
+ /**
64
+ * Determine if identifier creator is a GTIN creator.
65
+ *
66
+ * @param identifierCreator
67
+ * Identifier creator.
68
+ *
69
+ * @returns
70
+ * True if identifier creator is a GTIN creator.
71
+ */
72
+ export function isGTINCreator(identifierCreator: IdentifierCreator): identifierCreator is GTINCreator {
73
+ return isGTINDescriptor(identifierCreator);
74
+ }
75
+
76
+ /**
77
+ * Determine if identifier creator is a non-GTIN numeric identifier creator.
78
+ *
79
+ * @param identifierCreator
80
+ * Identifier creator.
81
+ *
82
+ * @returns
83
+ * True if identifier creator is a non-GTIN numeric identifier creator.
84
+ */
85
+ export function isNonGTINNumericIdentifierCreator(identifierCreator: IdentifierCreator): identifierCreator is NonGTINNumericIdentifierCreator {
86
+ return isNonGTINNumericIdentifierDescriptor(identifierCreator);
87
+ }
88
+
89
+ /**
90
+ * Determine if identifier creator is a serializable numeric identifier creator.
91
+ *
92
+ * @param identifierCreator
93
+ * Identifier creator.
94
+ *
95
+ * @returns
96
+ * True if identifier creator is a serializable numeric identifier creator.
97
+ */
98
+ export function isSerializableNumericIdentifierCreator(identifierCreator: IdentifierCreator): identifierCreator is SerializableNumericIdentifierCreator {
99
+ return isSerializableNumericIdentifierDescriptor(identifierCreator);
100
+ }
101
+
102
+ /**
103
+ * Determine if identifier creator is a non-numeric identifier creator.
104
+ *
105
+ * @param identifierCreator
106
+ * Identifier creator.
107
+ *
108
+ * @returns
109
+ * True if identifier creator is a non-numeric identifier creator.
110
+ */
111
+ export function isNonNumericIdentifierCreator(identifierCreator: IdentifierCreator): identifierCreator is NonNumericIdentifierCreator {
112
+ return isNonNumericIdentifierDescriptor(identifierCreator);
113
+ }