@aidc-toolkit/utility 1.0.23-beta → 1.0.25-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 (65) hide show
  1. package/README.md +30 -30
  2. package/dist/index.cjs +3570 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.cts +953 -0
  5. package/dist/index.d.ts +953 -26
  6. package/dist/index.js +3505 -8
  7. package/dist/index.js.map +1 -1
  8. package/package.json +7 -11
  9. package/src/character-set.ts +20 -19
  10. package/src/exclusion.ts +6 -1
  11. package/src/index.ts +9 -9
  12. package/src/locale/i18n.ts +3 -5
  13. package/src/locale/i18next.d.ts +1 -1
  14. package/src/record.ts +2 -2
  15. package/src/reg-exp.ts +7 -7
  16. package/src/string.ts +3 -3
  17. package/src/transformer.ts +19 -18
  18. package/test/record.test.ts +3 -1
  19. package/tsup.config.ts +3 -0
  20. package/typedoc.json +1 -3
  21. package/dist/character-set.d.ts +0 -307
  22. package/dist/character-set.d.ts.map +0 -1
  23. package/dist/character-set.js +0 -563
  24. package/dist/character-set.js.map +0 -1
  25. package/dist/exclusion.d.ts +0 -22
  26. package/dist/exclusion.d.ts.map +0 -1
  27. package/dist/exclusion.js +0 -18
  28. package/dist/exclusion.js.map +0 -1
  29. package/dist/index.d.ts.map +0 -1
  30. package/dist/iterable-utility.d.ts +0 -39
  31. package/dist/iterable-utility.d.ts.map +0 -1
  32. package/dist/iterable-utility.js +0 -35
  33. package/dist/iterable-utility.js.map +0 -1
  34. package/dist/locale/en/locale-resources.d.ts +0 -33
  35. package/dist/locale/en/locale-resources.d.ts.map +0 -1
  36. package/dist/locale/en/locale-resources.js +0 -32
  37. package/dist/locale/en/locale-resources.js.map +0 -1
  38. package/dist/locale/fr/locale-resources.d.ts +0 -33
  39. package/dist/locale/fr/locale-resources.d.ts.map +0 -1
  40. package/dist/locale/fr/locale-resources.js +0 -32
  41. package/dist/locale/fr/locale-resources.js.map +0 -1
  42. package/dist/locale/i18n.d.ts +0 -27
  43. package/dist/locale/i18n.d.ts.map +0 -1
  44. package/dist/locale/i18n.js +0 -35
  45. package/dist/locale/i18n.js.map +0 -1
  46. package/dist/record.d.ts +0 -44
  47. package/dist/record.d.ts.map +0 -1
  48. package/dist/record.js +0 -58
  49. package/dist/record.js.map +0 -1
  50. package/dist/reg-exp.d.ts +0 -43
  51. package/dist/reg-exp.d.ts.map +0 -1
  52. package/dist/reg-exp.js +0 -55
  53. package/dist/reg-exp.js.map +0 -1
  54. package/dist/sequence.d.ts +0 -68
  55. package/dist/sequence.d.ts.map +0 -1
  56. package/dist/sequence.js +0 -96
  57. package/dist/sequence.js.map +0 -1
  58. package/dist/string.d.ts +0 -25
  59. package/dist/string.d.ts.map +0 -1
  60. package/dist/string.js +0 -2
  61. package/dist/string.js.map +0 -1
  62. package/dist/transformer.d.ts +0 -346
  63. package/dist/transformer.d.ts.map +0 -1
  64. package/dist/transformer.js +0 -456
  65. package/dist/transformer.js.map +0 -1
