@aidc-toolkit/utility 0.9.7-beta → 0.9.9-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/LICENSE +0 -27
- package/README.md +14 -0
- package/dist/index.cjs +163 -533
- package/dist/index.d.cts +156 -89
- package/dist/index.d.ts +156 -89
- package/dist/index.js +145 -528
- package/package.json +8 -7
- package/src/{character_set.ts → character-set.ts} +18 -37
- package/src/index.ts +20 -6
- package/src/locale/en/{locale_strings.ts → locale-strings.ts} +2 -2
- package/src/locale/fr/{locale_strings.ts → locale-strings.ts} +2 -2
- package/src/locale/i18n.ts +38 -6
- package/src/locale/i18next.d.ts +3 -3
- package/src/record.ts +3 -4
- package/src/{reg_exp.ts → reg-exp.ts} +2 -3
- package/src/sequence.ts +107 -0
- package/src/transformer.ts +156 -87
- package/test/{character_set.test.ts → character-set.test.ts} +7 -6
- package/test/record.test.ts +3 -3
- package/test/{reg_exp.test.ts → reg-exp.test.ts} +3 -3
- package/test/sequence.test.ts +61 -0
- package/test/transformer.test.ts +38 -11
- package/src/iterator_proxy.ts +0 -517
- package/src/sequencer.ts +0 -149
- package/src/types.ts +0 -46
- package/test/iterator_proxy.test.ts +0 -252
- package/test/sequencer.test.ts +0 -72
package/dist/index.d.ts
CHANGED
|
@@ -1,63 +1,67 @@
|
|
|
1
|
-
|
|
1
|
+
import { I18NEnvironment } from '@aidc-toolkit/core';
|
|
2
|
+
import { Resource, i18n } from 'i18next';
|
|
3
|
+
|
|
4
|
+
declare const localeStrings: {
|
|
5
|
+
readonly Transformer: {
|
|
6
|
+
readonly domainMustBeGreaterThanZero: "Domain {{domain}} must be greater than 0";
|
|
7
|
+
readonly tweakMustBeGreaterThanOrEqualToZero: "Tweak {{tweak}} must be greater than or equal to 0";
|
|
8
|
+
readonly valueMustBeGreaterThanOrEqualToZero: "Value {{value}} must be greater than or equal to 0";
|
|
9
|
+
readonly valueMustBeLessThan: "Value {{value}} must be less than {{domain}}";
|
|
10
|
+
readonly minimumValueMustBeGreaterThanOrEqualToZero: "Minimum value {{minimumValue}} must be greater than or equal to 0";
|
|
11
|
+
readonly maximumValueMustBeLessThan: "Maximum value {{maximumValue}} must be less than {{domain}}";
|
|
12
|
+
};
|
|
13
|
+
readonly RegExpValidator: {
|
|
14
|
+
readonly stringDoesNotMatchPattern: "String {{s}} does not match pattern";
|
|
15
|
+
};
|
|
16
|
+
readonly CharacterSetValidator: {
|
|
17
|
+
readonly firstZeroFirstCharacter: "Character set must support zero as first character";
|
|
18
|
+
readonly allNumericAllNumericCharacters: "Character set must support all numeric characters in sequence";
|
|
19
|
+
readonly stringMustNotBeAllNumeric: "String must not be all numeric";
|
|
20
|
+
readonly lengthMustBeGreaterThanOrEqualTo: "Length {{length}} must be greater than or equal to {{minimumLength}}";
|
|
21
|
+
readonly lengthMustBeLessThanOrEqualTo: "Length {{length}} must be less than or equal to {{maximumLength}}";
|
|
22
|
+
readonly lengthMustBeEqualTo: "Length {{length}} must be equal to {{exactLength}}";
|
|
23
|
+
readonly lengthOfComponentMustBeGreaterThanOrEqualTo: "Length {{length}} of {{component}} must be greater than or equal to {{minimumLength}}";
|
|
24
|
+
readonly lengthOfComponentMustBeLessThanOrEqualTo: "Length {{length}} of {{component}} must be less than or equal to {{maximumLength}}";
|
|
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
|
+
};
|
|
2
36
|
|
|
37
|
+
declare const utilityNS = "aidct_utility";
|
|
3
38
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* - T (primitive type)
|
|
7
|
-
* - Iterable<T>
|
|
8
|
-
*
|
|
9
|
-
* @template T
|
|
10
|
-
* Primitive type.
|
|
39
|
+
* Locale strings type is extracted from the English locale strings object.
|
|
11
40
|
*/
|
|
12
|
-
type
|
|
41
|
+
type UtilityLocaleStrings = typeof localeStrings;
|
|
13
42
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* @template TInput
|
|
17
|
-
* Type of input to callback.
|
|
18
|
-
*
|
|
19
|
-
* @template TOutput
|
|
20
|
-
* Type of output to callback.
|
|
21
|
-
*
|
|
22
|
-
* @param input
|
|
23
|
-
* Input value.
|
|
24
|
-
*
|
|
25
|
-
* @param index
|
|
26
|
-
* Index in sequence (0 for single transformation).
|
|
27
|
-
*
|
|
28
|
-
* @returns
|
|
29
|
-
* Output value.
|
|
43
|
+
* Utility resources.
|
|
30
44
|
*/
|
|
31
|
-
|
|
45
|
+
declare const utilityResources: Resource;
|
|
46
|
+
declare const i18nextUtility: i18n;
|
|
32
47
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* - If type T is primitive type, result is type U.
|
|
36
|
-
* - If type T is Iterable type, result is type IterableIterator<U>.
|
|
48
|
+
* Initialize internationalization.
|
|
37
49
|
*
|
|
38
|
-
* @
|
|
39
|
-
*
|
|
50
|
+
* @param environment
|
|
51
|
+
* Environment in which the application is running.
|
|
40
52
|
*
|
|
41
|
-
* @
|
|
42
|
-
*
|
|
43
|
-
*/
|
|
44
|
-
type TransformerOutput<T extends TransformerInput<string | number | bigint | boolean>, U> = T extends (T extends TransformerInput<infer V> ? V : never) ? U : IterableIterator<U>;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Iterator proxy. In environments where
|
|
48
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator#iterator_helpers |
|
|
49
|
-
* iterator helpers} are supported, this references the {@linkcode Iterator} variable directly. Otherwise, it references
|
|
50
|
-
* an implementation of "from" that uses an internally-defined iterator proxy object.
|
|
53
|
+
* @param debug
|
|
54
|
+
* Debug setting.
|
|
51
55
|
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
56
|
+
* @returns
|
|
57
|
+
* Void promise.
|
|
54
58
|
*/
|
|
55
|
-
declare
|
|
59
|
+
declare function i18nUtilityInit(environment: I18NEnvironment, debug?: boolean): Promise<void>;
|
|
56
60
|
|
|
57
61
|
/**
|
|
58
|
-
*
|
|
62
|
+
* Sequence. Defines an ascending or descending sequence of big integers implemented as an iterable.
|
|
59
63
|
*/
|
|
60
|
-
declare class
|
|
64
|
+
declare class Sequence implements Iterable<bigint> {
|
|
61
65
|
/**
|
|
62
66
|
* Start value (inclusive).
|
|
63
67
|
*/
|
|
@@ -77,15 +81,11 @@ declare class Sequencer implements Iterable<bigint>, IterableIterator<bigint> {
|
|
|
77
81
|
/**
|
|
78
82
|
* Minimum value (inclusive).
|
|
79
83
|
*/
|
|
80
|
-
private readonly
|
|
84
|
+
private readonly _minimumValue;
|
|
81
85
|
/**
|
|
82
86
|
* Maximum value (inclusive).
|
|
83
87
|
*/
|
|
84
|
-
private readonly
|
|
85
|
-
/**
|
|
86
|
-
* Next value.
|
|
87
|
-
*/
|
|
88
|
-
private _nextValue;
|
|
88
|
+
private readonly _maximumValue;
|
|
89
89
|
/**
|
|
90
90
|
* Constructor.
|
|
91
91
|
*
|
|
@@ -112,31 +112,79 @@ declare class Sequencer implements Iterable<bigint>, IterableIterator<bigint> {
|
|
|
112
112
|
/**
|
|
113
113
|
* Get the minimum value (inclusive).
|
|
114
114
|
*/
|
|
115
|
-
get
|
|
115
|
+
get minimumValue(): bigint;
|
|
116
116
|
/**
|
|
117
117
|
* Get the maximum value (inclusive).
|
|
118
118
|
*/
|
|
119
|
-
get
|
|
119
|
+
get maximumValue(): bigint;
|
|
120
120
|
/**
|
|
121
121
|
* Iterable implementation.
|
|
122
122
|
*
|
|
123
|
-
* @
|
|
124
|
-
*
|
|
123
|
+
* @yields
|
|
124
|
+
* Next value in sequence.
|
|
125
125
|
*/
|
|
126
|
-
[Symbol.iterator]():
|
|
127
|
-
/**
|
|
128
|
-
* Iterator implementation.
|
|
129
|
-
*
|
|
130
|
-
* @returns
|
|
131
|
-
* Iterator result. If iterator is exhausted, the value is absolute value of the count.
|
|
132
|
-
*/
|
|
133
|
-
next(): IteratorResult<bigint, number>;
|
|
134
|
-
/**
|
|
135
|
-
* Reset the iterator.
|
|
136
|
-
*/
|
|
137
|
-
reset(): void;
|
|
126
|
+
[Symbol.iterator](): Generator<bigint>;
|
|
138
127
|
}
|
|
139
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>;
|
|
140
188
|
/**
|
|
141
189
|
* Transformer that transforms values in a numeric domain to values in a range equal to the domain or to another range
|
|
142
190
|
* defined by a callback function. In other words, the domain determines valid input values and, without a callback, the
|
|
@@ -207,31 +255,57 @@ declare abstract class Transformer {
|
|
|
207
255
|
* Transformed value.
|
|
208
256
|
*/
|
|
209
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;
|
|
210
284
|
/**
|
|
211
285
|
* Transform value(s) forward.
|
|
212
286
|
*
|
|
213
|
-
* @template
|
|
287
|
+
* @template TTransformerInput
|
|
214
288
|
* Value(s) input type.
|
|
215
289
|
*
|
|
216
290
|
* @param valueOrValues
|
|
217
|
-
* Value(s). If this is an instance of {@link
|
|
291
|
+
* Value(s). If this is an instance of {@link Sequence}, the minimum and maximum values are validated prior to
|
|
218
292
|
* transformation. Otherwise, the individual value(s) is/are validated at the time of transformation.
|
|
219
293
|
*
|
|
220
294
|
* @returns
|
|
221
295
|
* Transformed value(s).
|
|
222
296
|
*/
|
|
223
|
-
forward<
|
|
297
|
+
forward<TTransformerInput extends TransformerInput<number | bigint>>(valueOrValues: TTransformerInput): TransformerOutput<TTransformerInput, bigint>;
|
|
224
298
|
/**
|
|
225
299
|
* Transform value(s) forward, optionally applying a transformation.
|
|
226
300
|
*
|
|
227
|
-
* @template
|
|
301
|
+
* @template TTransformerInput
|
|
228
302
|
* Value(s) input type.
|
|
229
303
|
*
|
|
230
|
-
* @template
|
|
304
|
+
* @template TOutput
|
|
231
305
|
* Transformation callback output type.
|
|
232
306
|
*
|
|
233
307
|
* @param valueOrValues
|
|
234
|
-
* Value(s). If this is an instance of {@link
|
|
308
|
+
* Value(s). If this is an instance of {@link Sequence}, the minimum and maximum values are validated prior to
|
|
235
309
|
* transformation. Otherwise, the individual value(s) is/are validated at the time of transformation.
|
|
236
310
|
*
|
|
237
311
|
* @param transformerCallback
|
|
@@ -240,7 +314,7 @@ declare abstract class Transformer {
|
|
|
240
314
|
* @returns
|
|
241
315
|
* Transformed value(s).
|
|
242
316
|
*/
|
|
243
|
-
forward<
|
|
317
|
+
forward<TTransformerInput extends TransformerInput<number | bigint>, TOutput>(valueOrValues: TTransformerInput, transformerCallback: TransformerCallback<bigint, TOutput>): TransformerOutput<TTransformerInput, TOutput>;
|
|
244
318
|
/**
|
|
245
319
|
* Do the work of transforming a value in reverse.
|
|
246
320
|
*
|
|
@@ -276,10 +350,11 @@ declare class IdentityTransformer extends Transformer {
|
|
|
276
350
|
protected doReverse(transformedValue: bigint): bigint;
|
|
277
351
|
}
|
|
278
352
|
/**
|
|
279
|
-
* Encryption transformer. Values are transformed using repeated shuffle and xor operations
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
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.
|
|
283
358
|
*
|
|
284
359
|
* The purpose of the encryption transformer is to generate pseudo-random values in a deterministic manner to obscure
|
|
285
360
|
* the sequence of values generated over time. A typical example is for serial number generation, where knowledge of the
|
|
@@ -308,10 +383,6 @@ declare class EncryptionTransformer extends Transformer {
|
|
|
308
383
|
* Number of bytes covered by the domain.
|
|
309
384
|
*/
|
|
310
385
|
private readonly _domainBytes;
|
|
311
|
-
/**
|
|
312
|
-
* Tweak.
|
|
313
|
-
*/
|
|
314
|
-
private readonly _tweak;
|
|
315
386
|
/**
|
|
316
387
|
* Xor bytes array generated from the domain and tweak.
|
|
317
388
|
*/
|
|
@@ -338,10 +409,6 @@ declare class EncryptionTransformer extends Transformer {
|
|
|
338
409
|
* Tweak.
|
|
339
410
|
*/
|
|
340
411
|
constructor(domain: number | bigint, tweak: number | bigint);
|
|
341
|
-
/**
|
|
342
|
-
* Get the tweak.
|
|
343
|
-
*/
|
|
344
|
-
get tweak(): bigint;
|
|
345
412
|
/**
|
|
346
413
|
* Convert a value to a byte array big enough to handle the entire domain.
|
|
347
414
|
*
|
|
@@ -839,4 +906,4 @@ declare const ALPHABETIC_CREATOR: CharacterSetCreator;
|
|
|
839
906
|
*/
|
|
840
907
|
declare const ALPHANUMERIC_CREATOR: CharacterSetCreator;
|
|
841
908
|
|
|
842
|
-
export { ALPHABETIC_CREATOR, ALPHANUMERIC_CREATOR, CharacterSetCreator, type CharacterSetValidation, CharacterSetValidator, EncryptionTransformer, Exclusion, HEXADECIMAL_CREATOR, IdentityTransformer,
|
|
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 };
|