@aidc-toolkit/utility 0.9.5 → 0.9.7-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/index.cjs +126 -112
- package/dist/index.d.cts +74 -141
- package/dist/index.d.ts +74 -141
- package/dist/index.js +124 -111
- package/package.json +8 -9
- package/src/character_set.ts +34 -83
- package/src/index.ts +2 -0
- package/src/iterator_proxy.ts +5 -5
- package/src/transformer.ts +29 -103
- package/src/types.ts +46 -0
- package/test/character_set.test.ts +2 -3
- package/test/sequencer.test.ts +4 -4
- package/test/transformer.test.ts +2 -2
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -32
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/workflows/build-publish.yml +0 -20
- package/.idea/inspectionProfiles/Project_Default.xml +0 -7
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/runConfigurations/Test_all.xml +0 -12
- package/.idea/runConfigurations/Test_character_set.xml +0 -12
- package/.idea/runConfigurations/Test_iterator_proxy.xml +0 -12
- package/.idea/runConfigurations/Test_record.xml +0 -12
- package/.idea/runConfigurations/Test_regular_expression.xml +0 -12
- package/.idea/runConfigurations/Test_transformer.xml +0 -12
- package/.idea/runConfigurations/build.xml +0 -12
- package/.idea/runConfigurations/eslint.xml +0 -12
- package/.idea/utility.iml +0 -9
- package/.idea/vcs.xml +0 -6
package/src/character_set.ts
CHANGED
|
@@ -2,6 +2,7 @@ import i18next, { utilityNS } from "./locale/i18n.js";
|
|
|
2
2
|
import { RegExpValidator } from "./reg_exp.js";
|
|
3
3
|
import type { StringValidation, StringValidator } from "./string.js";
|
|
4
4
|
import { Transformer } from "./transformer.js";
|
|
5
|
+
import type { TransformerCallback, TransformerInput, TransformerOutput } from "./types.js";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Exclusion options for validating and creating strings based on character sets.
|
|
@@ -291,20 +292,6 @@ export class CharacterSetValidator implements StringValidator<CharacterSetValida
|
|
|
291
292
|
}
|
|
292
293
|
}
|
|
293
294
|
|
|
294
|
-
/**
|
|
295
|
-
* Creation callback, used to convert created string to its final value.
|
|
296
|
-
*
|
|
297
|
-
* @param s
|
|
298
|
-
* Created string.
|
|
299
|
-
*
|
|
300
|
-
* @param index
|
|
301
|
-
* Index in sequence creation (0 for single creation).
|
|
302
|
-
*
|
|
303
|
-
* @returns
|
|
304
|
-
* Final value.
|
|
305
|
-
*/
|
|
306
|
-
export type CreationCallback = (s: string, index: number) => string;
|
|
307
|
-
|
|
308
295
|
/**
|
|
309
296
|
* Character set creator. Maps numeric values to strings using the character set as digits.
|
|
310
297
|
*/
|
|
@@ -418,23 +405,33 @@ export class CharacterSetCreator extends CharacterSetValidator {
|
|
|
418
405
|
if (exclusionSupport.includes(Exclusion.AllNumeric)) {
|
|
419
406
|
const exclusionAllNumericDomains = new Array<bigint>(CharacterSetCreator.MAXIMUM_STRING_LENGTH + 1);
|
|
420
407
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
408
|
+
/**
|
|
409
|
+
* Validate that number indexes are defined and sequential.
|
|
410
|
+
*
|
|
411
|
+
* @param numberIndexes
|
|
412
|
+
* Number indexes.
|
|
413
|
+
*/
|
|
414
|
+
function validateNumberIndexes(numberIndexes: ReadonlyArray<number | undefined>): asserts numberIndexes is number[] {
|
|
415
|
+
let expectedNumberIndex = numberIndexes[0];
|
|
416
|
+
|
|
417
|
+
// Make sure that all numeric characters are present and in sequence.
|
|
418
|
+
for (const numberIndex of numberIndexes) {
|
|
419
|
+
if (numberIndex === undefined || numberIndex !== expectedNumberIndex) {
|
|
420
|
+
throw new RangeError(i18next.t("CharacterSetValidator.allNumericAllNumericCharacters", {
|
|
421
|
+
ns: utilityNS
|
|
422
|
+
}));
|
|
423
|
+
}
|
|
424
424
|
|
|
425
|
-
|
|
426
|
-
for (const numberIndex of numberIndexes) {
|
|
427
|
-
if (numberIndex === undefined || numberIndex !== expectedNumberIndex) {
|
|
428
|
-
throw new RangeError(i18next.t("CharacterSetValidator.allNumericAllNumericCharacters", {
|
|
429
|
-
ns: utilityNS
|
|
430
|
-
}));
|
|
425
|
+
expectedNumberIndex = numberIndex + 1;
|
|
431
426
|
}
|
|
432
|
-
|
|
433
|
-
expectedNumberIndex = numberIndex + 1;
|
|
434
427
|
}
|
|
435
428
|
|
|
429
|
+
const numberIndexes = this.characterIndexes("0123456789");
|
|
430
|
+
|
|
431
|
+
validateNumberIndexes(numberIndexes);
|
|
432
|
+
|
|
436
433
|
// Zero index is the all-zero value for a single-character string.
|
|
437
|
-
const zeroIndex = BigInt(
|
|
434
|
+
const zeroIndex = BigInt(numberIndexes[0]);
|
|
438
435
|
|
|
439
436
|
const allZerosValues = new Array<bigint>(CharacterSetCreator.MAXIMUM_STRING_LENGTH + 1);
|
|
440
437
|
let allZerosValue = 0n;
|
|
@@ -548,79 +545,33 @@ export class CharacterSetCreator extends CharacterSetValidator {
|
|
|
548
545
|
}
|
|
549
546
|
|
|
550
547
|
/**
|
|
551
|
-
* Create
|
|
548
|
+
* Create string(s) by mapping value(s) to the equivalent characters in the character set across the length of the
|
|
552
549
|
* string.
|
|
553
550
|
*
|
|
554
551
|
* @param length
|
|
555
552
|
* Required string length.
|
|
556
553
|
*
|
|
557
|
-
* @param value
|
|
558
|
-
* Numeric value of the string.
|
|
559
|
-
*
|
|
560
|
-
* @param exclusion
|
|
561
|
-
* Strings to be excluded from the range of outputs. See {@link Exclusion} for possible values and their meaning.
|
|
562
|
-
*
|
|
563
|
-
* @param tweak
|
|
564
|
-
* If provided, the numerical value of the string is "tweaked" using an {@link EncryptionTransformer | encryption
|
|
565
|
-
* transformer}.
|
|
566
|
-
*
|
|
567
|
-
* @param creationCallback
|
|
568
|
-
* If provided, called after the string is constructed to create the final value.
|
|
569
|
-
*
|
|
570
|
-
* @returns
|
|
571
|
-
* String created from the value.
|
|
572
|
-
*/
|
|
573
|
-
create(length: number, value: number | bigint, exclusion?: Exclusion, tweak?: number | bigint, creationCallback?: CreationCallback): string;
|
|
574
|
-
|
|
575
|
-
/**
|
|
576
|
-
* Create multiple strings by mapping each value to the equivalent characters in the character set across the length
|
|
577
|
-
* of the string. Equivalent to calling this method for each individual value.
|
|
578
|
-
*
|
|
579
|
-
* @param length
|
|
580
|
-
* Required string length.
|
|
581
|
-
*
|
|
582
|
-
* @param values
|
|
583
|
-
* Numeric values of the strings.
|
|
584
|
-
*
|
|
585
|
-
* @param exclusion
|
|
586
|
-
* Strings to be excluded from the range of outputs. See {@link Exclusion} for possible values and their meaning.
|
|
587
|
-
*
|
|
588
|
-
* @param tweak
|
|
589
|
-
* If provided, the numerical value of the strings are "tweaked" using an {@link EncryptionTransformer | encryption
|
|
590
|
-
* transformer}.
|
|
591
|
-
*
|
|
592
|
-
* @param creationCallback
|
|
593
|
-
* If provided, called after each string is constructed to create the final value.
|
|
594
|
-
*
|
|
595
|
-
* @returns
|
|
596
|
-
* Iterable iterator over strings created from the values.
|
|
597
|
-
*/
|
|
598
|
-
create(length: number, values: Iterable<number | bigint>, exclusion?: Exclusion, tweak?: number | bigint, creationCallback?: CreationCallback): IterableIterator<string>;
|
|
599
|
-
|
|
600
|
-
/**
|
|
601
|
-
* Create a string or multiple strings. This signature exists to allow similar overloaded methods in other classes
|
|
602
|
-
* to call this method correctly.
|
|
603
|
-
*
|
|
604
|
-
* @param length
|
|
605
|
-
*
|
|
606
554
|
* @param valueOrValues
|
|
555
|
+
* Numeric value(s) of the string(s).
|
|
607
556
|
*
|
|
608
557
|
* @param exclusion
|
|
558
|
+
* String(s) to be excluded from the range of outputs. See {@link Exclusion} for possible values and their meaning.
|
|
609
559
|
*
|
|
610
560
|
* @param tweak
|
|
561
|
+
* If provided, the numerical value of the string(s) is/are "tweaked" using an {@link EncryptionTransformer |
|
|
562
|
+
* encryption transformer}.
|
|
611
563
|
*
|
|
612
|
-
* @param
|
|
564
|
+
* @param creatorCallback
|
|
565
|
+
* If provided, called after each string is constructed to create the final value.
|
|
613
566
|
*
|
|
614
567
|
* @returns
|
|
568
|
+
* String(s) created from the value(s).
|
|
615
569
|
*/
|
|
616
|
-
create
|
|
617
|
-
|
|
618
|
-
// eslint-disable-next-line jsdoc/require-jsdoc -- Implementation of overloaded signatures.
|
|
619
|
-
create(length: number, valueOrValues: number | bigint | Iterable<number | bigint>, exclusion: Exclusion = Exclusion.None, tweak?: number | bigint, creationCallback?: CreationCallback): string | IterableIterator<string> {
|
|
570
|
+
create<T extends TransformerInput<number | bigint>>(length: number, valueOrValues: T, exclusion: Exclusion = Exclusion.None, tweak?: number | bigint, creatorCallback?: TransformerCallback<string, string>): TransformerOutput<T, string> {
|
|
620
571
|
this.validateLength(length);
|
|
621
572
|
this.validateExclusion(exclusion);
|
|
622
573
|
|
|
623
|
-
// Zero value obviates need for non-null assertion.
|
|
574
|
+
// Zero value in ternary else obviates need for non-null assertion.
|
|
624
575
|
const allZerosValue = exclusion === Exclusion.AllNumeric ? this._allZerosValues[length] : 0n;
|
|
625
576
|
|
|
626
577
|
const transformer = Transformer.get(this._exclusionDomains[exclusion][length], tweak);
|
|
@@ -651,7 +602,7 @@ export class CharacterSetCreator extends CharacterSetValidator {
|
|
|
651
602
|
s = this.character(exclusion === Exclusion.FirstZero ? Number(convertValue % this._characterSetSizeMinusOneN) + 1 : Number(convertValue % this._characterSetSizeN)) + s;
|
|
652
603
|
}
|
|
653
604
|
|
|
654
|
-
return
|
|
605
|
+
return creatorCallback !== undefined ? creatorCallback(s, index) : s;
|
|
655
606
|
});
|
|
656
607
|
}
|
|
657
608
|
|
package/src/index.ts
CHANGED
package/src/iterator_proxy.ts
CHANGED
|
@@ -150,10 +150,10 @@ abstract class IteratorProxyBase<TInitial, TFinal> implements IteratorObject<TFi
|
|
|
150
150
|
for (const value of this) {
|
|
151
151
|
// Need to check arguments length as U could include undefined.
|
|
152
152
|
if (index === 0 && arguments.length === 1) {
|
|
153
|
-
// Initial value is not supplied only when U is identical to TFinal.
|
|
153
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Initial value is not supplied only when U is identical to TFinal.
|
|
154
154
|
result = value as unknown as U;
|
|
155
155
|
} else {
|
|
156
|
-
// Iteration has occurred at least once so result is of the expected type.
|
|
156
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Iteration has occurred at least once so result is of the expected type.
|
|
157
157
|
result = callback(result as U, value, index);
|
|
158
158
|
}
|
|
159
159
|
|
|
@@ -164,7 +164,7 @@ abstract class IteratorProxyBase<TInitial, TFinal> implements IteratorObject<TFi
|
|
|
164
164
|
throw new Error("reduce() of empty iterator with no initial value");
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
// Iteration has occurred at least once so result is of the expected type.
|
|
167
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Iteration has occurred at least once so result is of the expected type.
|
|
168
168
|
return result as U;
|
|
169
169
|
}
|
|
170
170
|
|
|
@@ -508,8 +508,8 @@ function iteratorProxy(): Pick<typeof Iterator, "from"> {
|
|
|
508
508
|
/**
|
|
509
509
|
* Iterator proxy. In environments where
|
|
510
510
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator#iterator_helpers |
|
|
511
|
-
* iterator helpers} are supported, this references the {@
|
|
512
|
-
* implementation of "from" that uses an internally-defined iterator proxy object.
|
|
511
|
+
* iterator helpers} are supported, this references the {@linkcode Iterator} variable directly. Otherwise, it references
|
|
512
|
+
* an implementation of "from" that uses an internally-defined iterator proxy object.
|
|
513
513
|
*
|
|
514
514
|
* Client applications should **not** rely on long-term availability of this variable as it will be removed once there
|
|
515
515
|
* is widespread support for iterator helpers.
|
package/src/transformer.ts
CHANGED
|
@@ -1,23 +1,7 @@
|
|
|
1
1
|
import { IteratorProxy } from "./iterator_proxy.js";
|
|
2
2
|
import i18next, { utilityNS } from "./locale/i18n.js";
|
|
3
3
|
import { Sequencer } from "./sequencer.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Transformation callback, used to convert transformed value to its final value.
|
|
7
|
-
*
|
|
8
|
-
* @template T
|
|
9
|
-
* Type returned by callback.
|
|
10
|
-
*
|
|
11
|
-
* @param transformedValue
|
|
12
|
-
* Transformed value.
|
|
13
|
-
*
|
|
14
|
-
* @param index
|
|
15
|
-
* Index in sequence transformation (0 for single transformation).
|
|
16
|
-
*
|
|
17
|
-
* @returns
|
|
18
|
-
* Final value.
|
|
19
|
-
*/
|
|
20
|
-
export type TransformationCallback<T> = (transformedValue: bigint, index: number) => T;
|
|
4
|
+
import type { TransformerCallback, TransformerInput, TransformerOutput } from "./types.js";
|
|
21
5
|
|
|
22
6
|
/**
|
|
23
7
|
* Transformer that transforms values in a numeric domain to values in a range equal to the domain or to another range
|
|
@@ -143,104 +127,45 @@ export abstract class Transformer {
|
|
|
143
127
|
protected abstract doForward(value: bigint): bigint;
|
|
144
128
|
|
|
145
129
|
/**
|
|
146
|
-
* Transform
|
|
147
|
-
*
|
|
148
|
-
* @param value
|
|
149
|
-
* Value.
|
|
150
|
-
*
|
|
151
|
-
* @returns
|
|
152
|
-
* Transformed value.
|
|
153
|
-
*/
|
|
154
|
-
forward(value: number | bigint): bigint;
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Transform a value forward.
|
|
158
|
-
*
|
|
159
|
-
* @template T
|
|
160
|
-
* Type returned by transformation callback.
|
|
161
|
-
*
|
|
162
|
-
* @param value
|
|
163
|
-
* Value.
|
|
164
|
-
*
|
|
165
|
-
* @param transformationCallback
|
|
166
|
-
* Called after the value is transformed to convert it to its final value.
|
|
167
|
-
*
|
|
168
|
-
* @returns
|
|
169
|
-
* Value transformed into object.
|
|
170
|
-
*/
|
|
171
|
-
forward<T>(value: number | bigint, transformationCallback: TransformationCallback<T>): T;
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Transform values forward.
|
|
175
|
-
*
|
|
176
|
-
* @param values
|
|
177
|
-
* Values. If this is an instance of {@link Sequencer}, the minimum and maximum values are validated prior to
|
|
178
|
-
* transformation. Otherwise, the individual values are validated at the time of transformation.
|
|
179
|
-
*
|
|
180
|
-
* @returns
|
|
181
|
-
* Transformed values.
|
|
182
|
-
*/
|
|
183
|
-
forward(values: Iterable<number | bigint>): IterableIterator<bigint>;
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Transform values forward.
|
|
130
|
+
* Transform value(s) forward.
|
|
187
131
|
*
|
|
188
132
|
* @template T
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
* @param values
|
|
192
|
-
* Values. If this is an instance of {@link Sequencer}, the minimum and maximum values are validated prior to
|
|
193
|
-
* transformation. Otherwise, the individual values are validated at the time of transformation.
|
|
194
|
-
*
|
|
195
|
-
* @param transformationCallback
|
|
196
|
-
* Called after each value is transformed to convert it to its final value.
|
|
197
|
-
*
|
|
198
|
-
* @returns
|
|
199
|
-
* Values transformed into objects.
|
|
200
|
-
*/
|
|
201
|
-
forward<T>(values: Iterable<number | bigint>, transformationCallback: TransformationCallback<T>): IterableIterator<T>;
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Transform a value or values forward. This signature exists to allow similar overloaded methods in other classes
|
|
205
|
-
* to call this method correctly.
|
|
133
|
+
* Value(s) input type.
|
|
206
134
|
*
|
|
207
135
|
* @param valueOrValues
|
|
136
|
+
* Value(s). If this is an instance of {@link Sequencer}, the minimum and maximum values are validated prior to
|
|
137
|
+
* transformation. Otherwise, the individual value(s) is/are validated at the time of transformation.
|
|
208
138
|
*
|
|
209
139
|
* @returns
|
|
140
|
+
* Transformed value(s).
|
|
210
141
|
*/
|
|
211
|
-
forward
|
|
142
|
+
forward<T extends TransformerInput<number | bigint>>(valueOrValues: T): TransformerOutput<T, bigint>;
|
|
212
143
|
|
|
213
144
|
/**
|
|
214
|
-
* Transform
|
|
215
|
-
* to call this method correctly.
|
|
145
|
+
* Transform value(s) forward, optionally applying a transformation.
|
|
216
146
|
*
|
|
217
147
|
* @template T
|
|
148
|
+
* Value(s) input type.
|
|
218
149
|
*
|
|
219
|
-
* @
|
|
220
|
-
*
|
|
221
|
-
* @param transformationCallback
|
|
222
|
-
*
|
|
223
|
-
* @returns
|
|
224
|
-
*/
|
|
225
|
-
forward<T>(valueOrValues: number | bigint | Iterable<number | bigint>, transformationCallback: TransformationCallback<T>): T | IterableIterator<T>;
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Transform a value or values forward.
|
|
229
|
-
*
|
|
230
|
-
* @template T
|
|
231
|
-
* Type returned by transformation callback.
|
|
150
|
+
* @template U
|
|
151
|
+
* Transformation callback output type.
|
|
232
152
|
*
|
|
233
153
|
* @param valueOrValues
|
|
234
|
-
* Value(s).
|
|
154
|
+
* Value(s). If this is an instance of {@link Sequencer}, the minimum and maximum values are validated prior to
|
|
155
|
+
* transformation. Otherwise, the individual value(s) is/are validated at the time of transformation.
|
|
235
156
|
*
|
|
236
|
-
* @param
|
|
237
|
-
* Called after value
|
|
157
|
+
* @param transformerCallback
|
|
158
|
+
* Called after each value is transformed to convert it to its final value.
|
|
238
159
|
*
|
|
239
160
|
* @returns
|
|
240
|
-
*
|
|
161
|
+
* Transformed value(s).
|
|
241
162
|
*/
|
|
242
|
-
forward<T
|
|
243
|
-
|
|
163
|
+
forward<T extends TransformerInput<number | bigint>, U>(valueOrValues: T, transformerCallback: TransformerCallback<bigint, U>): TransformerOutput<T, U>;
|
|
164
|
+
|
|
165
|
+
// eslint-disable-next-line jsdoc/require-jsdoc -- Implementation of overloaded signatures.
|
|
166
|
+
forward<T extends TransformerInput<number | bigint>, U>(valueOrValues: T, transformerCallback?: TransformerCallback<bigint, U>): TransformerOutput<T, U> {
|
|
167
|
+
// TODO Refactor type when https://github.com/microsoft/TypeScript/pull/56941 released.
|
|
168
|
+
let result: bigint | U | IterableIterator<bigint> | IterableIterator<U>;
|
|
244
169
|
|
|
245
170
|
if (typeof valueOrValues !== "object") {
|
|
246
171
|
const valueN = BigInt(valueOrValues);
|
|
@@ -249,7 +174,7 @@ export abstract class Transformer {
|
|
|
249
174
|
|
|
250
175
|
const transformedValue = this.doForward(valueN);
|
|
251
176
|
|
|
252
|
-
result =
|
|
177
|
+
result = transformerCallback === undefined ? transformedValue : transformerCallback(transformedValue, 0);
|
|
253
178
|
} else if (valueOrValues instanceof Sequencer) {
|
|
254
179
|
if (valueOrValues.minValue < 0n) {
|
|
255
180
|
throw new RangeError(i18next.t("Transformer.minValueMustBeGreaterThanOrEqualToZero", {
|
|
@@ -266,11 +191,11 @@ export abstract class Transformer {
|
|
|
266
191
|
}));
|
|
267
192
|
}
|
|
268
193
|
|
|
269
|
-
result =
|
|
194
|
+
result = transformerCallback === undefined ?
|
|
270
195
|
IteratorProxy.from(valueOrValues).map(value => this.doForward(value)) :
|
|
271
|
-
IteratorProxy.from(valueOrValues).map((value, index) =>
|
|
196
|
+
IteratorProxy.from(valueOrValues).map((value, index) => transformerCallback(this.doForward(value), index));
|
|
272
197
|
} else {
|
|
273
|
-
result =
|
|
198
|
+
result = transformerCallback === undefined ?
|
|
274
199
|
IteratorProxy.from(valueOrValues).map((value) => {
|
|
275
200
|
const valueN = BigInt(value);
|
|
276
201
|
|
|
@@ -283,11 +208,12 @@ export abstract class Transformer {
|
|
|
283
208
|
|
|
284
209
|
this.validate(valueN);
|
|
285
210
|
|
|
286
|
-
return
|
|
211
|
+
return transformerCallback(this.doForward(valueN), index);
|
|
287
212
|
});
|
|
288
213
|
}
|
|
289
214
|
|
|
290
|
-
|
|
215
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type determination is handled above.
|
|
216
|
+
return result as TransformerOutput<T, U>;
|
|
291
217
|
}
|
|
292
218
|
|
|
293
219
|
/**
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transformer input, one of:
|
|
3
|
+
*
|
|
4
|
+
* - T (primitive type)
|
|
5
|
+
* - Iterable<T>
|
|
6
|
+
*
|
|
7
|
+
* @template T
|
|
8
|
+
* Primitive type.
|
|
9
|
+
*/
|
|
10
|
+
export type TransformerInput<T extends string | number | bigint | boolean> =
|
|
11
|
+
T | Iterable<T>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Transformer callback, used to convert transformed value to its final value.
|
|
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.
|
|
30
|
+
*/
|
|
31
|
+
export type TransformerCallback<TInput, TOutput> = (input: TInput, index: number) => TOutput;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Transformer output, based on transformer input:
|
|
35
|
+
*
|
|
36
|
+
* - If type T is primitive type, result is type U.
|
|
37
|
+
* - If type T is Iterable type, result is type IterableIterator<U>.
|
|
38
|
+
*
|
|
39
|
+
* @template T
|
|
40
|
+
* Transformer input type.
|
|
41
|
+
*
|
|
42
|
+
* @template U
|
|
43
|
+
* Output base type.
|
|
44
|
+
*/
|
|
45
|
+
export type TransformerOutput<T extends TransformerInput<string | number | bigint | boolean>, U> =
|
|
46
|
+
T extends (T extends TransformerInput<infer V> ? V : never) ? U : IterableIterator<U>;
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
CharacterSetCreator,
|
|
7
7
|
Exclusion,
|
|
8
8
|
HEXADECIMAL_CREATOR,
|
|
9
|
-
IteratorProxy,
|
|
10
9
|
NUMERIC_CREATOR,
|
|
11
10
|
Sequencer
|
|
12
11
|
} from "../src/index.js";
|
|
@@ -65,7 +64,7 @@ function testCharacterSetCreator(name: string, characterSetCreator: CharacterSet
|
|
|
65
64
|
break;
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
const sequence =
|
|
67
|
+
const sequence = Iterator.from(characterSetCreator.create(length, new Sequencer(0n, domain), exclusion));
|
|
69
68
|
|
|
70
69
|
let previousS = "";
|
|
71
70
|
|
|
@@ -86,7 +85,7 @@ function testCharacterSetCreator(name: string, characterSetCreator: CharacterSet
|
|
|
86
85
|
|
|
87
86
|
expect(() => characterSetCreator.create(length, domain, exclusion)).toThrow(`Value ${domain} must be less than ${domain}`);
|
|
88
87
|
|
|
89
|
-
const sparseSequence =
|
|
88
|
+
const sparseSequence = Iterator.from(characterSetCreator.create(length, new Sequencer(domain - 1, -domain), exclusion, 123456n));
|
|
90
89
|
|
|
91
90
|
let sequential = true;
|
|
92
91
|
previousS = "~";
|
package/test/sequencer.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { I18NEnvironment, i18nInit } from "@aidc-toolkit/core";
|
|
2
2
|
import { describe, expect, test } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import { Sequencer } from "../src/index.js";
|
|
4
4
|
|
|
5
5
|
await i18nInit(I18NEnvironment.CLI);
|
|
6
6
|
|
|
@@ -29,7 +29,7 @@ describe("Sequence", () => {
|
|
|
29
29
|
expectedValue = 10n;
|
|
30
30
|
count = 0;
|
|
31
31
|
|
|
32
|
-
for (const value of
|
|
32
|
+
for (const value of Iterator.from(sequencer1)) {
|
|
33
33
|
expect(value).toBe(expectedValue);
|
|
34
34
|
|
|
35
35
|
expectedValue++;
|
|
@@ -41,7 +41,7 @@ describe("Sequence", () => {
|
|
|
41
41
|
expectedValue = 29n;
|
|
42
42
|
count = 0;
|
|
43
43
|
|
|
44
|
-
for (const value of
|
|
44
|
+
for (const value of Iterator.from(sequencer2)) {
|
|
45
45
|
expect(value).toBe(expectedValue);
|
|
46
46
|
|
|
47
47
|
expectedValue--;
|
|
@@ -60,7 +60,7 @@ describe("Sequence", () => {
|
|
|
60
60
|
|
|
61
61
|
sequencer1.reset();
|
|
62
62
|
|
|
63
|
-
for (const value of
|
|
63
|
+
for (const value of Iterator.from(sequencer1)) {
|
|
64
64
|
expect(value).toBe(expectedValue);
|
|
65
65
|
|
|
66
66
|
expectedValue++;
|
package/test/transformer.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { I18NEnvironment, i18nInit } from "@aidc-toolkit/core";
|
|
2
2
|
import { describe, expect, test } from "vitest";
|
|
3
|
-
import { EncryptionTransformer, IdentityTransformer,
|
|
3
|
+
import { EncryptionTransformer, IdentityTransformer, Sequencer, Transformer } from "../src/index.js";
|
|
4
4
|
|
|
5
5
|
await i18nInit(I18NEnvironment.CLI);
|
|
6
6
|
|
|
@@ -11,7 +11,7 @@ function testTransformer(domain: number, tweak?: number, callback?: (value: bigi
|
|
|
11
11
|
|
|
12
12
|
const transformedValuesSet = new Set<bigint>();
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
Iterator.from(transformer.forward(new Sequencer(0n, domain))).forEach((transformedValue, index) => {
|
|
15
15
|
const indexN = BigInt(index);
|
|
16
16
|
|
|
17
17
|
if (sequential && transformedValue !== indexN) {
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Bug report
|
|
3
|
-
about: Create a report to help us improve
|
|
4
|
-
title: ''
|
|
5
|
-
labels: ''
|
|
6
|
-
assignees: ''
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
**Describe the bug**
|
|
11
|
-
A clear and concise description of what the bug is.
|
|
12
|
-
|
|
13
|
-
**To Reproduce**
|
|
14
|
-
Steps to reproduce the behavior:
|
|
15
|
-
1. Go to '...'
|
|
16
|
-
2. Click on '....'
|
|
17
|
-
3. Scroll down to '....'
|
|
18
|
-
4. See error
|
|
19
|
-
|
|
20
|
-
**Expected behavior**
|
|
21
|
-
A clear and concise description of what you expected to happen.
|
|
22
|
-
|
|
23
|
-
**Screenshots**
|
|
24
|
-
If applicable, add screenshots to help explain your problem.
|
|
25
|
-
|
|
26
|
-
**Platform**
|
|
27
|
-
- OS: [e.g. Windows, iOS]
|
|
28
|
-
- Browser [e.g. chrome, safari]
|
|
29
|
-
- Browser Version [e.g. 22]
|
|
30
|
-
|
|
31
|
-
**Additional context**
|
|
32
|
-
Add any other context about the problem here.
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Feature request
|
|
3
|
-
about: Suggest an idea for this project
|
|
4
|
-
title: ''
|
|
5
|
-
labels: ''
|
|
6
|
-
assignees: ''
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
**Is your feature request related to a problem? Please describe.**
|
|
11
|
-
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
|
12
|
-
|
|
13
|
-
**Describe the solution you'd like**
|
|
14
|
-
A clear and concise description of what you want to happen.
|
|
15
|
-
|
|
16
|
-
**Describe alternatives you've considered**
|
|
17
|
-
A clear and concise description of any alternative solutions or features you've considered.
|
|
18
|
-
|
|
19
|
-
**Additional context**
|
|
20
|
-
Add any other context or screenshots about the feature request here.
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
name: Build and publish
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
release:
|
|
5
|
-
types:
|
|
6
|
-
- published
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
build-and-publish:
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
|
|
12
|
-
steps:
|
|
13
|
-
- name: Build and publish utility
|
|
14
|
-
uses: aidc-toolkit/dev/.github/actions/build-publish@main
|
|
15
|
-
with:
|
|
16
|
-
project: utility
|
|
17
|
-
node_version: ${{ vars.NODE_VERSION }}
|
|
18
|
-
node_auth_token: ${{ secrets.NODE_AUTH_TOKEN }}
|
|
19
|
-
terminal_pre_build: ${{ vars.TERMINAL_PRE_BUILD }}
|
|
20
|
-
terminal_post_build: ${{ vars.TERMINAL_POST_BUILD }}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
<component name="InspectionProjectProfileManager">
|
|
2
|
-
<profile version="1.0">
|
|
3
|
-
<option name="myName" value="Project Default" />
|
|
4
|
-
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
|
5
|
-
<inspection_tool class="UpdateDependencyToLatestVersion" enabled="true" level="WARNING" enabled_by_default="true" editorAttributes="WARNING_ATTRIBUTES" />
|
|
6
|
-
</profile>
|
|
7
|
-
</component>
|
package/.idea/misc.xml
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="openjdk-21" project-jdk-type="JavaSDK">
|
|
4
|
-
<output url="file://$PROJECT_DIR$/out" />
|
|
5
|
-
</component>
|
|
6
|
-
</project>
|
package/.idea/modules.xml
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<component name="ProjectRunConfigurationManager">
|
|
2
|
-
<configuration default="false" name="Test all" type="JavaScriptTestRunnerVitest">
|
|
3
|
-
<node-interpreter value="project" />
|
|
4
|
-
<vitest-package value="$PROJECT_DIR$/node_modules/vitest" />
|
|
5
|
-
<working-dir value="$PROJECT_DIR$" />
|
|
6
|
-
<vitest-options value="--run" />
|
|
7
|
-
<envs />
|
|
8
|
-
<scope-kind value="DIRECTORY" />
|
|
9
|
-
<test-directory value="$PROJECT_DIR$/test" />
|
|
10
|
-
<method v="2" />
|
|
11
|
-
</configuration>
|
|
12
|
-
</component>
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<component name="ProjectRunConfigurationManager">
|
|
2
|
-
<configuration default="false" name="Test character set" type="JavaScriptTestRunnerVitest">
|
|
3
|
-
<node-interpreter value="project" />
|
|
4
|
-
<vitest-package value="$PROJECT_DIR$/node_modules/vitest" />
|
|
5
|
-
<working-dir value="$PROJECT_DIR$" />
|
|
6
|
-
<vitest-options value="--run" />
|
|
7
|
-
<envs />
|
|
8
|
-
<scope-kind value="TEST_FILE" />
|
|
9
|
-
<test-file value="$PROJECT_DIR$/test/character_set.test.ts" />
|
|
10
|
-
<method v="2" />
|
|
11
|
-
</configuration>
|
|
12
|
-
</component>
|