@@ -1,9 +1,9 @@
1
- import { type Exclusion, Exclusions } from "./exclusion.js";
2
- import type { IndexedCallback } from "./iterable-utility.js";
3
- import { i18nextUtility } from "./locale/i18n.js";
4
- import { RegExpValidator } from "./reg-exp.js";
5
- import type { StringValidation, StringValidator } from "./string.js";
6
- import { Transformer, type TransformerInput, type TransformerOutput } from "./transformer.js";
1
+ import { type Exclusion, Exclusions } from "./exclusion";
2
+ import type { IndexedCallback } from "./iterable-utility";
3
+ import { i18nextUtility } from "./locale/i18n";
4
+ import { RegExpValidator } from "./reg-exp";
5
+ import type { StringValidation, StringValidator } from "./string";
6
+ import { Transformer, type TransformerInput, type TransformerOutput } from "./transformer";
7
7
 
8
8
  /**
9
9
  * Character set validation parameters.
@@ -81,7 +81,7 @@ export class CharacterSetValidator implements StringValidator<CharacterSetValida
81
81
  * set.
82
82
  *
83
83
  * @param exclusionSupport
84
- * Exclusions supported by the character set. All character sets implicitly support {@link Exclusions.None}.
84
+ * Exclusions supported by the character set. All character sets implicitly support {@linkcode Exclusions.None}.
85
85
  */
