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