@aidc-toolkit/utility 1.0.25-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 (70) hide show
  1. package/dist/character-set.d.ts +308 -0
  2. package/dist/character-set.d.ts.map +1 -0
  3. package/dist/character-set.js +564 -0
  4. package/dist/character-set.js.map +1 -0
  5. package/dist/exclusion.d.ts +26 -0
  6. package/dist/exclusion.d.ts.map +1 -0
  7. package/dist/exclusion.js +18 -0
  8. package/dist/exclusion.js.map +1 -0
  9. package/dist/index.d.ts +26 -953
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +8 -3505
  12. package/dist/index.js.map +1 -1
  13. package/dist/iterable-utility.d.ts +39 -0
  14. package/dist/iterable-utility.d.ts.map +1 -0
  15. package/dist/iterable-utility.js +35 -0
  16. package/dist/iterable-utility.js.map +1 -0
  17. package/dist/locale/en/locale-resources.d.ts +33 -0
  18. package/dist/locale/en/locale-resources.d.ts.map +1 -0
  19. package/dist/locale/en/locale-resources.js +32 -0
  20. package/dist/locale/en/locale-resources.js.map +1 -0
  21. package/dist/locale/fr/locale-resources.d.ts +33 -0
  22. package/dist/locale/fr/locale-resources.d.ts.map +1 -0
  23. package/dist/locale/fr/locale-resources.js +32 -0
  24. package/dist/locale/fr/locale-resources.js.map +1 -0
  25. package/dist/locale/i18n.d.ts +27 -0
  26. package/dist/locale/i18n.d.ts.map +1 -0
  27. package/dist/locale/i18n.js +34 -0
  28. package/dist/locale/i18n.js.map +1 -0
  29. package/dist/record.d.ts +44 -0
  30. package/dist/record.d.ts.map +1 -0
  31. package/dist/record.js +58 -0
  32. package/dist/record.js.map +1 -0
  33. package/dist/reg-exp.d.ts +43 -0
  34. package/dist/reg-exp.d.ts.map +1 -0
  35. package/dist/reg-exp.js +55 -0
  36. package/dist/reg-exp.js.map +1 -0
  37. package/dist/sequence.d.ts +68 -0
  38. package/dist/sequence.d.ts.map +1 -0
  39. package/dist/sequence.js +96 -0
  40. package/dist/sequence.js.map +1 -0
  41. package/dist/string.d.ts +25 -0
  42. package/dist/string.d.ts.map +1 -0
  43. package/dist/string.js +2 -0
  44. package/dist/string.js.map +1 -0
  45. package/dist/transformer.d.ts +347 -0
  46. package/dist/transformer.d.ts.map +1 -0
  47. package/dist/transformer.js +457 -0
  48. package/dist/transformer.js.map +1 -0
  49. package/package.json +10 -6
  50. package/src/character-set.ts +6 -6
  51. package/src/index.ts +9 -9
  52. package/src/locale/i18n.ts +3 -3
  53. package/src/locale/i18next.d.ts +1 -1
  54. package/src/record.ts +2 -2
  55. package/src/reg-exp.ts +2 -2
  56. package/src/transformer.ts +3 -3
  57. package/test/character-set.test.ts +1 -1
  58. package/test/record.test.ts +1 -1
  59. package/test/reg-exp.test.ts +1 -1
  60. package/test/sequence.test.ts +1 -1
  61. package/test/setup.ts +1 -1
  62. package/test/transformer.test.ts +1 -1
  63. package/tsconfig-config.json +4 -0
  64. package/tsconfig-src.json +8 -0
  65. package/tsconfig-test.json +9 -0
  66. package/tsconfig.json +12 -1
  67. package/tsup.config.ts +3 -2
  68. package/dist/index.cjs +0 -3570
  69. package/dist/index.cjs.map +0 -1
  70. package/dist/index.d.cts +0 -953
