@aidc-toolkit/utility 1.0.46 → 1.0.47-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.
- package/dist/character-set.d.ts +242 -0
- package/dist/character-set.d.ts.map +1 -0
- package/dist/character-set.js +542 -0
- package/dist/character-set.js.map +1 -0
- package/dist/exclusion.d.ts +26 -0
- package/dist/exclusion.d.ts.map +1 -0
- package/dist/exclusion.js +18 -0
- package/dist/exclusion.js.map +1 -0
- package/dist/index.d.ts +26 -699
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -0
- package/dist/iterable-utility.d.ts +39 -0
- package/dist/iterable-utility.d.ts.map +1 -0
- package/dist/iterable-utility.js +35 -0
- package/dist/iterable-utility.js.map +1 -0
- package/dist/locale/en/locale-resources.d.ts +33 -0
- package/dist/locale/en/locale-resources.d.ts.map +1 -0
- package/dist/locale/en/locale-resources.js +32 -0
- package/dist/locale/en/locale-resources.js.map +1 -0
- package/dist/locale/fr/locale-resources.d.ts +33 -0
- package/dist/locale/fr/locale-resources.d.ts.map +1 -0
- package/dist/locale/fr/locale-resources.js +32 -0
- package/dist/locale/fr/locale-resources.js.map +1 -0
- package/dist/locale/i18n.d.ts +27 -0
- package/dist/locale/i18n.d.ts.map +1 -0
- package/dist/locale/i18n.js +34 -0
- package/dist/locale/i18n.js.map +1 -0
- package/dist/record.d.ts +37 -0
- package/dist/record.d.ts.map +1 -0
- package/dist/record.js +58 -0
- package/dist/record.js.map +1 -0
- package/dist/reg-exp.d.ts +40 -0
- package/dist/reg-exp.d.ts.map +1 -0
- package/dist/reg-exp.js +55 -0
- package/dist/reg-exp.js.map +1 -0
- package/dist/sequence.d.ts +45 -0
- package/dist/sequence.d.ts.map +1 -0
- package/dist/sequence.js +96 -0
- package/dist/sequence.js.map +1 -0
- package/dist/string.d.ts +25 -0
- package/dist/string.d.ts.map +1 -0
- package/dist/string.js +2 -0
- package/dist/string.js.map +1 -0
- package/dist/transformer.d.ts +191 -0
- package/dist/transformer.d.ts.map +1 -0
- package/dist/transformer.js +459 -0
- package/dist/transformer.js.map +1 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/package.json +3 -3
- package/src/version.ts +1 -1
- package/tsconfig-src.tsbuildinfo +1 -1
- package/dist/index.cjs +0 -17
- package/dist/index.d.cts +0 -699
package/dist/index.d.ts
CHANGED
|
@@ -1,699 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
invalidCharacterAtPositionOfComponent: string;
|
|
28
|
-
exclusionNotSupported: string;
|
|
29
|
-
endSequenceValueMustBeLessThanOrEqualTo: string;
|
|
30
|
-
};
|
|
31
|
-
RecordValidator: {
|
|
32
|
-
typeNameKeyNotFound: string;
|
|
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 resource bundle.
|
|
43
|
-
*/
|
|
44
|
-
declare const utilityResourceBundle: Resource;
|
|
45
|
-
declare const i18nextUtility: i18n;
|
|
46
|
-
/**
|
|
47
|
-
* Initialize internationalization.
|
|
48
|
-
*
|
|
49
|
-
* @param languageDetector
|
|
50
|
-
* Language detector.
|
|
51
|
-
*
|
|
52
|
-
* @param debug
|
|
53
|
-
* Debug setting.
|
|
54
|
-
*
|
|
55
|
-
* @returns
|
|
56
|
-
* Utility resource bundle.
|
|
57
|
-
*/
|
|
58
|
-
declare function i18nUtilityInit(languageDetector: I18nLanguageDetector, debug?: boolean): Promise<Resource>;
|
|
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
|
-
#private;
|
|
65
|
-
/**
|
|
66
|
-
* Constructor.
|
|
67
|
-
*
|
|
68
|
-
* @param startValue
|
|
69
|
-
* Start value.
|
|
70
|
-
*
|
|
71
|
-
* @param count
|
|
72
|
-
* Count of values. If count is zero or positive, iteration ascends from start value, otherwise it descends from
|
|
73
|
-
* start value.
|
|
74
|
-
*/
|
|
75
|
-
constructor(startValue: number | bigint, count: number);
|
|
76
|
-
/**
|
|
77
|
-
* Get the start value (inclusive).
|
|
78
|
-
*/
|
|
79
|
-
get startValue(): bigint;
|
|
80
|
-
/**
|
|
81
|
-
* Get the end value (exclusive).
|
|
82
|
-
*/
|
|
83
|
-
get endValue(): bigint;
|
|
84
|
-
/**
|
|
85
|
-
* Get the count of values.
|
|
86
|
-
*/
|
|
87
|
-
get count(): number;
|
|
88
|
-
/**
|
|
89
|
-
* Get the minimum value (inclusive).
|
|
90
|
-
*/
|
|
91
|
-
get minimumValue(): bigint;
|
|
92
|
-
/**
|
|
93
|
-
* Get the maximum value (inclusive).
|
|
94
|
-
*/
|
|
95
|
-
get maximumValue(): bigint;
|
|
96
|
-
/**
|
|
97
|
-
* Iterable implementation.
|
|
98
|
-
*
|
|
99
|
-
* @yields
|
|
100
|
-
* Next value in sequence.
|
|
101
|
-
*/
|
|
102
|
-
[Symbol.iterator](): Generator<bigint>;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Indexed callback, used to map an input and optionally its index in an iterable to an output.
|
|
107
|
-
*
|
|
108
|
-
* @template TInput
|
|
109
|
-
* Input type.
|
|
110
|
-
*
|
|
111
|
-
* @template TOutput
|
|
112
|
-
* Output type.
|
|
113
|
-
*
|
|
114
|
-
* @param input
|
|
115
|
-
* Input value.
|
|
116
|
-
*
|
|
117
|
-
* @param index
|
|
118
|
-
* Index in iterable or undefined for single mapping).
|
|
119
|
-
*
|
|
120
|
-
* @returns
|
|
121
|
-
* Output value.
|
|
122
|
-
*/
|
|
123
|
-
type IndexedCallback<TInput, TOutput> = (input: TInput, index?: number) => TOutput;
|
|
124
|
-
/**
|
|
125
|
-
* Map an input iterable to an output iterable that applies a transformer callback to each value in the input.
|
|
126
|
-
*
|
|
127
|
-
* @template TInput
|
|
128
|
-
* Input type.
|
|
129
|
-
*
|
|
130
|
-
* @template TOutput
|
|
131
|
-
* Output type.
|
|
132
|
-
*
|
|
133
|
-
* @param values
|
|
134
|
-
* Input values iterable.
|
|
135
|
-
*
|
|
136
|
-
* @param indexedCallback
|
|
137
|
-
* Callback to transform input value to output value.
|
|
138
|
-
*
|
|
139
|
-
* @returns
|
|
140
|
-
* Output values iterable.
|
|
141
|
-
*/
|
|
142
|
-
declare function mapIterable<TInput, TOutput>(values: Iterable<TInput>, indexedCallback: IndexedCallback<TInput, TOutput>): Iterable<TOutput>;
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Transformer that transforms values in a numeric domain to values in a range equal to the domain or to another range
|
|
146
|
-
* defined by a callback function. In other words, the domain determines valid input values and, without a callback, the
|
|
147
|
-
* range of valid output values.
|
|
148
|
-
*
|
|
149
|
-
* The concept is similar to {@link https://en.wikipedia.org/wiki/Format-preserving_encryption | format-preserving
|
|
150
|
-
* encryption}, where input values within a specified domain (e.g., {@link
|
|
151
|
-
* https://en.wikipedia.org/wiki/Payment_card_number | payment card numbers} ranging from 8-19 digits) are transformed
|
|
152
|
-
* into values in the same domain, typically for storage in a database where the data type and length are already fixed
|
|
153
|
-
* and exfiltration of the data can have significant repercussions.
|
|
154
|
-
*
|
|
155
|
-
* Two subclasses are supported directly by this class: {@linkcode IdentityTransformer} (which operates based on a
|
|
156
|
-
* domain only) and {@linkcode EncryptionTransformer} (which operates based on a domain and a tweak). If an application
|
|
157
|
-
* is expected to make repeated use of a transformer with the same domain and (optional) tweak and can't manage the
|
|
158
|
-
* transformer object, an in-memory cache is available via the {@linkcode get | get()} method. Properties in {@linkcode
|
|
159
|
-
* IdentityTransformer} and {@linkcode EncryptionTransformer} are read-only once constructed, so there is no issue with
|
|
160
|
-
* their shared use.
|
|
161
|
-
*/
|
|
162
|
-
declare abstract class Transformer {
|
|
163
|
-
#private;
|
|
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 {@linkcode IdentityTransformer} if tweak is
|
|
173
|
-
* undefined, {@linkcode EncryptionTransformer} if tweak is defined. Note that although an {@linkcode
|
|
174
|
-
* EncryptionTransformer} with a zero tweak operates as an {@linkcode IdentityTransformer}, {@linkcode
|
|
175
|
-
* EncryptionTransformer} is still the type returned if a zero tweak is explicitly specified.
|
|
176
|
-
*
|
|
177
|
-
* @param domain
|
|
178
|
-
* Domain.
|
|
179
|
-
*
|
|
180
|
-
* @param tweak
|
|
181
|
-
* Tweak.
|
|
182
|
-
*
|
|
183
|
-
* @returns
|
|
184
|
-
* Transformer.
|
|
185
|
-
*/
|
|
186
|
-
static get(domain: number | bigint, tweak?: number | bigint): Transformer;
|
|
187
|
-
/**
|
|
188
|
-
* Get the domain.
|
|
189
|
-
*/
|
|
190
|
-
get domain(): bigint;
|
|
191
|
-
/**
|
|
192
|
-
* Do the work of transforming a value forward.
|
|
193
|
-
*
|
|
194
|
-
* @param value
|
|
195
|
-
* Value.
|
|
196
|
-
*
|
|
197
|
-
* @returns
|
|
198
|
-
* Transformed value.
|
|
199
|
-
*/
|
|
200
|
-
protected abstract doForward(value: bigint): bigint;
|
|
201
|
-
/**
|
|
202
|
-
* Transform a value forward.
|
|
203
|
-
*
|
|
204
|
-
* @param value
|
|
205
|
-
* Value.
|
|
206
|
-
*
|
|
207
|
-
* @returns
|
|
208
|
-
* Transformed value.
|
|
209
|
-
*/
|
|
210
|
-
forward(value: number | bigint): bigint;
|
|
211
|
-
/**
|
|
212
|
-
* Transform a value forward and apply another transformation.
|
|
213
|
-
*
|
|
214
|
-
* @template TOutput
|
|
215
|
-
* Transformer callback output type.
|
|
216
|
-
*
|
|
217
|
-
* @param value
|
|
218
|
-
* Value.
|
|
219
|
-
*
|
|
220
|
-
* @param transformerCallback
|
|
221
|
-
* Called with interim transformed value to transform it to its final value.
|
|
222
|
-
*
|
|
223
|
-
* @returns
|
|
224
|
-
* Transformed value.
|
|
225
|
-
*/
|
|
226
|
-
forward<TOutput>(value: number | bigint, transformerCallback: IndexedCallback<bigint, TOutput>): TOutput;
|
|
227
|
-
/**
|
|
228
|
-
* Transform values forward.
|
|
229
|
-
*
|
|
230
|
-
* @param values
|
|
231
|
-
* Values. If this is an instance of {@linkcode Sequence}, the minimum and maximum values are validated prior to
|
|
232
|
-
* transformation. Otherwise, the individual values are validated at the time of each transformation.
|
|
233
|
-
*
|
|
234
|
-
* @returns
|
|
235
|
-
* Transformed values.
|
|
236
|
-
*/
|
|
237
|
-
forward(values: Iterable<number | bigint>): Iterable<bigint>;
|
|
238
|
-
/**
|
|
239
|
-
* Transform values forward and apply another transformation to each.
|
|
240
|
-
*
|
|
241
|
-
* @template TOutput
|
|
242
|
-
* Transformer callback output type.
|
|
243
|
-
*
|
|
244
|
-
* @param values
|
|
245
|
-
* Values. If this is an instance of {@linkcode Sequence}, the minimum and maximum values are validated prior to
|
|
246
|
-
* transformation. Otherwise, the individual values are validated at the time of each transformation.
|
|
247
|
-
*
|
|
248
|
-
* @param transformerCallback
|
|
249
|
-
* Called with each interim transformed value to transform it to its final value.
|
|
250
|
-
*
|
|
251
|
-
* @returns
|
|
252
|
-
* Transformed values.
|
|
253
|
-
*/
|
|
254
|
-
forward<TOutput>(values: Iterable<number | bigint>, transformerCallback: IndexedCallback<bigint, TOutput>): Iterable<TOutput>;
|
|
255
|
-
forward<TInput extends number | bigint | Iterable<number | bigint>>(valueOrValues: TInput extends Iterable<number | bigint> ? TInput : number | bigint): TInput extends Iterable<number | bigint> ? Iterable<bigint> : bigint;
|
|
256
|
-
forward<TInput extends number | bigint | Iterable<number | bigint>, TOutput>(valueOrValues: TInput extends Iterable<number | bigint> ? TInput : number | bigint, transformerCallback: IndexedCallback<bigint, TOutput>): TInput extends Iterable<number | bigint> ? Iterable<TOutput> : TOutput;
|
|
257
|
-
/**
|
|
258
|
-
* Do the work of transforming a value in reverse.
|
|
259
|
-
*
|
|
260
|
-
* @param transformedValue
|
|
261
|
-
* Transformed value.
|
|
262
|
-
*
|
|
263
|
-
* @returns
|
|
264
|
-
* Value.
|
|
265
|
-
*/
|
|
266
|
-
protected abstract doReverse(transformedValue: bigint): bigint;
|
|
267
|
-
/**
|
|
268
|
-
* Transform a value in reverse.
|
|
269
|
-
*
|
|
270
|
-
* @param transformedValue
|
|
271
|
-
* Transformed value.
|
|
272
|
-
*
|
|
273
|
-
* @returns
|
|
274
|
-
* Value.
|
|
275
|
-
*/
|
|
276
|
-
reverse(transformedValue: number | bigint): bigint;
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Identity transformer. Values are transformed to themselves.
|
|
280
|
-
*/
|
|
281
|
-
declare class IdentityTransformer extends Transformer {
|
|
282
|
-
/**
|
|
283
|
-
* @inheritDoc
|
|
284
|
-
*/
|
|
285
|
-
protected doForward(value: bigint): bigint;
|
|
286
|
-
/**
|
|
287
|
-
* @inheritDoc
|
|
288
|
-
*/
|
|
289
|
-
protected doReverse(transformedValue: bigint): bigint;
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Encryption transformer. Values are transformed using repeated shuffle and xor operations, similar to those found in
|
|
293
|
-
* many cryptography algorithms, particularly AES. While sufficient for obfuscation of numeric sequences (e.g., serial
|
|
294
|
-
* number generation, below), if true format-preserving encryption is required, a more robust algorithm such as {@link
|
|
295
|
-
* https://doi.org/10.6028/NIST.SP.800-38Gr1.2pd | FF1} is recommended. Furthermore, no work has been done to mitigate
|
|
296
|
-
* {@link https://timing.attacks.cr.yp.to/index.html | timing attacks} for key detection.
|
|
297
|
-
*
|
|
298
|
-
* The purpose of the encryption transformer is to generate pseudo-random values in a deterministic manner to obscure
|
|
299
|
-
* the sequence of values generated over time. A typical example is for serial number generation, where knowledge of the
|
|
300
|
-
* sequence can infer production volumes (e.g., serial number 1000 implies that at least 1,000 units have been
|
|
301
|
-
* manufactured) or can be used in counterfeiting (e.g., a counterfeiter can generate serial numbers 1001, 1002, ...
|
|
302
|
-
* with reasonable confidence that they would be valid if queried).
|
|
303
|
-
*
|
|
304
|
-
* The domain and the tweak together determine the encryption key, which in turn determines the number of rounds of
|
|
305
|
-
* shuffle and xor operations. The minimum number of rounds is 4, except where the domain is less than or equal to 256,
|
|
306
|
-
* which results in single-byte operations. To ensure that the operations are effective for single-byte domains, the
|
|
307
|
-
* number of rounds is 1 and only the xor operation is applied (shuffling a single byte is an identity operation).
|
|
308
|
-
*
|
|
309
|
-
* Another exception is when there is a tweak value of 0; this results in identity operations where the output value is
|
|
310
|
-
* identical to the input value, as no shuffle or xor takes place.
|
|
311
|
-
*/
|
|
312
|
-
declare class EncryptionTransformer extends Transformer {
|
|
313
|
-
#private;
|
|
314
|
-
/**
|
|
315
|
-
* Constructor.
|
|
316
|
-
*
|
|
317
|
-
* @param domain
|
|
318
|
-
* Domain.
|
|
319
|
-
*
|
|
320
|
-
* @param tweak
|
|
321
|
-
* Tweak.
|
|
322
|
-
*/
|
|
323
|
-
constructor(domain: number | bigint, tweak: number | bigint);
|
|
324
|
-
/**
|
|
325
|
-
* @inheritDoc
|
|
326
|
-
*/
|
|
327
|
-
protected doForward(value: bigint): bigint;
|
|
328
|
-
/**
|
|
329
|
-
* @inheritDoc
|
|
330
|
-
*/
|
|
331
|
-
protected doReverse(transformedValue: bigint): bigint;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* String validation interface. To ensure signature compatibility in implementing classes, string validation is
|
|
336
|
-
* controlled by validation interfaces specific to each validator type.
|
|
337
|
-
*/
|
|
338
|
-
interface StringValidation {
|
|
339
|
-
}
|
|
340
|
-
/**
|
|
341
|
-
* String validator interface.
|
|
342
|
-
*
|
|
343
|
-
* @template TStringValidation
|
|
344
|
-
* String validation type.
|
|
345
|
-
*/
|
|
346
|
-
interface StringValidator<TStringValidation extends StringValidation = StringValidation> {
|
|
347
|
-
/**
|
|
348
|
-
* Validate a string and throw an error if validation fails.
|
|
349
|
-
*
|
|
350
|
-
* @param s
|
|
351
|
-
* String.
|
|
352
|
-
*
|
|
353
|
-
* @param validation
|
|
354
|
-
* String validation parameters.
|
|
355
|
-
*/
|
|
356
|
-
validate: (s: string, validation?: TStringValidation) => void;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* Regular expression validator. The regular expression applies to the full string only if constructed as such. For
|
|
361
|
-
* example, <code>/\d*/</code> (0 or more digits) matches every string, <code>/\d+/</code> (1
|
|
362
|
-
* or more digits) matches strings with at least one digit, <code>/^\d*$/</code> matches strings that are
|
|
363
|
-
* all digits or empty, and <code>/^\d+$/</code> matches strings that are all digits and not empty.
|
|
364
|
-
*
|
|
365
|
-
* Clients of this class are recommended to override the {@linkcode createErrorMessage | createErrorMessage()} method
|
|
366
|
-
* to create a more suitable error message for their use case.
|
|
367
|
-
*/
|
|
368
|
-
declare class RegExpValidator implements StringValidator {
|
|
369
|
-
#private;
|
|
370
|
-
/**
|
|
371
|
-
* Constructor.
|
|
372
|
-
*
|
|
373
|
-
* @param regExp
|
|
374
|
-
* Regular expression. See {@link RegExpValidator | class documentation} for notes.
|
|
375
|
-
*/
|
|
376
|
-
constructor(regExp: RegExp);
|
|
377
|
-
/**
|
|
378
|
-
* Get the regular expression.
|
|
379
|
-
*/
|
|
380
|
-
get regExp(): RegExp;
|
|
381
|
-
/**
|
|
382
|
-
* Create an error message for a string. The generic error message is sufficient for many use cases but a more
|
|
383
|
-
* domain-specific error message, possibly including the pattern itself, is often required.
|
|
384
|
-
*
|
|
385
|
-
* @param s
|
|
386
|
-
* String.
|
|
387
|
-
*
|
|
388
|
-
* @returns
|
|
389
|
-
* Error message.
|
|
390
|
-
*/
|
|
391
|
-
protected createErrorMessage(s: string): string;
|
|
392
|
-
/**
|
|
393
|
-
* @inheritDoc
|
|
394
|
-
*/
|
|
395
|
-
validate(s: string): void;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* Record validator. Validation is performed against a record with a string key type and throws an error if the key is
|
|
400
|
-
* not found.
|
|
401
|
-
*
|
|
402
|
-
* @template T
|
|
403
|
-
* Property type.
|
|
404
|
-
*/
|
|
405
|
-
declare class RecordValidator<T> implements StringValidator {
|
|
406
|
-
#private;
|
|
407
|
-
/**
|
|
408
|
-
* Constructor.
|
|
409
|
-
*
|
|
410
|
-
* @param typeName
|
|
411
|
-
* Type name for error message.
|
|
412
|
-
*
|
|
413
|
-
* @param record
|
|
414
|
-
* Record in which to look up keys.
|
|
415
|
-
*/
|
|
416
|
-
constructor(typeName: string, record: Readonly<Record<string, T>>);
|
|
417
|
-
/**
|
|
418
|
-
* Get the type name.
|
|
419
|
-
*/
|
|
420
|
-
get typeName(): string;
|
|
421
|
-
/**
|
|
422
|
-
* Get the record.
|
|
423
|
-
*/
|
|
424
|
-
get record(): Readonly<Record<string, T>>;
|
|
425
|
-
/**
|
|
426
|
-
* Validate a key by looking it up in the record.
|
|
427
|
-
*
|
|
428
|
-
* @param key
|
|
429
|
-
* Record key.
|
|
430
|
-
*/
|
|
431
|
-
validate(key: string): void;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
/**
|
|
435
|
-
* Exclusion options for validating and creating strings based on character sets.
|
|
436
|
-
*/
|
|
437
|
-
declare const Exclusions: {
|
|
438
|
-
/**
|
|
439
|
-
* No strings excluded.
|
|
440
|
-
*/
|
|
441
|
-
readonly None: 0;
|
|
442
|
-
/**
|
|
443
|
-
* Strings that start with zero ('0') excluded.
|
|
444
|
-
*/
|
|
445
|
-
readonly FirstZero: 1;
|
|
446
|
-
/**
|
|
447
|
-
* Strings that are all-numeric (e.g., "123456") excluded.
|
|
448
|
-
*/
|
|
449
|
-
readonly AllNumeric: 2;
|
|
450
|
-
};
|
|
451
|
-
/**
|
|
452
|
-
* Exclusion key.
|
|
453
|
-
*/
|
|
454
|
-
type ExclusionKey = keyof typeof Exclusions;
|
|
455
|
-
/**
|
|
456
|
-
* Exclusion.
|
|
457
|
-
*/
|
|
458
|
-
type Exclusion = typeof Exclusions[ExclusionKey];
|
|
459
|
-
|
|
460
|
-
/**
|
|
461
|
-
* Character set validation parameters.
|
|
462
|
-
*/
|
|
463
|
-
interface CharacterSetValidation extends StringValidation {
|
|
464
|
-
/**
|
|
465
|
-
* Minimum length. If defined and the string is less than this length, an error is thrown.
|
|
466
|
-
*/
|
|
467
|
-
minimumLength?: number | undefined;
|
|
468
|
-
/**
|
|
469
|
-
* Maximum length. If defined and the string is greater than this length, an error is thrown.
|
|
470
|
-
*/
|
|
471
|
-
maximumLength?: number | undefined;
|
|
472
|
-
/**
|
|
473
|
-
* Exclusion from the string. If defined and the string is within the exclusion range, an error is thrown.
|
|
474
|
-
*/
|
|
475
|
-
exclusion?: Exclusion | undefined;
|
|
476
|
-
/**
|
|
477
|
-
* Position offset within a larger string. Strings are sometimes composed of multiple substrings; this parameter
|
|
478
|
-
* ensures that the error notes the proper position in the string.
|
|
479
|
-
*/
|
|
480
|
-
positionOffset?: number | undefined;
|
|
481
|
-
/**
|
|
482
|
-
* Name of component, typically but not exclusively within a larger string. This parameter ensure that the
|
|
483
|
-
* error notes the component that triggered it. Value may be a string or a callback that returns a string, the
|
|
484
|
-
* latter allowing for localization changes.
|
|
485
|
-
*/
|
|
486
|
-
component?: string | (() => string) | undefined;
|
|
487
|
-
}
|
|
488
|
-
/**
|
|
489
|
-
* Character set validator. Validates a string against a specified character set.
|
|
490
|
-
*/
|
|
491
|
-
declare class CharacterSetValidator implements StringValidator<CharacterSetValidation> {
|
|
492
|
-
#private;
|
|
493
|
-
/**
|
|
494
|
-
* Constructor.
|
|
495
|
-
*
|
|
496
|
-
* @param characterSet
|
|
497
|
-
* Character set. Each element is a single-character string, unique within the array, that defines the character
|
|
498
|
-
* set.
|
|
499
|
-
*
|
|
500
|
-
* @param exclusionSupport
|
|
501
|
-
* Exclusions supported by the character set. All character sets implicitly support {@linkcode Exclusions.None}.
|
|
502
|
-
*/
|
|
503
|
-
constructor(characterSet: readonly string[], ...exclusionSupport: readonly Exclusion[]);
|
|
504
|
-
/**
|
|
505
|
-
* Get the character set.
|
|
506
|
-
*/
|
|
507
|
-
get characterSet(): readonly string[];
|
|
508
|
-
/**
|
|
509
|
-
* Get the character set size.
|
|
510
|
-
*/
|
|
511
|
-
get characterSetSize(): number;
|
|
512
|
-
/**
|
|
513
|
-
* Get the exclusions supported by the character set.
|
|
514
|
-
*/
|
|
515
|
-
get exclusionSupport(): readonly Exclusion[];
|
|
516
|
-
/**
|
|
517
|
-
* Get the character at an index.
|
|
518
|
-
*
|
|
519
|
-
* @param index
|
|
520
|
-
* Index into the character set.
|
|
521
|
-
*
|
|
522
|
-
* @returns
|
|
523
|
-
* Character at the index.
|
|
524
|
-
*/
|
|
525
|
-
character(index: number): string;
|
|
526
|
-
/**
|
|
527
|
-
* Get the index for a character.
|
|
528
|
-
*
|
|
529
|
-
* @param c
|
|
530
|
-
* Character.
|
|
531
|
-
*
|
|
532
|
-
* @returns
|
|
533
|
-
* Index for the character or undefined if the character is not in the character set.
|
|
534
|
-
*/
|
|
535
|
-
characterIndex(c: string): number | undefined;
|
|
536
|
-
/**
|
|
537
|
-
* Get the indexes for all characters in a string.
|
|
538
|
-
*
|
|
539
|
-
* @param s
|
|
540
|
-
* String.
|
|
541
|
-
*
|
|
542
|
-
* @returns
|
|
543
|
-
* Array of indexes for each character or undefined if the character is not in the character set.
|
|
544
|
-
*/
|
|
545
|
-
characterIndexes(s: string): ReadonlyArray<number | undefined>;
|
|
546
|
-
/**
|
|
547
|
-
* Validate that an exclusion is supported. If not, an error is thrown.
|
|
548
|
-
*
|
|
549
|
-
* @param exclusion
|
|
550
|
-
* Exclusion.
|
|
551
|
-
*/
|
|
552
|
-
protected validateExclusion(exclusion: Exclusion | undefined): void;
|
|
553
|
-
/**
|
|
554
|
-
* Validate a string. If the string violates the character set or any of the character set validation parameters, an
|
|
555
|
-
* error is thrown.
|
|
556
|
-
*
|
|
557
|
-
* @param s
|
|
558
|
-
* String.
|
|
559
|
-
*
|
|
560
|
-
* @param validation
|
|
561
|
-
* Character set validation parameters.
|
|
562
|
-
*/
|
|
563
|
-
validate(s: string, validation?: CharacterSetValidation): void;
|
|
564
|
-
}
|
|
565
|
-
/**
|
|
566
|
-
* Character set creator. Maps numeric values to strings using the character set as digits.
|
|
567
|
-
*/
|
|
568
|
-
declare class CharacterSetCreator extends CharacterSetValidator {
|
|
569
|
-
#private;
|
|
570
|
-
/**
|
|
571
|
-
* Maximum string length supported.
|
|
572
|
-
*/
|
|
573
|
-
static readonly MAXIMUM_STRING_LENGTH = 40;
|
|
574
|
-
/**
|
|
575
|
-
* Get a power of 10.
|
|
576
|
-
*
|
|
577
|
-
* @param power
|
|
578
|
-
* Power.
|
|
579
|
-
*
|
|
580
|
-
* @returns
|
|
581
|
-
* `10**power`.
|
|
582
|
-
*/
|
|
583
|
-
static powerOf10(power: number): bigint;
|
|
584
|
-
/**
|
|
585
|
-
* Constructor.
|
|
586
|
-
*
|
|
587
|
-
* @param characterSet
|
|
588
|
-
* Character set. Each element is a single-character string, unique within the array, that defines the character
|
|
589
|
-
* set.
|
|
590
|
-
*
|
|
591
|
-
* @param exclusionSupport
|
|
592
|
-
* Exclusions supported by the character set. All character sets implicitly support {@linkcode Exclusions.None}.
|
|
593
|
-
*/
|
|
594
|
-
constructor(characterSet: readonly string[], ...exclusionSupport: readonly Exclusion[]);
|
|
595
|
-
/**
|
|
596
|
-
* Create a string by mapping a value to the equivalent characters in the character set across the required string
|
|
597
|
-
* length.
|
|
598
|
-
*
|
|
599
|
-
* @param length
|
|
600
|
-
* Required string length.
|
|
601
|
-
*
|
|
602
|
-
* @param value
|
|
603
|
-
* Numeric value of the string.
|
|
604
|
-
*
|
|
605
|
-
* @param exclusion
|
|
606
|
-
* Strings to be excluded from the output range. See {@linkcode Exclusions} for possible values and their meanings.
|
|
607
|
-
*
|
|
608
|
-
* @param tweak
|
|
609
|
-
* If provided, the numeric value of the string is "tweaked" using an {@link EncryptionTransformer | encryption
|
|
610
|
-
* transformer}.
|
|
611
|
-
*
|
|
612
|
-
* @param creatorCallback
|
|
613
|
-
* Called after the string is constructed to create the final value.
|
|
614
|
-
*
|
|
615
|
-
* @returns
|
|
616
|
-
* String created from the value.
|
|
617
|
-
*/
|
|
618
|
-
create(length: number, value: number | bigint, exclusion?: Exclusion, tweak?: number | bigint, creatorCallback?: IndexedCallback<string, string>): string;
|
|
619
|
-
/**
|
|
620
|
-
* Create strings by mapping values to the equivalent characters in the character set across the required string
|
|
621
|
-
* length.
|
|
622
|
-
*
|
|
623
|
-
* @param length
|
|
624
|
-
* Required string length.
|
|
625
|
-
*
|
|
626
|
-
* @param values
|
|
627
|
-
* Numeric values of the string.
|
|
628
|
-
*
|
|
629
|
-
* @param exclusion
|
|
630
|
-
* Strings to be excluded from the output range. See {@linkcode Exclusions} for possible values and their meanings.
|
|
631
|
-
*
|
|
632
|
-
* @param tweak
|
|
633
|
-
* If provided, the numeric value of each string is "tweaked" using an {@link EncryptionTransformer | encryption
|
|
634
|
-
* transformer}.
|
|
635
|
-
*
|
|
636
|
-
* @param creatorCallback
|
|
637
|
-
* Called after each string is constructed to create the final value.
|
|
638
|
-
*
|
|
639
|
-
* @returns
|
|
640
|
-
* Strings created from the values.
|
|
641
|
-
*/
|
|
642
|
-
create(length: number, values: Iterable<number | bigint>, exclusion?: Exclusion, tweak?: number | bigint, creatorCallback?: IndexedCallback<string, string>): Iterable<string>;
|
|
643
|
-
create<TInput extends number | bigint | Iterable<number | bigint>>(length: number, valueOrValues: TInput extends Iterable<number | bigint> ? TInput : number | bigint, exclusion?: Exclusion, tweak?: number | bigint, creatorCallback?: IndexedCallback<string, string>): TInput extends Iterable<number | bigint> ? Iterable<string> : string;
|
|
644
|
-
/**
|
|
645
|
-
* Determine the value for a string.
|
|
646
|
-
*
|
|
647
|
-
* @param s
|
|
648
|
-
* String.
|
|
649
|
-
*
|
|
650
|
-
* @param exclusion
|
|
651
|
-
* Strings excluded from the input domain. See {@linkcode Exclusions} for possible values and their meanings.
|
|
652
|
-
*
|
|
653
|
-
* @param tweak
|
|
654
|
-
* If provided, the numerical value of the string was "tweaked" using an {@link EncryptionTransformer | encryption
|
|
655
|
-
* transformer}.
|
|
656
|
-
*
|
|
657
|
-
* @returns
|
|
658
|
-
* Numeric value of the string.
|
|
659
|
-
*/
|
|
660
|
-
valueFor(s: string, exclusion?: Exclusion, tweak?: number | bigint): bigint;
|
|
661
|
-
}
|
|
662
|
-
/**
|
|
663
|
-
* Numeric creator. Character set is 0-9. Supports {@linkcode Exclusions.FirstZero}.
|
|
664
|
-
*/
|
|
665
|
-
declare const NUMERIC_CREATOR: CharacterSetCreator;
|
|
666
|
-
/**
|
|
667
|
-
* Numeric validator. Character set is 0-9. Supports {@linkcode Exclusions.FirstZero}.
|
|
668
|
-
*/
|
|
669
|
-
declare const NUMERIC_VALIDATOR: CharacterSetValidator;
|
|
670
|
-
/**
|
|
671
|
-
* Hexadecimal creator. Character set is 0-9, A-F. Supports {@linkcode Exclusions.FirstZero} and {@linkcode
|
|
672
|
-
* Exclusions.AllNumeric}.
|
|
673
|
-
*/
|
|
674
|
-
declare const HEXADECIMAL_CREATOR: CharacterSetCreator;
|
|
675
|
-
/**
|
|
676
|
-
* Hexadecimal validator. Character set is 0-9, A-F. Supports {@linkcode Exclusions.FirstZero} and {@linkcode
|
|
677
|
-
* Exclusions.AllNumeric}.
|
|
678
|
-
*/
|
|
679
|
-
declare const HEXADECIMAL_VALIDATOR: CharacterSetValidator;
|
|
680
|
-
/**
|
|
681
|
-
* Alphabetic creator. Character set is A-Z.
|
|
682
|
-
*/
|
|
683
|
-
declare const ALPHABETIC_CREATOR: CharacterSetCreator;
|
|
684
|
-
/**
|
|
685
|
-
* Alphabetic validator. Character set is A-Z.
|
|
686
|
-
*/
|
|
687
|
-
declare const ALPHABETIC_VALIDATOR: CharacterSetValidator;
|
|
688
|
-
/**
|
|
689
|
-
* Alphanumeric creator. Character set is 0-9, A-Z. Supports {@linkcode Exclusions.FirstZero} and {@linkcode
|
|
690
|
-
* Exclusions.AllNumeric}.
|
|
691
|
-
*/
|
|
692
|
-
declare const ALPHANUMERIC_CREATOR: CharacterSetCreator;
|
|
693
|
-
/**
|
|
694
|
-
* Alphanumeric validator. Character set is 0-9, A-Z. Supports {@linkcode Exclusions.FirstZero} and {@linkcode
|
|
695
|
-
* Exclusions.AllNumeric}.
|
|
696
|
-
*/
|
|
697
|
-
declare const ALPHANUMERIC_VALIDATOR: CharacterSetValidator;
|
|
698
|
-
|
|
699
|
-
export { ALPHABETIC_CREATOR, ALPHABETIC_VALIDATOR, ALPHANUMERIC_CREATOR, ALPHANUMERIC_VALIDATOR, CharacterSetCreator, type CharacterSetValidation, CharacterSetValidator, EncryptionTransformer, type Exclusion, type ExclusionKey, Exclusions, HEXADECIMAL_CREATOR, HEXADECIMAL_VALIDATOR, IdentityTransformer, type IndexedCallback, NUMERIC_CREATOR, NUMERIC_VALIDATOR, RecordValidator, RegExpValidator, Sequence, type StringValidation, type StringValidator, Transformer, type UtilityLocaleResources, i18nUtilityInit, i18nextUtility, mapIterable, utilityNS, utilityResourceBundle };
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright © 2024-2026 Dolphin Data Development Ltd. and AIDC Toolkit
|
|
3
|
+
* contributors
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
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";
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|