86
86
  constructor(characterSet: readonly string[], ...exclusionSupport: readonly Exclusion[]) {
87
87
  this._characterSet = characterSet;
@@ -324,7 +324,7 @@ export class CharacterSetCreator extends CharacterSetValidator {
324
324
  private readonly _characterSetSizeMinusOneN: bigint;
325
325
 
326
326
  /**
327
- * Domains for every length for every supported {@link Exclusions}.
327
+ * Domains for every length for every supported {@linkcode Exclusions}.
328
328
  */
329
329
  private readonly _exclusionDomains: ReadonlyArray<readonly bigint[]>;
330
330
 
@@ -341,7 +341,7 @@ export class CharacterSetCreator extends CharacterSetValidator {
341
341
  * set.
342
342
  *
343
343
  * @param exclusionSupport
344
- * Exclusions supported by the character set. All character sets implicitly support {@link Exclusions.None}.
344
+ * Exclusions supported by the character set. All character sets implicitly support {@linkcode Exclusions.None}.
345
345
  */
346
346
  constructor(characterSet: readonly string[], ...exclusionSupport: readonly Exclusion[]) {
347
347
  super(characterSet, ...exclusionSupport);
@@ -488,7 +488,7 @@ export class CharacterSetCreator extends CharacterSetValidator {
488
488
  }
489
489
 
490
490
  /**
491
- * Validate that a length is less than or equal to {@link MAXIMUM_STRING_LENGTH}. If not, an error is thrown.
491
+ * Validate that a length is less than or equal to {@linkcode MAXIMUM_STRING_LENGTH}. If not, an error is thrown.
492
492
  *
493
493
  * @param length
494
494
  * Length.
@@ -523,7 +523,8 @@ export class CharacterSetCreator extends CharacterSetValidator {
523
523
  * Numeric value(s) of the string(s).
524
524
  *
525
525
  * @param exclusion
526
- * String(s) to be excluded from the range of outputs. See {@link Exclusions} for possible values and their meaning.
526
+ * String(s) to be excluded from the range of outputs. See {@linkcode Exclusions} for possible values and their
527
+ * meaning.
527
528
  *
528
529
  * @param tweak
529
530
  * If provided, the numerical value of the string(s) is/are "tweaked" using an {@link EncryptionTransformer |
@@ -553,7 +554,7 @@ export class CharacterSetCreator extends CharacterSetValidator {
553
554
 
554
555
  if (exclusion === Exclusions.AllNumeric && convertValue >= allZerosValue) {
555
556
  // Value to convert is shifted by the number of all-numeric strings that occur at or prior to it.
556
- convertValue = convertValue + this.allNumericShift(true, length, convertValue - allZerosValue);
557
+ convertValue += this.allNumericShift(true, length, convertValue - allZerosValue);
557
558
  }
558
559
 
559
560
  // Build string from right to left excluding the first character.
@@ -581,7 +582,7 @@ export class CharacterSetCreator extends CharacterSetValidator {
581
582
  * String.
582
583
  *
583
584
  * @param exclusion
584
- * Strings excluded from the range of inputs. See {@link Exclusions} for possible values and their meaning.
585
+ * Strings excluded from the range of inputs. See {@linkcode Exclusions} for possible values and their meaning.
585
586
  *
586
587
  * @param tweak
587
588
  * If provided, the numerical value of the string was "tweaked" using an {@link EncryptionTransformer | encryption
@@ -640,19 +641,19 @@ export class CharacterSetCreator extends CharacterSetValidator {
640
641
  }
641
642
 
642
643
  /**
643
- * Numeric creator. Character set is 0-9. Supports {@link Exclusions.FirstZero}.
644
+ * Numeric creator. Character set is 0-9. Supports {@linkcode Exclusions.FirstZero}.
644
645
  */
645
646
  export const NUMERIC_CREATOR = new CharacterSetCreator([
646
647
  "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
647
648
  ], Exclusions.FirstZero);
648
649
 
649
650
  /**
650
- * Numeric validator. Character set is 0-9. Supports {@link Exclusions.FirstZero}.
651
+ * Numeric validator. Character set is 0-9. Supports {@linkcode Exclusions.FirstZero}.
651
652
  */
652
653
  export const NUMERIC_VALIDATOR = NUMERIC_CREATOR as CharacterSetValidator;
653
654
 
654
655
  /**
655
- * Hexadecimal creator. Character set is 0-9, A-F. Supports {@link Exclusions.FirstZero} and {@link
656
+ * Hexadecimal creator. Character set is 0-9, A-F. Supports {@linkcode Exclusions.FirstZero} and {@linkcode
656
657
  * Exclusions.AllNumeric}.
657
658
  */
658
659
  export const HEXADECIMAL_CREATOR = new CharacterSetCreator([
@@ -661,7 +662,7 @@ export const HEXADECIMAL_CREATOR = new CharacterSetCreator([
661
662
  ], Exclusions.FirstZero, Exclusions.AllNumeric);
662
663
 
663
664
  /**
664
- * Hexadecimal validator. Character set is 0-9, A-F. Supports {@link Exclusions.FirstZero} and {@link
665
+ * Hexadecimal validator. Character set is 0-9, A-F. Supports {@linkcode Exclusions.FirstZero} and {@linkcode
665
666
  * Exclusions.AllNumeric}.
666
667
  */
667
668
  export const HEXADECIMAL_VALIDATOR = HEXADECIMAL_CREATOR as CharacterSetValidator;
@@ -680,7 +681,7 @@ export const ALPHABETIC_CREATOR = new CharacterSetCreator([
680
681
  export const ALPHABETIC_VALIDATOR = ALPHABETIC_CREATOR as CharacterSetValidator;
681
682
 
682
683
  /**
683
- * Alphanumeric creator. Character set is 0-9, A-Z. Supports {@link Exclusions.FirstZero} and {@link
684
+ * Alphanumeric creator. Character set is 0-9, A-Z. Supports {@linkcode Exclusions.FirstZero} and {@linkcode
684
685
  * Exclusions.AllNumeric}.
685
686
  */
686
687
  export const ALPHANUMERIC_CREATOR = new CharacterSetCreator([
@@ -690,7 +691,7 @@ export const ALPHANUMERIC_CREATOR = new CharacterSetCreator([
690
691
  ], Exclusions.FirstZero, Exclusions.AllNumeric);
691
692
 
692
693
  /**
693
- * Alphanumeric validator. Character set is 0-9, A-Z. Supports {@link Exclusions.FirstZero} and {@link
694
+ * Alphanumeric validator. Character set is 0-9, A-Z. Supports {@linkcode Exclusions.FirstZero} and {@linkcode
694
695
  * Exclusions.AllNumeric}.
695
696
  */
696
697
  export const ALPHANUMERIC_VALIDATOR = ALPHANUMERIC_CREATOR as CharacterSetValidator;
package/src/exclusion.ts CHANGED
@@ -18,7 +18,12 @@ export const Exclusions = {
18
18
  AllNumeric: 2
19
19
  } as const;
20
20
 
21
+ /**
22
+ * Exclusion key.
23
+ */
24
+ export type ExclusionKey = keyof typeof Exclusions;
25
+
21
26
  /**
22
27
  * Exclusion.
23
28
  */
24
- export type Exclusion = typeof Exclusions[keyof typeof Exclusions];
29
+ export type Exclusion = typeof Exclusions[ExclusionKey];
package/src/index.ts CHANGED
@@ -14,12 +14,12 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- export * from "./locale/i18n.js";
18
- export * from "./sequence.js";
19
- export * from "./iterable-utility.js";
20
- export * from "./transformer.js";
21
- export type * from "./string.js";
22
- export * from "./reg-exp.js";
23
- export * from "./record.js";
24
- export * from "./exclusion.js";
25
- export * from "./character-set.js";
17
+ export * from "./locale/i18n";
18
+ export * from "./sequence";
19
+ export * from "./iterable-utility";
20
+ export * from "./transformer";
21
+ export type * from "./string";
22
+ export * from "./reg-exp";
23
+ export * from "./record";
24
+ export * from "./exclusion";
25
+ export * from "./character-set";
@@ -1,7 +1,7 @@
1
- import { i18nAssertValidResources, i18nCoreInit, type I18nEnvironment } from "@aidc-toolkit/core";
1
+ import { i18nCoreInit, type I18nEnvironment } from "@aidc-toolkit/core";
2
2
  import i18next, { type i18n, type Resource } from "i18next";
3
- import enLocaleResources from "./en/locale-resources.js";
4
- import frLocaleResources from "./fr/locale-resources.js";
3
+ import enLocaleResources from "./en/locale-resources";
4
+ import frLocaleResources from "./fr/locale-resources";
5
5
 
6
6
  export const utilityNS = "aidct_utility";
7
7
 
@@ -10,8 +10,6 @@ export const utilityNS = "aidct_utility";
10
10
  */
11
11
  export type UtilityLocaleResources = typeof enLocaleResources;
12
12
 
13
- i18nAssertValidResources(enLocaleResources, "fr", frLocaleResources);
14
-
15
13
  /**
16
14
  * Utility resources.
17
15
  */
@@ -1,4 +1,4 @@
1
- import type { UtilityLocaleResources } from "./i18n.js";
1
+ import type { UtilityLocaleResources } from "./i18n";
2
2
 
3
3
  /**
4
4
  * Internationalization module.
package/src/record.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { i18nextUtility } from "./locale/i18n.js";
2
- import type { StringValidator } from "./string.js";
1
+ import { i18nextUtility } from "./locale/i18n";
2
+ import type { StringValidator } from "./string";
3
3
 
4
4
  /**
5
5
  * Record validator. Validation is performed against a record with a string key type and throws an error if the key is
package/src/reg-exp.ts CHANGED
@@ -1,14 +1,14 @@
1
- import { i18nextUtility } from "./locale/i18n.js";
2
- import type { StringValidator } from "./string.js";
1
+ import { i18nextUtility } from "./locale/i18n";
2
+ import type { StringValidator } from "./string";
3
3
 
4
4
  /**
5
5
  * Regular expression validator. The regular expression applies to the full string only if constructed as such. For
6
- * example, <code>&#x2F;\d&#x2A;&#x2F;</code> (0 or more digits) matches every string, <code>&#x2F;\d+&#x2F;</code>
7
- * (1 or more digits) matches strings with at least one digit, <code>&#x2F;^\d&#x2A;$&#x2F;</code> matches strings that
8
- * are all digits or empty, and <code>&#x2F;^\d+$&#x2F;</code> matches strings that are all digits and not empty.
6
+ * example, <code>&#x2F;\d&#x2A;&#x2F;</code> (0 or more digits) matches every string, <code>&#x2F;\d+&#x2F;</code> (1
7
+ * or more digits) matches strings with at least one digit, <code>&#x2F;^\d&#x2A;$&#x2F;</code> matches strings that are
8
+ * all digits or empty, and <code>&#x2F;^\d+$&#x2F;</code> matches strings that are all digits and not empty.
9
9
  *
10
- * Clients of this class are recommended to override the {@link createErrorMessage} method create a more suitable error
11
- * message for their use case.
10
+ * Clients of this class are recommended to override the {@linkcode createErrorMessage | createErrorMessage()} method
11
+ * to create a more suitable error message for their use case.
12
12
  */
13
13
  export class RegExpValidator implements StringValidator {
14
14
  /**
package/src/string.ts CHANGED
@@ -8,10 +8,10 @@ export interface StringValidation {
8
8
  /**
9
9
  * String validator interface.
10
10
  *
11
- * @template V
11
+ * @template TStringValidation
12
12
  * String validation type.
13
13
  */
14
- export interface StringValidator<V extends StringValidation = StringValidation> {
14
+ export interface StringValidator<TStringValidation extends StringValidation = StringValidation> {
15
15
  /**
16
16
  * Validate a string and throw an error if validation fails.
17
17
  *
@@ -21,5 +21,5 @@ export interface StringValidator<V extends StringValidation = StringValidation>
21
21
  * @param validation
22
22
  * String validation parameters.
23
23
  */
24
- validate: (s: string, validation?: V) => void;
24
+ validate: (s: string, validation?: TStringValidation) => void;
25
25
  }
@@ -1,6 +1,6 @@
1
- import { type IndexedCallback, mapIterable } from "./iterable-utility.js";
2
- import { i18nextUtility } from "./locale/i18n.js";
3
- import { Sequence } from "./sequence.js";
1
+ import { type IndexedCallback, mapIterable } from "./iterable-utility";
2
+ import { i18nextUtility } from "./locale/i18n";
3
+ import { Sequence } from "./sequence";
4
4
 
5
5
  /**
6
6
  * Transformer primitive type.
@@ -43,11 +43,12 @@ export type TransformerOutput<TTransformerInput extends TransformerInput<Transfo
43
43
  * into values in the same domain, typically for storage in a database where the data type and length are already fixed
44
44
  * and exfiltration of the data can have significant repercussions.
45
45
  *
46
- * Two subclasses are supported directly by this class: {@link IdentityTransformer} (which operates based on a domain
47
- * only) and {@link EncryptionTransformer} (which operates based on a domain and a tweak). If an application is expected
48
- * to make repeated use of a transformer with the same domain and (optional) tweak and can't manage the transformer
49
- * object, an in-memory cache is available via the {@link get} method. Properties in {@link IdentityTransformer} and
50
- * {@link EncryptionTransformer} are read-only once constructed, so there is no issue with their shared use.
46
+ * Two subclasses are supported directly by this class: {@linkcode IdentityTransformer} (which operates based on a
47
+ * domain only) and {@linkcode EncryptionTransformer} (which operates based on a domain and a tweak). If an application
48
+ * is expected to make repeated use of a transformer with the same domain and (optional) tweak and can't manage the
49
+ * transformer object, an in-memory cache is available via the {@linkcode get | get()} method. Properties in {@linkcode
50
+ * IdentityTransformer} and {@linkcode EncryptionTransformer} are read-only once constructed, so there is no issue with
51
+ * their shared use.
51
52
  */
52
53
  export abstract class Transformer {
53
54
  /**
@@ -77,10 +78,10 @@ export abstract class Transformer {
77
78
  }
78
79
 
79
80
  /**
80
- * Get a transformer, constructing it if necessary. The type returned is {@link IdentityTransformer} if tweak is
81
- * undefined, {@link EncryptionTransformer} if tweak is defined. Note that although an {@link EncryptionTransformer}
82
- * with a zero tweak operates as an {@link IdentityTransformer}, {@link EncryptionTransformer} is still the type
83
- * returned if a zero tweak is explicitly specified.
81
+ * Get a transformer, constructing it if necessary. The type returned is {@linkcode IdentityTransformer} if tweak is
82
+ * undefined, {@linkcode EncryptionTransformer} if tweak is defined. Note that although an {@linkcode
83
+ * EncryptionTransformer} with a zero tweak operates as an {@linkcode IdentityTransformer}, {@linkcode
84
+ * EncryptionTransformer} is still the type returned if a zero tweak is explicitly specified.
84
85
  *
85
86
  * @param domain
86
87
  * Domain.
@@ -89,7 +90,7 @@ export abstract class Transformer {
89
90
  * Tweak.
90
91
  *
91
92
  * @returns
92
- * {@link IdentityTransformer} if tweak is undefined, {@link EncryptionTransformer} if tweak is defined.
93
+ * {@linkcode IdentityTransformer} if tweak is undefined, {@linkcode EncryptionTransformer} if tweak is defined.
93
94
  */
94
95
  static get(domain: number | bigint, tweak?: number | bigint): Transformer {
95
96
  const domainN = BigInt(domain);
@@ -195,7 +196,7 @@ export abstract class Transformer {
195
196
  * Value(s) input type.
196
197
  *
197
198
  * @param valueOrValues
198
- * Value(s). If this is an instance of {@link Sequence}, the minimum and maximum values are validated prior to
199
+ * Value(s). If this is an instance of {@linkcode Sequence}, the minimum and maximum values are validated prior to
199
200
  * transformation. Otherwise, the individual value(s) is/are validated at the time of transformation.
200
201
  *
201
202
  * @returns
@@ -213,7 +214,7 @@ export abstract class Transformer {
213
214
  * Transformation callback output type.
214
215
  *
215
216
  * @param valueOrValues
216
- * Value(s). If this is an instance of {@link Sequence}, the minimum and maximum values are validated prior to
217
+ * Value(s). If this is an instance of {@linkcode Sequence}, the minimum and maximum values are validated prior to
217
218
  * transformation. Otherwise, the individual value(s) is/are validated at the time of transformation.
218
219
  *
219
220
  * @param transformerCallback
@@ -305,9 +306,9 @@ export class IdentityTransformer extends Transformer {
305
306
  /**
306
307
  * Encryption transformer. Values are transformed using repeated shuffle and xor operations, similar to those found in
307
308
  * many cryptography algorithms, particularly AES. While sufficient for obfuscation of numeric sequences (e.g., serial
308
- * number generation, below), if true format-preserving encryption is required, a more robust algorithm such as
309
- * {@link https://doi.org/10.6028/NIST.SP.800-38Gr1-draft | FF1} is recommended. Furthermore, no work has been done to
310
- * mitigate {@link https://timing.attacks.cr.yp.to/index.html | timing attacks} for key detection.
309
+ * number generation, below), if true format-preserving encryption is required, a more robust algorithm such as {@link
310
+ * https://doi.org/10.6028/NIST.SP.800-38Gr1.2pd | FF1} is recommended. Furthermore, no work has been done to mitigate
311
+ * {@link https://timing.attacks.cr.yp.to/index.html | timing attacks} for key detection.
311
312
  *
312
313
  * The purpose of the encryption transformer is to generate pseudo-random values in a deterministic manner to obscure
313
314
  * the sequence of values generated over time. A typical example is for serial number generation, where knowledge of the
@@ -9,7 +9,9 @@ describe("Record validator", () => {
9
9
  ValueD: "D"
10
10
  } as const;
11
11
 
12
- type StringIndex = typeof StringIndexes[keyof typeof StringIndexes];
12
+ type StringIndexKey = keyof typeof StringIndexes;
13
+
14
+ type StringIndex = typeof StringIndexes[StringIndexKey];
13
15
 
14
16
  const stringRecord: Record<StringIndex, string> = {
15
17
  [StringIndexes.ValueA]: "This is for Value A",
package/tsup.config.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { tsupConfigAIDCToolkit } from "@aidc-toolkit/dev";
2
+
3
+ export default tsupConfigAIDCToolkit;
package/typedoc.json CHANGED
@@ -3,7 +3,5 @@
3
3
  "extends": [
4
4
  "@aidc-toolkit/dev/typedoc.json"
5
5
  ],
6
- "name": "Utility",
7
- "tsconfig": "node_modules/@aidc-toolkit/dev/tsconfig-build-dev.json",
8
- "gitRevision": "main"
6
+ "name": "Utility"
9
7
  }
@@ -1,307 +0,0 @@
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 {@link 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 {@link 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 {@link 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 {@link 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 {@link Exclusions} for possible values and their meaning.
241
- *
242
- * @param tweak
243
- * If provided, the numerical value of the string(s) is/are "tweaked" using an {@link EncryptionTransformer |
244
- * encryption transformer}.
245
- *
246
- * @param creatorCallback
247
- * If provided, called after each string is constructed to create the final value.
248
- *
249
- * @returns
250
- * String(s) created from the value(s).
251
- */
252
- create<TTransformerInput extends TransformerInput<number | bigint>>(length: number, valueOrValues: TTransformerInput, exclusion?: Exclusion, tweak?: number | bigint, creatorCallback?: IndexedCallback<string, string>): TransformerOutput<TTransformerInput, string>;
253
- /**
254
- * Determine the value for a string.
255
- *
256
- * @param s
257
- * String.
258
- *
259
- * @param exclusion
260
- * Strings excluded from the range of inputs. See {@link Exclusions} for possible values and their meaning.
261
- *
262
- * @param tweak
263
- * If provided, the numerical value of the string was "tweaked" using an {@link EncryptionTransformer | encryption
264
- * transformer}.
265
- *
266
- * @returns
267
- * Numeric value of the string.
268
- */
269
- valueFor(s: string, exclusion?: Exclusion, tweak?: number | bigint): bigint;
270
- }
271
- /**
272
- * Numeric creator. Character set is 0-9. Supports {@link Exclusions.FirstZero}.
273
- */
274
- export declare const NUMERIC_CREATOR: CharacterSetCreator;
275
- /**
276
- * Numeric validator. Character set is 0-9. Supports {@link Exclusions.FirstZero}.
277
- */
278
- export declare const NUMERIC_VALIDATOR: CharacterSetValidator;
279
- /**
280
- * Hexadecimal creator. Character set is 0-9, A-F. Supports {@link Exclusions.FirstZero} and {@link
281
- * Exclusions.AllNumeric}.
282
- */
283
- export declare const HEXADECIMAL_CREATOR: CharacterSetCreator;
284
- /**
285
- * Hexadecimal validator. Character set is 0-9, A-F. Supports {@link Exclusions.FirstZero} and {@link
286
- * Exclusions.AllNumeric}.
287
- */
288
- export declare const HEXADECIMAL_VALIDATOR: CharacterSetValidator;
289
- /**
290
- * Alphabetic creator. Character set is A-Z.
291
- */
292
- export declare const ALPHABETIC_CREATOR: CharacterSetCreator;
293
- /**
294
- * Alphabetic validator. Character set is A-Z.
295
- */
296
- export declare const ALPHABETIC_VALIDATOR: CharacterSetValidator;
297
- /**
298
- * Alphanumeric creator. Character set is 0-9, A-Z. Supports {@link Exclusions.FirstZero} and {@link
299
- * Exclusions.AllNumeric}.
300
- */
301
- export declare const ALPHANUMERIC_CREATOR: CharacterSetCreator;
302
- /**
303
- * Alphanumeric validator. Character set is 0-9, A-Z. Supports {@link Exclusions.FirstZero} and {@link
304
- * Exclusions.AllNumeric}.
305
- */
306
- export declare const ALPHANUMERIC_VALIDATOR: CharacterSetValidator;
307
- //# sourceMappingURL=character-set.d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