@aidc-toolkit/utility 1.0.25-beta → 1.0.27-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 (71) hide show
  1. package/dist/character-set.d.ts +222 -0
  2. package/dist/character-set.d.ts.map +1 -0
  3. package/dist/character-set.js +568 -0
  4. package/dist/character-set.js.map +1 -0
  5. package/dist/exclusion.d.ts +26 -0
  6. package/dist/exclusion.d.ts.map +1 -0
  7. package/dist/exclusion.js +18 -0
  8. package/dist/exclusion.js.map +1 -0
  9. package/dist/index.d.ts +26 -953
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +8 -3505
  12. package/dist/index.js.map +1 -1
  13. package/dist/iterable-utility.d.ts +39 -0
  14. package/dist/iterable-utility.d.ts.map +1 -0
  15. package/dist/iterable-utility.js +35 -0
  16. package/dist/iterable-utility.js.map +1 -0
  17. package/dist/locale/en/locale-resources.d.ts +33 -0
  18. package/dist/locale/en/locale-resources.d.ts.map +1 -0
  19. package/dist/locale/en/locale-resources.js +32 -0
  20. package/dist/locale/en/locale-resources.js.map +1 -0
  21. package/dist/locale/fr/locale-resources.d.ts +33 -0
  22. package/dist/locale/fr/locale-resources.d.ts.map +1 -0
  23. package/dist/locale/fr/locale-resources.js +32 -0
  24. package/dist/locale/fr/locale-resources.js.map +1 -0
  25. package/dist/locale/i18n.d.ts +27 -0
  26. package/dist/locale/i18n.d.ts.map +1 -0
  27. package/dist/locale/i18n.js +34 -0
  28. package/dist/locale/i18n.js.map +1 -0
  29. package/dist/record.d.ts +37 -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 +40 -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 +45 -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 +196 -0
  46. package/dist/transformer.d.ts.map +1 -0
  47. package/dist/transformer.js +457 -0
  48. package/dist/transformer.js.map +1 -0
  49. package/package.json +10 -6
  50. package/src/character-set.ts +62 -59
  51. package/src/index.ts +9 -9
  52. package/src/locale/i18n.ts +3 -3
  53. package/src/locale/i18next.d.ts +1 -1
  54. package/src/record.ts +8 -8
  55. package/src/reg-exp.ts +6 -6
  56. package/src/sequence.ts +21 -21
  57. package/src/transformer.ts +54 -54
  58. package/test/character-set.test.ts +1 -1
  59. package/test/record.test.ts +1 -1
  60. package/test/reg-exp.test.ts +1 -1
  61. package/test/sequence.test.ts +1 -1
  62. package/test/setup.ts +1 -1
  63. package/test/transformer.test.ts +1 -6
  64. package/tsconfig-config.json +4 -0
  65. package/tsconfig-src.json +8 -0
  66. package/tsconfig-test.json +9 -0
  67. package/tsconfig.json +12 -1
  68. package/tsup.config.ts +3 -2
  69. package/dist/index.cjs +0 -3570
  70. package/dist/index.cjs.map +0 -1
  71. package/dist/index.d.cts +0 -953
