@aidc-toolkit/utility 0.9.4 → 0.9.6-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 +1726 -0
- package/dist/index.d.cts +840 -0
- package/dist/index.d.ts +840 -0
- package/dist/index.js +1686 -0
- package/package.json +8 -8
- package/src/character_set.ts +34 -83
- package/src/index.ts +1 -0
- package/src/iterator_proxy.ts +177 -189
- package/src/transformer.ts +29 -103
- package/src/types.ts +46 -0
- package/test/character_set.test.ts +6 -7
- package/test/iterator_proxy.test.ts +34 -2
- package/test/record.test.ts +1 -1
- package/test/reg_exp.test.ts +1 -1
- package/test/sequencer.test.ts +5 -5
- package/test/transformer.test.ts +1 -1
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -32
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/workflows/npm-publish.yml +0 -38
- 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/build_dev.xml +0 -12
- package/.idea/runConfigurations/eslint.xml +0 -12
- package/.idea/utility.iml +0 -9
- package/.idea/vcs.xml +0 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aidc-toolkit/utility",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.6-beta",
|
|
4
4
|
"description": "Foundational utilities for AIDC Toolkit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,21 +19,21 @@
|
|
|
19
19
|
"url": "https://www.linkedin.com/in/kdean"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
|
-
"
|
|
22
|
+
"lint": "eslint .",
|
|
23
23
|
"build": "tsup src/index.ts --clean --format cjs,esm --dts",
|
|
24
24
|
"build-doc": "npm run build && tsc src/index.ts --outDir dist --target esnext --moduleResolution nodenext --module nodenext --emitDeclarationOnly --declaration --declarationMap",
|
|
25
25
|
"test": "vitest run"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@aidc-toolkit/dev": "^0.9.
|
|
29
|
-
"eslint": "^9.
|
|
28
|
+
"@aidc-toolkit/dev": "^0.9.6-beta",
|
|
29
|
+
"eslint": "^9.16.0",
|
|
30
30
|
"ts-node": "^10.9.2",
|
|
31
31
|
"tsup": "^8.3.5",
|
|
32
|
-
"typescript": "^5.
|
|
33
|
-
"vitest": "^2.1.
|
|
32
|
+
"typescript": "^5.7.2",
|
|
33
|
+
"vitest": "^2.1.7"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@aidc-toolkit/core": "^0.9.
|
|
37
|
-
"
|
|
36
|
+
"@aidc-toolkit/core": "^0.9.6-beta",
|
|
37
|
+
"@rollup/rollup-linux-x64-gnu": "^4.28.0"
|
|
38
38
|
}
|
|
39
39
|
}
|
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