@@ -0,0 +1,308 @@
1
+ import { type Exclusion } from "./exclusion.js";
2
+ import type { IndexedCallback } from "./iterable-utility.js";
3
+ import type { StringValidation, StringValidator } from "./string.js";
4
+ import { type TransformerInput, type TransformerOutput } from "./transformer.js";
5
+ /**
6
+ * Character set validation parameters.
7
+ */
8
+ export interface CharacterSetValidation extends StringValidation {
9
+ /**
10
+ * Minimum length. If defined and the string is less than this length, an error is thrown.
11
+ */
12
+ minimumLength?: number | undefined;
13
+ /**
14
+ * Maximum length. If defined and the string is greater than this length, an error is thrown.
15
+ */
16
+ maximumLength?: number | undefined;
17
+ /**
18
+ * Exclusion from the string. If defined and the string is within the exclusion range, an error is thrown.
19
+ */
20
+ exclusion?: Exclusion | undefined;
21
+ /**
22
+ * Position offset within a larger string. Strings are sometimes composed of multiple substrings; this parameter
23
+ * ensures that the error notes the proper position in the string.
24
+ */
25
+ positionOffset?: number | undefined;
26
+ /**
27
+ * Name of component, typically but not exclusively within a larger string. This parameter ensure that the
28
+ * error notes the component that triggered it. Value may be a string or a callback that returns a string, the
29
+ * latter allowing for localization changes.
30
+ */
31
+ component?: string | (() => string) | undefined;
32
+ }
33
+ /**
34
+ * Character set validator. Validates a string against a specified character set.
35
+ */
36
+ export declare class CharacterSetValidator implements StringValidator<CharacterSetValidation> {
37
+ private static readonly NOT_ALL_NUMERIC_VALIDATOR;
38
+ /**
39
+ * Character set.
40
+ */
41
+ private readonly _characterSet;
42
+ /**
43
+ * Character set map, mapping each character in the character set to its index such that
44
+ * `_characterSetMap.get(_characterSet[index]) === index`.
45
+ */
46
+ private readonly _characterSetMap;
47
+ /**
48
+ * Exclusions supported by the character set.
49
+ */
50
+ private readonly _exclusionSupport;
51
+ /**
52
+ * Constructor.
53
+ *
54
+ * @param characterSet
55
+ * Character set. Each element is a single-character string, unique within the array, that defines the character
56
+ * set.
57
+ *
58
+ * @param exclusionSupport
59
+ * Exclusions supported by the character set. All character sets implicitly support {@linkcode Exclusions.None}.
60
+ */
61
+ constructor(characterSet: readonly string[], ...exclusionSupport: readonly Exclusion[]);
62
+ /**
63
+ * Get the character set.
64
+ */
65
+ get characterSet(): readonly string[];
66
+ /**
67
+ * Get the character set size.
68
+ */
69
+ get characterSetSize(): number;
70
+ /**
71
+ * Get the exclusions supported by the character set.
72
+ */
73
+ get exclusionSupport(): readonly Exclusion[];
74
+ /**
75
+ * Get the character at an index.
76
+ *
77
+ * @param index
78
+ * Index into the character set.
79
+ *
80
+ * @returns
81
+ * Character at the index.
82
+ */
83
+ character(index: number): string;
84
+ /**
85
+ * Get the index for a character.
86
+ *
87
+ * @param c
88
+ * Character.
89
+ *
90
+ * @returns
91
+ * Index for the character or undefined if the character is not in the character set.
92
+ */
93
+ characterIndex(c: string): number | undefined;
94
+ /**
95
+ * Get the indexes for all characters in a string.
96
+ *
97
+ * @param s
98
+ * String.
99
+ *
100
+ * @returns
101
+ * Array of indexes for each character or undefined if the character is not in the character set.
102
+ */
103
+ characterIndexes(s: string): ReadonlyArray<number | undefined>;
104
+ /**
105
+ * Convert a component definition to a string or undefined. Checks the type of the component and makes the callback
106
+ * if required.
107
+ *
108
+ * @param component
109
+ * Component definition as a string, callback, or undefined.
110
+ *
111
+ * @returns
112
+ * Component as a string or undefined.
113
+ */
114
+ private static componentToString;
115
+ /**
116
+ * Validate that an exclusion is supported. If not, an error is thrown.
117
+ *
118
+ * @param exclusion
119
+ * Exclusion.
120
+ */
121
+ protected validateExclusion(exclusion: Exclusion): void;
122
+ /**
123
+ * Validate a string. If the string violates the character set or any of the character set validation parameters, an
124
+ * error is thrown.
125
+ *
126
+ * @param s
127
+ * String.
128
+ *
129
+ * @param validation
130
+ * Character set validation parameters.
131
+ */
132
+ validate(s: string, validation?: CharacterSetValidation): void;
133
+ }
134
+ /**
135
+ * Character set creator. Maps numeric values to strings using the character set as digits.
136
+ */
137
+ export declare class CharacterSetCreator extends CharacterSetValidator {
138
+ /**
139
+ * Maximum string length supported.
140
+ */
141
+ static readonly MAXIMUM_STRING_LENGTH = 40;
142
+ /**
143
+ * Powers of 10 from 1 (`10**0`) to `10**MAXIMUM_STRING_LENGTH`.
144
+ */
145
+ private static readonly _powersOf10;
146
+ /**
147
+ * Create powers of a given base from 1 (`base**0`) to `base**MAXIMUM_STRING_LENGTH`.
148
+ *
149
+ * @param base
150
+ * Number base.
151
+ *
152
+ * @returns
153
+ * Array of powers of base.
154
+ */
155
+ private static createPowersOf;
156
+ /**
157
+ * Get a power of 10.
158
+ *
159
+ * @param power
160
+ * Power.
161
+ *
162
+ * @returns
163
+ * `10**power`.
164
+ */
165
+ static powerOf10(power: number): bigint;
166
+ /**
167
+ * Character set size as big integer, cached for performance purposes.
168
+ */
169
+ private readonly _characterSetSizeN;
170
+ /**
171
+ * Character set size minus 1 as big integer, cached for performance purposes.
172
+ */
173
+ private readonly _characterSetSizeMinusOneN;
174
+ /**
175
+ * Domains for every length for every supported {@linkcode Exclusions}.
176
+ */
177
+ private readonly _exclusionDomains;
178
+ /**
179
+ * Values that would generate all zeros in the created string.
180
+ */
181
+ private readonly _allZerosValues;
182
+ /**
183
+ * Constructor.
184
+ *
185
+ * @param characterSet
186
+ * Character set. Each element is a single-character string, unique within the array, that defines the character
187
+ * set.
188
+ *
189
+ * @param exclusionSupport
190
+ * Exclusions supported by the character set. All character sets implicitly support {@linkcode Exclusions.None}.
191
+ */
192
+ constructor(characterSet: readonly string[], ...exclusionSupport: readonly Exclusion[]);
193
+ /**
194
+ * Get a power of character set size.
195
+ *
196
+ * @param power
197
+ * Power.
198
+ *
199
+ * @returns
200
+ * `characterSetSize**power`.
201
+ */
202
+ private powerOfSize;
203
+ /**
204
+ * Determine the shift required to skip all all-numeric strings up to the value.
205
+ *
206
+ * @param shiftForward
207
+ * True to shift forward (value to string), false to shift backward (string to value).
208
+ *
209
+ * @param length
210
+ * Length of string for which to get the all-numeric shift.
211
+ *
212
+ * @param value
213
+ * Value for which to get the all-numeric shift.
214
+ *
215
+ * @returns
216
+ * Shift required to skip all all-numeric strings.
217
+ */
218
+ private allNumericShift;
219
+ /**
220
+ * Validate that a length is less than or equal to {@linkcode MAXIMUM_STRING_LENGTH}. If not, an error is thrown.
221
+ *
222
+ * @param length
223
+ * Length.
224
+ */
225
+ private validateLength;
226
+ /**
227
+ * Create string(s) by mapping value(s) to the equivalent characters in the character set across the length of the
228
+ * string.
229
+ *
230
+ * @template TTransformerInput
231
+ * Transformer input type.
232
+ *
233
+ * @param length
234
+ * Required string length.
235
+ *
236
+ * @param valueOrValues
237
+ * Numeric value(s) of the string(s).
238
+ *
239
+ * @param exclusion
240
+ * String(s) to be excluded from the range of outputs. See {@linkcode Exclusions} for possible values and their
241
+ * meaning.
242
+ *
243
+ * @param tweak
244
+ * If provided, the numerical value of the string(s) is/are "tweaked" using an {@link EncryptionTransformer |
245
+ * encryption transformer}.
246
+ *
247
+ * @param creatorCallback
248
+ * If provided, called after each string is constructed to create the final value.
249
+ *
250
+ * @returns
251
+ * String(s) created from the value(s).
252
+ */
253
+ create<TTransformerInput extends TransformerInput<number | bigint>>(length: number, valueOrValues: TTransformerInput, exclusion?: Exclusion, tweak?: number | bigint, creatorCallback?: IndexedCallback<string, string>): TransformerOutput<TTransformerInput, string>;
254
+ /**
255
+ * Determine the value for a string.
256
+ *
257
+ * @param s
258
+ * String.
259
+ *
260
+ * @param exclusion
261
+ * Strings excluded from the range of inputs. See {@linkcode Exclusions} for possible values and their meaning.
262
+ *
263
+ * @param tweak
264
+ * If provided, the numerical value of the string was "tweaked" using an {@link EncryptionTransformer | encryption
265
+ * transformer}.
266
+ *
267
+ * @returns
268
+ * Numeric value of the string.
269
+ */
270
+ valueFor(s: string, exclusion?: Exclusion, tweak?: number | bigint): bigint;
271
+ }
272
+ /**
273
+ * Numeric creator. Character set is 0-9. Supports {@linkcode Exclusions.FirstZero}.
274
+ */
275
+ export declare const NUMERIC_CREATOR: CharacterSetCreator;
276
+ /**
277
+ * Numeric validator. Character set is 0-9. Supports {@linkcode Exclusions.FirstZero}.
278
+ */
279
+ export declare const NUMERIC_VALIDATOR: CharacterSetValidator;
280
+ /**
281
+ * Hexadecimal creator. Character set is 0-9, A-F. Supports {@linkcode Exclusions.FirstZero} and {@linkcode
282
+ * Exclusions.AllNumeric}.
283
+ */
284
+ export declare const HEXADECIMAL_CREATOR: CharacterSetCreator;
285
+ /**
286
+ * Hexadecimal validator. Character set is 0-9, A-F. Supports {@linkcode Exclusions.FirstZero} and {@linkcode
287
+ * Exclusions.AllNumeric}.
288
+ */
289
+ export declare const HEXADECIMAL_VALIDATOR: CharacterSetValidator;
290
+ /**
291
+ * Alphabetic creator. Character set is A-Z.
292
+ */
293
+ export declare const ALPHABETIC_CREATOR: CharacterSetCreator;
294
+ /**
295
+ * Alphabetic validator. Character set is A-Z.
296
+ */
297
+ export declare const ALPHABETIC_VALIDATOR: CharacterSetValidator;
298
+ /**
299
+ * Alphanumeric creator. Character set is 0-9, A-Z. Supports {@linkcode Exclusions.FirstZero} and {@linkcode
300
+ * Exclusions.AllNumeric}.
301
+ */
302
+ export declare const ALPHANUMERIC_CREATOR: CharacterSetCreator;
303
+ /**
304
+ * Alphanumeric validator. Character set is 0-9, A-Z. Supports {@linkcode Exclusions.FirstZero} and {@linkcode
305
+ * Exclusions.AllNumeric}.
306
+ */
307
+ export declare const ALPHANUMERIC_VALIDATOR: CharacterSetValidator;
308
+ //# sourceMappingURL=character-set.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"character-set.d.ts","sourceRoot":"","sources":["../src/character-set.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAc,MAAM,gBAAgB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAG7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAe,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE9F;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,gBAAgB;IAC5D;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAEnC;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAEnC;;OAEG;IACH,SAAS,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAElC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAEpC;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,SAAS,CAAC;CACnD;AAED;;GAEG;AACH,qBAAa,qBAAsB,YAAW,eAAe,CAAC,sBAAsB,CAAC;IACjF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,yBAAyB,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