@aidc-toolkit/utility 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 (72) 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 -947
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +8 -3504
  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 +11 -7
  50. package/src/character-set.ts +20 -19
  51. package/src/exclusion.ts +6 -1
  52. package/src/index.ts +9 -9
  53. package/src/locale/i18n.ts +3 -3
  54. package/src/locale/i18next.d.ts +1 -1
  55. package/src/record.ts +2 -2
  56. package/src/reg-exp.ts +7 -7
  57. package/src/string.ts +3 -3
  58. package/src/transformer.ts +19 -18
  59. package/test/character-set.test.ts +1 -1
  60. package/test/record.test.ts +4 -2
  61. package/test/reg-exp.test.ts +1 -1
  62. package/test/sequence.test.ts +1 -1
  63. package/test/setup.ts +1 -1
  64. package/test/transformer.test.ts +1 -1
  65. package/tsconfig-config.json +4 -0
  66. package/tsconfig-src.json +8 -0
  67. package/tsconfig-test.json +9 -0
  68. package/tsconfig.json +12 -1
  69. package/tsup.config.ts +3 -2
  70. package/dist/index.cjs +0 -3569
  71. package/dist/index.cjs.map +0 -1
  72. package/dist/index.d.cts +0 -947
package/dist/index.d.cts DELETED
@@ -1,947 +0,0 @@
1
- import { I18nEnvironment } from '@aidc-toolkit/core';
2
- import { Resource, i18n } from 'i18next';
3
-
4
- declare const _default: {
5
- readonly Transformer: {
6
- readonly domainMustBeGreaterThanZero: "Domain {{domain, number}} must be greater than 0";
7
- readonly tweakMustBeGreaterThanOrEqualToZero: "Tweak {{tweak, number}} must be greater than or equal to 0";
8
- readonly valueMustBeGreaterThanOrEqualToZero: "Value {{value, number}} must be greater than or equal to 0";
9
- readonly valueMustBeLessThan: "Value {{value, number}} must be less than {{domain, number}}";
10
- readonly minimumValueMustBeGreaterThanOrEqualToZero: "Minimum value {{minimumValue, number}} must be greater than or equal to 0";
11
- readonly maximumValueMustBeLessThan: "Maximum value {{maximumValue, number}} must be less than {{domain, number}}";
12
- };
13
- readonly RegExpValidator: {
14
- readonly stringDoesNotMatchPattern: "String {{s}} does not match pattern";
15
- };
16
- readonly CharacterSetValidator: {
17
- readonly firstZeroFirstCharacter: "Character set must support zero as first character";
18
- readonly allNumericAllNumericCharacters: "Character set must support all numeric characters in sequence";
19
- readonly stringMustNotBeAllNumeric: "String must not be all numeric";
20
- readonly lengthMustBeGreaterThanOrEqualTo: "Length {{length, number}} must be greater than or equal to {{minimumLength, number}}";
21
- readonly lengthMustBeLessThanOrEqualTo: "Length {{length, number}} must be less than or equal to {{maximumLength, number}}";
22
- readonly lengthMustBeEqualTo: "Length {{length, number}} must be equal to {{exactLength, number}}";
23
- readonly lengthOfComponentMustBeGreaterThanOrEqualTo: "Length {{length, number}} of {{component}} must be greater than or equal to {{minimumLength, number}}";
24
- readonly lengthOfComponentMustBeLessThanOrEqualTo: "Length {{length, number}} of {{component}} must be less than or equal to {{maximumLength, number}}";
25
- readonly lengthOfComponentMustBeEqualTo: "Length {{length, number}} of {{component}} must be equal to {{exactLength, number}}";
26
- readonly invalidCharacterAtPosition: "Invalid character '{{c}}' at position {{position, number}}";
27
- readonly invalidCharacterAtPositionOfComponent: "Invalid character '{{c}}' at position {{position, number}} of {{component}}";
28
- readonly exclusionNotSupported: "Exclusion value of {{exclusion, number}} is not supported";
29
- readonly endSequenceValueMustBeLessThanOrEqualTo: "End sequence value (start sequence value + count - 1) must be less than {{domain, number}}";
30
- };
31
- readonly RecordValidator: {
32
- readonly typeNameKeyNotFound: "{{typeName}} \"{{key}}\" not found";
33
- };
34
- };
35
-
36
- declare const utilityNS = "aidct_utility";
37
- /**
38
- * Locale strings type is extracted from the English locale strings object.
39
- */
40
- type UtilityLocaleResources = typeof _default;
41
- /**
42
- * Utility resources.
43
- */
44
- declare const utilityResources: Resource;
45
- declare const i18nextUtility: i18n;
46
- /**
47
- * Initialize internationalization.
48
- *
49
- * @param environment
50
- * Environment in which the application is running.
51
- *
52
- * @param debug
53
- * Debug setting.
54
- *
55
- * @returns
56
- * Void promise.
57
- */
58
- declare function i18nUtilityInit(environment: I18nEnvironment, debug?: boolean): Promise<void>;
59
-
60
- /**
61
- * Sequence. Defines an ascending or descending sequence of big integers implemented as an iterable.
62
- */
63
- declare class Sequence implements Iterable<bigint> {
64
- /**
65
- * Start value (inclusive).
66
- */
67
- private readonly _startValue;
68
- /**
69
- * End value (exclusive).
70
- */
71
- private readonly _endValue;
72
- /**
73
- * Count of values.
74
- */
75
- private readonly _count;
76
- /**
77
- * Delta to the next value; equal to the sign of the count.
78
- */
79
- private readonly _nextDelta;
80
- /**
81
- * Minimum value (inclusive).
82
- */
83
- private readonly _minimumValue;
84
- /**
85
- * Maximum value (inclusive).
86
- */
87
- private readonly _maximumValue;
88
- /**
89
- * Constructor.
90
- *
91
- * @param startValue
92
- * Start value.
93
- *
94
- * @param count
95
- * Count of values. If count is zero or positive, iteration ascends from start value, otherwise it descends from
96
- * start value.
97
- */
98
- constructor(startValue: number | bigint, count: number);
99
- /**
100
- * Get the start value (inclusive).
101
- */
102
- get startValue(): bigint;
103
- /**
104
- * Get the end value (exclusive).
105
- */
106
- get endValue(): bigint;
107
- /**
108
- * Get the count of values.
109
- */
110
- get count(): number;
111
- /**
112
- * Get the minimum value (inclusive).
113
- */
114
- get minimumValue(): bigint;
115
- /**
116
- * Get the maximum value (inclusive).
117
- */
118
- get maximumValue(): bigint;
119
- /**
120
- * Iterable implementation.
121
- *
122
- * @yields
123
- * Next value in sequence.
124
- */
125
- [Symbol.iterator](): Generator<bigint>;
126
- }
127
-
128
- /**
129
- * Indexed callback, used to map an input and optionally its index in an iterable to an output.
130
- *
131
- * @template TInput
132
- * Input type.
133
- *
134
- * @template TOutput
135
- * Output type.
136
- *
137
- * @param input
138
- * Input value.
139
- *
140
- * @param index
141
- * Index in iterable or undefined for single mapping).
142
- *
143
- * @returns
144
- * Output value.
145
- */
146
- type IndexedCallback<TInput, TOutput> = (input: TInput, index?: number) => TOutput;
147
- /**
148
- * Map an input iterable to an output iterable that applies a transformer callback to each value in the input.
149
- *
150
- * @template TInput
151
- * Input type.
152
- *
153
- * @template TOutput
154
- * Output type.
155
- *
156
- * @param values
157
- * Input values iterable.
158
- *
159
- * @param indexedCallback
160
- * Callback to transform input value to output value.
161
- *
162
- * @returns
163
- * Output values iterable.
164
- */
165
- declare function mapIterable<TInput, TOutput>(values: Iterable<TInput>, indexedCallback: IndexedCallback<TInput, TOutput>): Iterable<TOutput>;
166
-
167
- /**
168
- * Transformer primitive type.
169
- */
170
- type TransformerPrimitive = string | number | bigint | boolean;
171
- /**
172
- * Transformer input type, one of:
173
- *
174
- * - TInput (primitive type)
175
- * - Iterable\<TInput\>
176
- *
177
- * @template TInput
178
- * Transformer input primitive type.
179
- */
180
- type TransformerInput<TInput extends TransformerPrimitive> = TInput | Iterable<TInput>;
181
- /**
182
- * Transformer output, based on transformer input:
183
- *
184
- * - If type TTransformerInput is primitive, result is type TOutput.
185
- * - If type TTransformerInput is Iterable, result is type Iterable\<TOutput\>.
186
- *
187
- * @template TTransformerInput
188
- * Transformer input type.
189
- *
190
- * @template TOutput
191
- * Output base type.
192
- */
193
- type TransformerOutput<TTransformerInput extends TransformerInput<TransformerPrimitive>, TOutput> = TTransformerInput extends (TTransformerInput extends TransformerInput<infer TInput> ? TInput : never) ? TOutput : Iterable<TOutput>;
194
- /**
195
- * Transformer that transforms values in a numeric domain to values in a range equal to the domain or to another range
196
- * defined by a callback function. In other words, the domain determines valid input values and, without a callback, the
197
- * range of valid output values.
198
- *
199
- * The concept is similar to {@link https://en.wikipedia.org/wiki/Format-preserving_encryption | format-preserving
200
- * encryption}, where input values within a specified domain (e.g., {@link
201
- * https://en.wikipedia.org/wiki/Payment_card_number | payment card numbers} ranging from 8-19 digits) are transformed
202
- * into values in the same domain, typically for storage in a database where the data type and length are already fixed
203
- * and exfiltration of the data can have significant repercussions.
204
- *
205
- * Two subclasses are supported directly by this class: {@link IdentityTransformer} (which operates based on a domain
206
- * only) and {@link EncryptionTransformer} (which operates based on a domain and a tweak). If an application is expected
207
- * to make repeated use of a transformer with the same domain and (optional) tweak and can't manage the transformer
208
- * object, an in-memory cache is available via the {@link get} method. Properties in {@link IdentityTransformer} and
209
- * {@link EncryptionTransformer} are read-only once constructed, so there is no issue with their shared use.
210
- */
211
- declare abstract class Transformer {
212
- /**
213
- * Transformers cache, mapping a domain to another map, which maps an optional tweak to a transformer.
214
- */
215
- private static readonly TRANSFORMER_MAPS_MAP;
216
- /**
217
- * Domain.
218
- */
219
- private readonly _domain;
220
- /**
221
- * Constructor.
222
- *
223
- * @param domain
224
- * Domain.
225
- */
226
- constructor(domain: number | bigint);
227
- /**
228
- * Get a transformer, constructing it if necessary. The type returned is {@link IdentityTransformer} if tweak is
229
- * undefined, {@link EncryptionTransformer} if tweak is defined. Note that although an {@link EncryptionTransformer}
230
- * with a zero tweak operates as an {@link IdentityTransformer}, {@link EncryptionTransformer} is still the type
231
- * returned if a zero tweak is explicitly specified.
232
- *
233
- * @param domain
234
- * Domain.
235
- *
236
- * @param tweak
237
- * Tweak.
238
- *
239
- * @returns
240
- * {@link IdentityTransformer} if tweak is undefined, {@link EncryptionTransformer} if tweak is defined.
241
- */
242
- static get(domain: number | bigint, tweak?: number | bigint): Transformer;
243
- /**
244
- * Get the domain.
245
- */
246
- get domain(): bigint;
247
- /**
248
- * Validate that a value is within the domain.
249
- *
250
- * @param value
251
- * Value.
252
- */
253
- private validate;
254
- /**
255
- * Do the work of transforming a value forward.
256
- *
257
- * @param value
258
- * Value.
259
- *
260
- * @returns
261
- * Transformed value.
262
- */
263
- protected abstract doForward(value: bigint): bigint;
264
- /**
265
- * Validate that a value is within the domain and do the work of transforming it forward.
266
- *
267
- * @param value
268
- * Value.
269
- *
270
- * @returns
271
- * Transformed value.
272
- */
273
- private validateDoForward;
274
- /**
275
- * Validate that a value is within the domain, do the work of transforming it forward, and apply a callback.
276
- *
277
- * @param transformerCallback
278
- * Called after each value is transformed to convert it to its final value.
279
- *
280
- * @param value
281
- * Value.
282
- *
283
- * @param index
284
- * Index in sequence (0 for single transformation).
285
- *
286
- * @returns
287
- * Transformed value.
288
- */
289
- private validateDoForwardCallback;
290
- /**
291
- * Transform value(s) forward.
292
- *
293
- * @template TTransformerInput
294
- * Value(s) input type.
295
- *
296
- * @param valueOrValues
297
- * Value(s). If this is an instance of {@link Sequence}, the minimum and maximum values are validated prior to
298
- * transformation. Otherwise, the individual value(s) is/are validated at the time of transformation.
299
- *
300
- * @returns
301
- * Transformed value(s).
302
- */
303
- forward<TTransformerInput extends TransformerInput<number | bigint>>(valueOrValues: TTransformerInput): TransformerOutput<TTransformerInput, bigint>;
304
- /**
305
- * Transform value(s) forward, optionally applying a transformation.
306
- *
307
- * @template TTransformerInput
308
- * Value(s) input type.
309
- *
310
- * @template TOutput
311
- * Transformation callback output type.
312
- *
313
- * @param valueOrValues
314
- * Value(s). If this is an instance of {@link Sequence}, the minimum and maximum values are validated prior to
315
- * transformation. Otherwise, the individual value(s) is/are validated at the time of transformation.
316
- *
317
- * @param transformerCallback
318
- * Called after each value is transformed to convert it to its final value.
319
- *
320
- * @returns
321
- * Transformed value(s).
322
- */
323
- forward<TTransformerInput extends TransformerInput<number | bigint>, TOutput>(valueOrValues: TTransformerInput, transformerCallback: IndexedCallback<bigint, TOutput>): TransformerOutput<TTransformerInput, TOutput>;
324
- /**
325
- * Do the work of transforming a value in reverse.
326
- *
327
- * @param transformedValue
328
- * Transformed value.
329
- *
330
- * @returns
331
- * Value.
332
- */
333
- protected abstract doReverse(transformedValue: bigint): bigint;
334
- /**
335
- * Transform a value in reverse.
336
- *
337
- * @param transformedValue
338
- * Transformed value.
339
- *
340
- * @returns
341
- * Value.
342
- */
343
- reverse(transformedValue: number | bigint): bigint;
344
- }
345
- /**
346
- * Identity transformer. Values are transformed to themselves.
347
- */
348
- declare class IdentityTransformer extends Transformer {
349
- /**
350
- * @inheritDoc
351
- */
352
- protected doForward(value: bigint): bigint;
353
- /**
354
- * @inheritDoc
355
- */
356
- protected doReverse(transformedValue: bigint): bigint;
357
- }
358
- /**
359
- * Encryption transformer. Values are transformed using repeated shuffle and xor operations, similar to those found in
360
- * many cryptography algorithms, particularly AES. While sufficient for obfuscation of numeric sequences (e.g., serial
361
- * number generation, below), if true format-preserving encryption is required, a more robust algorithm such as
362
- * {@link https://doi.org/10.6028/NIST.SP.800-38Gr1-draft | FF1} is recommended. Furthermore, no work has been done to
363
- * mitigate {@link https://timing.attacks.cr.yp.to/index.html | timing attacks} for key detection.
364
- *
365
- * The purpose of the encryption transformer is to generate pseudo-random values in a deterministic manner to obscure
366
- * the sequence of values generated over time. A typical example is for serial number generation, where knowledge of the
367
- * sequence can infer production volumes (e.g., serial number 1000 implies that at least 1,000 units have been
368
- * manufactured) or can be used in counterfeiting (e.g., a counterfeiter can generate serial numbers 1001, 1002, ...
369
- * with reasonable confidence that they would be valid if queried).
370
- *
371
- * The domain and the tweak together determine the encryption key, which in turn determines the number of rounds of
372
- * shuffle and xor operations. The minimum number of rounds is 4, except where the domain is less than or equal to 256,
373
- * which results in single-byte operations. To ensure that the operations are effective for single-byte domains, the
374
- * number of rounds is 1 and only the xor operation is applied (shuffling a single byte is an identity operation).
375
- *
376
- * Another exception is when there is a tweak value of 0; this results in identity operations where the output value is
377
- * identical to the input value, as no shuffle or xor takes place.
378
- */
379
- declare class EncryptionTransformer extends Transformer {
380
- /**
381
- * Individual bits, pre-calculated for performance.
382
- */
383
- private static readonly BITS;
384
- /**
385
- * Inverse individual bits, pre-calculated for performance.
386
- */
387
- private static readonly INVERSE_BITS;
388
- /**
389
- * Number of bytes covered by the domain.
390
- */
391
- private readonly _domainBytes;
392
- /**
393
- * Xor bytes array generated from the domain and tweak.
394
- */
395
- private readonly _xorBytes;
396
- /**
397
- * Bits array generated from the domain and tweak.
398
- */
399
- private readonly _bits;
400
- /**
401
- * Inverse bits array generated from the domain and tweak.
402
- */
403
- private readonly _inverseBits;
404
- /**
405
- * Number of rounds (length of arrays) generated from the domain and tweak.
406
- */
407
- private readonly _rounds;
408
- /**
409
- * Constructor.
410
- *
411
- * @param domain
412
- * Domain.
413
- *
414
- * @param tweak
415
- * Tweak.
416
- */
417
- constructor(domain: number | bigint, tweak: number | bigint);
418
- /**
419
- * Convert a value to a byte array big enough to handle the entire domain.
420
- *
421
- * @param value
422
- * Value.
423
- *
424
- * @returns
425
- * Big-endian byte array equivalent to the value.
426
- */
427
- private valueToBytes;
428
- /**
429
- * Convert a byte array to a value.
430
- *
431
- * @param bytes
432
- * Big-endian byte array equivalent to the value.
433
- *
434
- * @returns
435
- * Value.
436
- */
437
- private static bytesToValue;
438
- /**
439
- * Shuffle a byte array.
440
- *
441
- * The input array to the forward operation (output from the reverse operation) is `bytes` and the output array from
442
- * the forward operation (input to the reverse operation) is `bytes'`.
443
- *
444
- * The shuffle operation starts by testing the bit at `bits[round]` for each `byte` in `bytes`. The indexes for all
445
- * bytes with that bit set are put into one array (`shuffleIndexes1`) and the rest are put into another
446
- * (`shuffleIndexes0`). The two arrays are concatenated and used to shuffle the input array, using their values
447
- * (`shuffleIndex`) and the indexes of those values (`index`) in the concatenated array.
448
- *
449
- * Forward shuffling moves the entry at `shuffleIndex` to the `index` position.
450
- *
451
- * Reverse shuffling moves the entry at `index` to the `shuffleIndex` position.
452
- *
453
- * As each byte is moved, the bit at `bits[round]` is preserved in its original position. This ensures that the
454
- * process is reversible.
455
- *
456
- * @param bytes
457
- * Byte array.
458
- *
459
- * @param round
460
- * Round number.
461
- *
462
- * @param forward
463
- * True if operating forward (encrypting), false if operating in reverse (decrypting).
464
- *
465
- * @returns
466
- * Shuffled byte array.
467
- */
468
- private shuffle;
469
- /**
470
- * Xor a byte array.
471
- *
472
- * The input array to the forward operation (output from the reverse operation) is `bytes` and the output array from
473
- * the forward operation (input to the reverse operation) is `bytes'`.
474
- *
475
- * Forward:
476
- * - `bytes'[0] = bytes[0] ^ xorBytes[round]`
477
- * - `bytes'[1] = bytes[1] ^ bytes'[0]`
478
- * - `bytes'[2] = bytes[2] ^ bytes'[1]`
479
- * - `...`
480
- * - `bytes'[domainBytes - 1] = bytes[domainBytes - 1] ^ bytes'[domainBytes - 2]`
481
- *
482
- * Reverse:
483
- * - `bytes[0] = bytes'[0] ^ xorBytes[round]`
484
- * - `bytes[1] = bytes'[1] ^ bytes'[0]`
485
- * - `bytes[2] = bytes'[2] ^ bytes'[1]`
486
- * - `...`
487
- * - `bytes[domainBytes - 1] = bytes'[domainBytes - 1] ^ bytes'[domainBytes - 2]`
488
- *
489
- * @param bytes
490
- * Byte array.
491
- *
492
- * @param round
493
- * Round number.
494
- *
495
- * @param forward
496
- * True if operating forward (encrypting), false if operating in reverse (decrypting).
497
- *
498
- * @returns
499
- * Xored byte array.
500
- */
501
- private xor;
502
- /**
503
- * @inheritDoc
504
- */
505
- protected doForward(value: bigint): bigint;
506
- /**
507
- * @inheritDoc
508
- */
509
- protected doReverse(transformedValue: bigint): bigint;
510
- }
511
-
512
- /**
513
- * String validation interface. To ensure signature compatibility in implementing classes, string validation is
514
- * controlled by validation interfaces specific to each validator type.
515
- */
516
- interface StringValidation {
517
- }
518
- /**
519
- * String validator interface.
520
- *
521
- * @template V
522
- * String validation type.
523
- */
524
- interface StringValidator<V extends StringValidation = StringValidation> {
525
- /**
526
- * Validate a string and throw an error if validation fails.
527
- *
528
- * @param s
529
- * String.
530
- *
531
- * @param validation
532
- * String validation parameters.
533
- */
534
- validate: (s: string, validation?: V) => void;
535
- }
536
-
537
- /**
538
- * Regular expression validator. The regular expression applies to the full string only if constructed as such. For
539
- * example, <code>&#x2F;\d&#x2A;&#x2F;</code> (0 or more digits) matches every string, <code>&#x2F;\d+&#x2F;</code>
540
- * (1 or more digits) matches strings with at least one digit, <code>&#x2F;^\d&#x2A;$&#x2F;</code> matches strings that
541
- * are all digits or empty, and <code>&#x2F;^\d+$&#x2F;</code> matches strings that are all digits and not empty.
542
- *
543
- * Clients of this class are recommended to override the {@link createErrorMessage} method create a more suitable error
544
- * message for their use case.
545
- */
546
- declare class RegExpValidator implements StringValidator {
547
- /**
548
- * Regular expression.
549
- */
550
- private readonly _regExp;
551
- /**
552
- * Constructor.
553
- *
554
- * @param regExp
555
- * Regular expression. See {@link RegExpValidator | class documentation} for notes.
556
- */
557
- constructor(regExp: RegExp);
558
- /**
559
- * Get the regular expression.
560
- */
561
- get regExp(): RegExp;
562
- /**
563
- * Create an error message for a string. The generic error message is sufficient for many use cases but a more
564
- * domain-specific error message, possibly including the pattern itself, is often required.
565
- *
566
- * @param s
567
- * String.
568
- *
569
- * @returns
570
- * Error message.
571
- */
572
- protected createErrorMessage(s: string): string;
573
- /**
574
- * @inheritDoc
575
- */
576
- validate(s: string): void;
577
- }
578
-
579
- /**
580
- * Record validator. Validation is performed against a record with a string key type and throws an error if the key is
581
- * not found.
582
- *
583
- * @template T
584
- * Property type.
585
- */
586
- declare class RecordValidator<T> implements StringValidator {
587
- /**
588
- * Type name for error message.
589
- */
590
- private readonly _typeName;
591
- /**
592
- * Record in which to look up keys.
593
- */
594
- private readonly _record;
595
- /**
596
- * Constructor.
597
- *
598
- * @param typeName
599
- * Type name for error message.
600
- *
601
- * @param record
602
- * Record in which to look up keys.
603
- */
604
- constructor(typeName: string, record: Readonly<Record<string, T>>);
605
- /**
606
- * Get the type name.
607
- */
608
- get typeName(): string;
609
- /**
610
- * Get the record.
611
- */
612
- get record(): Readonly<Record<string, T>>;
613
- /**
614
- * Validate a key by looking it up in the record.
615
- *
616
- * @param key
617
- * Record key.
618
- */
619
- validate(key: string): void;
620
- }
621
-
622
- /**
623
- * Exclusion options for validating and creating strings based on character sets.
624
- */
625
- declare const Exclusions: {
626
- /**
627
- * No strings excluded.
628
- */
629
- readonly None: 0;
630
- /**
631
- * Strings that start with zero ('0') excluded.
632
- */
633
- readonly FirstZero: 1;
634
- /**
635
- * Strings that are all-numeric (e.g., "123456") excluded.
636
- */
637
- readonly AllNumeric: 2;
638
- };
639
- /**
640
- * Exclusion.
641
- */
642
- type Exclusion = typeof Exclusions[keyof typeof Exclusions];
643
-
644
- /**
645
- * Character set validation parameters.
646
- */
647
- interface CharacterSetValidation extends StringValidation {
648
- /**
649
- * Minimum length. If defined and the string is less than this length, an error is thrown.
650
- */
651
- minimumLength?: number | undefined;
652
- /**
653
- * Maximum length. If defined and the string is greater than this length, an error is thrown.
654
- */
655
- maximumLength?: number | undefined;
656
- /**
657
- * Exclusion from the string. If defined and the string is within the exclusion range, an error is thrown.
658
- */
659
- exclusion?: Exclusion | undefined;
660
- /**
661
- * Position offset within a larger string. Strings are sometimes composed of multiple substrings; this parameter
662
- * ensures that the error notes the proper position in the string.
663
- */
664
- positionOffset?: number | undefined;
665
- /**
666
- * Name of component, typically but not exclusively within a larger string. This parameter ensure that the
667
- * error notes the component that triggered it. Value may be a string or a callback that returns a string, the
668
- * latter allowing for localization changes.
669
- */
670
- component?: string | (() => string) | undefined;
671
- }
672
- /**
673
- * Character set validator. Validates a string against a specified character set.
674
- */
675
- declare class CharacterSetValidator implements StringValidator<CharacterSetValidation> {
676
- private static readonly NOT_ALL_NUMERIC_VALIDATOR;
677
- /**
678
- * Character set.
679
- */
680
- private readonly _characterSet;
681
- /**
682
- * Character set map, mapping each character in the character set to its index such that
683
- * `_characterSetMap.get(_characterSet[index]) === index`.
684
- */
685
- private readonly _characterSetMap;
686
- /**
687
- * Exclusions supported by the character set.
688
- */
689
- private readonly _exclusionSupport;
690
- /**
691
- * Constructor.
692
- *
693
- * @param characterSet
694
- * Character set. Each element is a single-character string, unique within the array, that defines the character
695
- * set.
696
- *
697
- * @param exclusionSupport
698
- * Exclusions supported by the character set. All character sets implicitly support {@link Exclusions.None}.
699
- */
700
- constructor(characterSet: readonly string[], ...exclusionSupport: readonly Exclusion[]);
701
- /**
702
- * Get the character set.
703
- */
704
- get characterSet(): readonly string[];
705
- /**
706
- * Get the character set size.
707
- */
708
- get characterSetSize(): number;
709
- /**
710
- * Get the exclusions supported by the character set.
711
- */
712
- get exclusionSupport(): readonly Exclusion[];
713
- /**
714
- * Get the character at an index.
715
- *
716
- * @param index
717
- * Index into the character set.
718
- *
719
- * @returns
720
- * Character at the index.
721
- */
722
- character(index: number): string;
723
- /**
724
- * Get the index for a character.
725
- *
726
- * @param c
727
- * Character.
728
- *
729
- * @returns
730
- * Index for the character or undefined if the character is not in the character set.
731
- */
732
- characterIndex(c: string): number | undefined;
733
- /**
734
- * Get the indexes for all characters in a string.
735
- *
736
- * @param s
737
- * String.
738
- *
739
- * @returns
740
- * Array of indexes for each character or undefined if the character is not in the character set.
741
- */
742
- characterIndexes(s: string): ReadonlyArray<number | undefined>;
743
- /**
744
- * Convert a component definition to a string or undefined. Checks the type of the component and makes the callback
745
- * if required.
746
- *
747
- * @param component
748
- * Component definition as a string, callback, or undefined.
749
- *
750
- * @returns
751
- * Component as a string or undefined.
752
- */
753
- private static componentToString;
754
- /**
755
- * Validate that an exclusion is supported. If not, an error is thrown.
756
- *
757
- * @param exclusion
758
- * Exclusion.
759
- */
760
- protected validateExclusion(exclusion: Exclusion): void;
761
- /**
762
- * Validate a string. If the string violates the character set or any of the character set validation parameters, an
763
- * error is thrown.
764
- *
765
- * @param s
766
- * String.
767
- *
768
- * @param validation
769
- * Character set validation parameters.
770
- */
771
- validate(s: string, validation?: CharacterSetValidation): void;
772
- }
773
- /**
774
- * Character set creator. Maps numeric values to strings using the character set as digits.
775
- */
776
- declare class CharacterSetCreator extends CharacterSetValidator {
777
- /**
778
- * Maximum string length supported.
779
- */
780
- static readonly MAXIMUM_STRING_LENGTH = 40;
781
- /**
782
- * Powers of 10 from 1 (`10**0`) to `10**MAXIMUM_STRING_LENGTH`.
783
- */
784
- private static readonly _powersOf10;
785
- /**
786
- * Create powers of a given base from 1 (`base**0`) to `base**MAXIMUM_STRING_LENGTH`.
787
- *
788
- * @param base
789
- * Number base.
790
- *
791
- * @returns
792
- * Array of powers of base.
793
- */
794
- private static createPowersOf;
795
- /**
796
- * Get a power of 10.
797
- *
798
- * @param power
799
- * Power.
800
- *
801
- * @returns
802
- * `10**power`.
803
- */
804
- static powerOf10(power: number): bigint;
805
- /**
806
- * Character set size as big integer, cached for performance purposes.
807
- */
808
- private readonly _characterSetSizeN;
809
- /**
810
- * Character set size minus 1 as big integer, cached for performance purposes.
811
- */
812
- private readonly _characterSetSizeMinusOneN;
813
- /**
814
- * Domains for every length for every supported {@link Exclusions}.
815
- */
816
- private readonly _exclusionDomains;
817
- /**
818
- * Values that would generate all zeros in the created string.
819
- */
820
- private readonly _allZerosValues;
821
- /**
822
- * Constructor.
823
- *
824
- * @param characterSet
825
- * Character set. Each element is a single-character string, unique within the array, that defines the character
826
- * set.
827
- *
828
- * @param exclusionSupport
829
- * Exclusions supported by the character set. All character sets implicitly support {@link Exclusions.None}.
830
- */
831
- constructor(characterSet: readonly string[], ...exclusionSupport: readonly Exclusion[]);
832
- /**
833
- * Get a power of character set size.
834
- *
835
- * @param power
836
- * Power.
837
- *
838
- * @returns
839
- * `characterSetSize**power`.
840
- */
841
- private powerOfSize;
842
- /**
843
- * Determine the shift required to skip all all-numeric strings up to the value.
844
- *
845
- * @param shiftForward
846
- * True to shift forward (value to string), false to shift backward (string to value).
847
- *
848
- * @param length
849
- * Length of string for which to get the all-numeric shift.
850
- *
851
- * @param value
852
- * Value for which to get the all-numeric shift.
853
- *
854
- * @returns
855
- * Shift required to skip all all-numeric strings.
856
- */
857
- private allNumericShift;
858
- /**
859
- * Validate that a length is less than or equal to {@link MAXIMUM_STRING_LENGTH}. If not, an error is thrown.
860
- *
861
- * @param length
862
- * Length.
863
- */
864
- private validateLength;
865
- /**
866
- * Create string(s) by mapping value(s) to the equivalent characters in the character set across the length of the
867
- * string.
868
- *
869
- * @template TTransformerInput
870
- * Transformer input type.
871
- *
872
- * @param length
873
- * Required string length.
874
- *
875
- * @param valueOrValues
876
- * Numeric value(s) of the string(s).
877
- *
878
- * @param exclusion
879
- * String(s) to be excluded from the range of outputs. See {@link Exclusions} for possible values and their meaning.
880
- *
881
- * @param tweak
882
- * If provided, the numerical value of the string(s) is/are "tweaked" using an {@link EncryptionTransformer |
883
- * encryption transformer}.
884
- *
885
- * @param creatorCallback
886
- * If provided, called after each string is constructed to create the final value.
887
- *
888
- * @returns
889
- * String(s) created from the value(s).
890
- */
891
- create<TTransformerInput extends TransformerInput<number | bigint>>(length: number, valueOrValues: TTransformerInput, exclusion?: Exclusion, tweak?: number | bigint, creatorCallback?: IndexedCallback<string, string>): TransformerOutput<TTransformerInput, string>;
892
- /**
893
- * Determine the value for a string.
894
- *
895
- * @param s
896
- * String.
897
- *
898
- * @param exclusion
899
- * Strings excluded from the range of inputs. See {@link Exclusions} for possible values and their meaning.
900
- *
901
- * @param tweak
902
- * If provided, the numerical value of the string was "tweaked" using an {@link EncryptionTransformer | encryption
903
- * transformer}.
904
- *
905
- * @returns
906
- * Numeric value of the string.
907
- */
908
- valueFor(s: string, exclusion?: Exclusion, tweak?: number | bigint): bigint;
909
- }
910
- /**
911
- * Numeric creator. Character set is 0-9. Supports {@link Exclusions.FirstZero}.
912
- */
913
- declare const NUMERIC_CREATOR: CharacterSetCreator;
914
- /**
915
- * Numeric validator. Character set is 0-9. Supports {@link Exclusions.FirstZero}.
916
- */
917
- declare const NUMERIC_VALIDATOR: CharacterSetValidator;
918
- /**
919
- * Hexadecimal creator. Character set is 0-9, A-F. Supports {@link Exclusions.FirstZero} and {@link
920
- * Exclusions.AllNumeric}.
921
- */
922
- declare const HEXADECIMAL_CREATOR: CharacterSetCreator;
923
- /**
924
- * Hexadecimal validator. Character set is 0-9, A-F. Supports {@link Exclusions.FirstZero} and {@link
925
- * Exclusions.AllNumeric}.
926
- */
927
- declare const HEXADECIMAL_VALIDATOR: CharacterSetValidator;
928
- /**
929
- * Alphabetic creator. Character set is A-Z.
930
- */
931
- declare const ALPHABETIC_CREATOR: CharacterSetCreator;
932
- /**
933
- * Alphabetic validator. Character set is A-Z.
934
- */
935
- declare const ALPHABETIC_VALIDATOR: CharacterSetValidator;
936
- /**
937
- * Alphanumeric creator. Character set is 0-9, A-Z. Supports {@link Exclusions.FirstZero} and {@link
938
- * Exclusions.AllNumeric}.
939
- */
940
- declare const ALPHANUMERIC_CREATOR: CharacterSetCreator;
941
- /**
942
- * Alphanumeric validator. Character set is 0-9, A-Z. Supports {@link Exclusions.FirstZero} and {@link
943
- * Exclusions.AllNumeric}.
944
- */
945
- declare const ALPHANUMERIC_VALIDATOR: CharacterSetValidator;
946
-
947
- export { ALPHABETIC_CREATOR, ALPHABETIC_VALIDATOR, ALPHANUMERIC_CREATOR, ALPHANUMERIC_VALIDATOR, CharacterSetCreator, type CharacterSetValidation, CharacterSetValidator, EncryptionTransformer, type Exclusion, Exclusions, HEXADECIMAL_CREATOR, HEXADECIMAL_VALIDATOR, IdentityTransformer, type IndexedCallback, NUMERIC_CREATOR, NUMERIC_VALIDATOR, RecordValidator, RegExpValidator, Sequence, type StringValidation, type StringValidator, Transformer, type TransformerInput, type TransformerOutput, type TransformerPrimitive, type UtilityLocaleResources, i18nUtilityInit, i18nextUtility, mapIterable, utilityNS, utilityResources };