@@ -0,0 +1,222 @@
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;
38
+ /**
39
+ * Constructor.
40
+ *
41
+ * @param characterSet
42
+ * Character set. Each element is a single-character string, unique within the array, that defines the character
43
+ * set.
44
+ *
45
+ * @param exclusionSupport
46
+ * Exclusions supported by the character set. All character sets implicitly support {@linkcode Exclusions.None}.
47
+ */
48
+ constructor(characterSet: readonly string[], ...exclusionSupport: readonly Exclusion[]);
49
+ /**
50
+ * Get the character set.
51
+ */
52
+ get characterSet(): readonly string[];
53
+ /**
54
+ * Get the character set size.
55
+ */
56
+ get characterSetSize(): number;
57
+ /**
58
+ * Get the exclusions supported by the character set.
59
+ */
60
+ get exclusionSupport(): readonly Exclusion[];
61
+ /**
62
+ * Get the character at an index.
63
+ *
64
+ * @param index
65
+ * Index into the character set.
66
+ *
67
+ * @returns
68
+ * Character at the index.
69
+ */
70
+ character(index: number): string;
71
+ /**
72
+ * Get the index for a character.
73
+ *
74
+ * @param c
75
+ * Character.
76
+ *
77
+ * @returns
78
+ * Index for the character or undefined if the character is not in the character set.
79
+ */
80
+ characterIndex(c: string): number | undefined;
81
+ /**
82
+ * Get the indexes for all characters in a string.
83
+ *
84
+ * @param s
85
+ * String.
86
+ *
87
+ * @returns
88
+ * Array of indexes for each character or undefined if the character is not in the character set.
89
+ */
90
+ characterIndexes(s: string): ReadonlyArray<number | undefined>;
91
+ /**
92
+ * Validate that an exclusion is supported. If not, an error is thrown.
93
+ *
94
+ * @param exclusion
95
+ * Exclusion.
96
+ */
97
+ protected validateExclusion(exclusion: Exclusion): void;
98
+ /**
99
+ * Validate a string. If the string violates the character set or any of the character set validation parameters, an
100
+ * error is thrown.
101
+ *
102
+ * @param s
103
+ * String.
104
+ *
105
+ * @param validation
106
+ * Character set validation parameters.
107
+ */
108
+ validate(s: string, validation?: CharacterSetValidation): void;
109
+ }
110
+ /**
111
+ * Character set creator. Maps numeric values to strings using the character set as digits.
112
+ */
113
+ export declare class CharacterSetCreator extends CharacterSetValidator {
114
+ #private;
115
+ /**
116
+ * Maximum string length supported.
117
+ */
118
+ static readonly MAXIMUM_STRING_LENGTH = 40;
119
+ /**
120
+ * Get a power of 10.
121
+ *
122
+ * @param power
123
+ * Power.
124
+ *
125
+ * @returns
126
+ * `10**power`.
127
+ */
128
+ static powerOf10(power: number): bigint;
129
+ /**
130
+ * Constructor.
131
+ *
132
+ * @param characterSet
133
+ * Character set. Each element is a single-character string, unique within the array, that defines the character
134
+ * set.
135
+ *
136
+ * @param exclusionSupport
137
+ * Exclusions supported by the character set. All character sets implicitly support {@linkcode Exclusions.None}.
138
+ */
139
+ constructor(characterSet: readonly string[], ...exclusionSupport: readonly Exclusion[]);
140
+ /**
141
+ * Create string(s) by mapping value(s) to the equivalent characters in the character set across the length of the
142
+ * string.
143
+ *
144
+ * @template TTransformerInput
145
+ * Transformer input type.
146
+ *
147
+ * @param length
148
+ * Required string length.
149
+ *
150
+ * @param valueOrValues
151
+ * Numeric value(s) of the string(s).
152
+ *
153
+ * @param exclusion
154
+ * String(s) to be excluded from the range of outputs. See {@linkcode Exclusions} for possible values and their
155
+ * meaning.
156
+ *
157
+ * @param tweak
158
+ * If provided, the numerical value of the string(s) is/are "tweaked" using an {@link EncryptionTransformer |
159
+ * encryption transformer}.
160
+ *
161
+ * @param creatorCallback
162
+ * If provided, called after each string is constructed to create the final value.
163
+ *
164
+ * @returns
165
+ * String(s) created from the value(s).
166
+ */
167
+ create<TTransformerInput extends TransformerInput<number | bigint>>(length: number, valueOrValues: TTransformerInput, exclusion?: Exclusion, tweak?: number | bigint, creatorCallback?: IndexedCallback<string, string>): TransformerOutput<TTransformerInput, string>;
168
+ /**
169
+ * Determine the value for a string.
170
+ *
171
+ * @param s
172
+ * String.
173
+ *
174
+ * @param exclusion
175
+ * Strings excluded from the range of inputs. See {@linkcode Exclusions} for possible values and their meaning.
176
+ *
177
+ * @param tweak
178
+ * If provided, the numerical value of the string was "tweaked" using an {@link EncryptionTransformer | encryption
179
+ * transformer}.
180
+ *
181
+ * @returns
182
+ * Numeric value of the string.
183
+ */
184
+ valueFor(s: string, exclusion?: Exclusion, tweak?: number | bigint): bigint;
185
+ }
186
+ /**
187
+ * Numeric creator. Character set is 0-9. Supports {@linkcode Exclusions.FirstZero}.
188
+ */
189
+ export declare const NUMERIC_CREATOR: CharacterSetCreator;
190
+ /**
191
+ * Numeric validator. Character set is 0-9. Supports {@linkcode Exclusions.FirstZero}.
192
+ */
193
+ export declare const NUMERIC_VALIDATOR: CharacterSetValidator;
194
+ /**
195
+ * Hexadecimal creator. Character set is 0-9, A-F. Supports {@linkcode Exclusions.FirstZero} and {@linkcode
196
+ * Exclusions.AllNumeric}.
197
+ */
198
+ export declare const HEXADECIMAL_CREATOR: CharacterSetCreator;
199
+ /**
200
+ * Hexadecimal validator. Character set is 0-9, A-F. Supports {@linkcode Exclusions.FirstZero} and {@linkcode
201
+ * Exclusions.AllNumeric}.
202
+ */
203
+ export declare const HEXADECIMAL_VALIDATOR: CharacterSetValidator;
204
+ /**
205
+ * Alphabetic creator. Character set is A-Z.
206
+ */
207
+ export declare const ALPHABETIC_CREATOR: CharacterSetCreator;
208
+ /**
209
+ * Alphabetic validator. Character set is A-Z.
210
+ */
211
+ export declare const ALPHABETIC_VALIDATOR: CharacterSetValidator;
212
+ /**
213
+ * Alphanumeric creator. Character set is 0-9, A-Z. Supports {@linkcode Exclusions.FirstZero} and {@linkcode
214
+ * Exclusions.AllNumeric}.
215
+ */
216
+ export declare const ALPHANUMERIC_CREATOR: CharacterSetCreator;
217
+ /**
218
+ * Alphanumeric validator. Character set is 0-9, A-Z. Supports {@linkcode Exclusions.FirstZero} and {@linkcode
219
+ * Exclusions.AllNumeric}.
220
+ */
221
+ export declare const ALPHANUMERIC_VALIDATOR: CharacterSetValidator;
222
+ //# sourceMappingURL=character-set.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"character-set.d.ts","sourceRoot":"","sources":["../src/character-set.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAc,MAAM,gBAAgB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAG7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAe,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE9F;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,gBAAgB;IAC5D;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAEnC;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAEnC;;OAEG;IACH,SAAS,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAElC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAEpC;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,SAAS,CAAC;CACnD;AAED;;GAEG;AACH,qBAAa,qBAAsB,YAAW,eAAe,CAAC,sBAAsB,CAAC;;IAgCjF;;;;;;;;;OASG;gBACS,YAAY,EAAE,SAAS,MAAM,EAAE,EAAE,GAAG,gBAAgB,EAAE,SAAS,SAAS,EAAE;IActF;;OAEG;IACH,IAAI,YAAY,IAAI,SAAS,MAAM,EAAE,CAEpC;IAED;;OAEG;IACH,IAAI,gBAAgB,IAAI,MAAM,CAE7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