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