@aidc-toolkit/utility 0.9.16-beta → 0.9.18-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.
Files changed (46) hide show
  1. package/dist/character-set.d.ts +24 -2
  2. package/dist/character-set.d.ts.map +1 -1
  3. package/dist/character-set.js +21 -0
  4. package/dist/character-set.js.map +1 -1
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/iterable-utility.d.ts +39 -0
  10. package/dist/iterable-utility.d.ts.map +1 -0
  11. package/dist/iterable-utility.js +35 -0
  12. package/dist/iterable-utility.js.map +1 -0
  13. package/dist/locale/en/locale-strings.d.ts +16 -17
  14. package/dist/locale/en/locale-strings.d.ts.map +1 -1
  15. package/dist/locale/en/locale-strings.js +16 -17
  16. package/dist/locale/en/locale-strings.js.map +1 -1
  17. package/dist/locale/fr/locale-strings.d.ts +16 -17
  18. package/dist/locale/fr/locale-strings.d.ts.map +1 -1
  19. package/dist/locale/fr/locale-strings.js +16 -17
  20. package/dist/locale/fr/locale-strings.js.map +1 -1
  21. package/dist/record.d.ts +3 -0
  22. package/dist/record.d.ts.map +1 -1
  23. package/dist/record.js +3 -0
  24. package/dist/record.js.map +1 -1
  25. package/dist/string.d.ts +3 -0
  26. package/dist/string.d.ts.map +1 -1
  27. package/dist/transformer.d.ts +4 -35
  28. package/dist/transformer.d.ts.map +1 -1
  29. package/dist/transformer.js +4 -31
  30. package/dist/transformer.js.map +1 -1
  31. package/package.json +5 -7
  32. package/src/character-set.ts +28 -2
  33. package/src/index.ts +1 -0
  34. package/src/iterable-utility.ts +55 -0
  35. package/src/locale/en/locale-strings.ts +16 -17
  36. package/src/locale/fr/locale-strings.ts +16 -17
  37. package/src/record.ts +3 -0
  38. package/src/string.ts +3 -0
  39. package/src/transformer.ts +10 -60
  40. package/test/character-set.test.ts +53 -28
  41. package/test/record.test.ts +1 -1
  42. package/test/reg-exp.test.ts +1 -1
  43. package/test/sequence.test.ts +3 -3
  44. package/test/transformer.test.ts +18 -10
  45. package/typedoc.json +1 -3
  46. package/utility.iml +9 -0
@@ -1,20 +1,27 @@
1
1
  import { I18NEnvironment } from "@aidc-toolkit/core";
2
2
  import { describe, expect, test } from "vitest";
3
3
  import {
4
- ALPHABETIC_CREATOR,
5
- ALPHANUMERIC_CREATOR,
6
- CharacterSetCreator,
4
+ ALPHABETIC_CREATOR, ALPHABETIC_VALIDATOR,
5
+ ALPHANUMERIC_CREATOR, ALPHANUMERIC_VALIDATOR,
6
+ CharacterSetCreator, type CharacterSetValidator,
7
7
  Exclusion,
8
- HEXADECIMAL_CREATOR,
8
+ HEXADECIMAL_CREATOR, HEXADECIMAL_VALIDATOR,
9
9
  i18nUtilityInit,
10
- NUMERIC_CREATOR,
10
+ NUMERIC_CREATOR, NUMERIC_VALIDATOR,
11
11
  Sequence
12
- } from "../src/index.js";
12
+ } from "../src";
13
13
 
14
14
  await i18nUtilityInit(I18NEnvironment.CLI);
15
15
 
16
- function testCharacterSetCreator(name: string, characterSetCreator: CharacterSetCreator, characterSetSize: number, length: number, excludeFirstZero: boolean, excludeAllNumeric: boolean): void {
16
+ // Type is used to ensure that testCharacterSet() is not called with creator twice.
17
+ type ValidatorNotCreator<T extends CharacterSetValidator> = T extends CharacterSetCreator ? never : T;
18
+
19
+ function testCharacterSet<T extends CharacterSetValidator>(name: string, characterSetCreator: CharacterSetCreator, characterSetValidator: ValidatorNotCreator<T>, characterSetSize: number, length: number, excludeFirstZero: boolean, excludeAllNumeric: boolean): void {
17
20
  describe(name, () => {
21
+ test("Validator is creator", () => {
22
+ expect(characterSetValidator).toBe(characterSetCreator);
23
+ });
24
+
18
25
  test("Character set", () => {
19
26
  characterSetCreator.characterSet.forEach((c, index) => {
20
27
  expect(c).not.toBeUndefined();
@@ -65,37 +72,40 @@ function testCharacterSetCreator(name: string, characterSetCreator: CharacterSet
65
72
  break;
66
73
  }
67
74
 
68
- const sequence = Iterator.from(characterSetCreator.create(length, new Sequence(0n, domain), exclusion));
75
+ const sequence = characterSetCreator.create(length, new Sequence(0n, domain), exclusion);
69
76
 
70
77
  let previousS = "";
71
78
 
72
- let sequenceCount = 0;
79
+ let index = 0;
73
80
 
74
- sequence.forEach((s, index) => {
81
+ for (const s of sequence) {
75
82
  expect(s > previousS).toBe(true);
76
83
  previousS = s;
77
84
 
78
85
  expect(s.length).toBe(length);
79
86
 
87
+ expect(() => {
88
+ characterSetValidator.validate(s);
89
+ }).not.toThrow(RangeError);
80
90
  expect(characterSetCreator.valueFor(s, exclusion)).toBe(BigInt(index));
81
91
 
82
- sequenceCount++;
83
- });
92
+ index++;
93
+ }
84
94
 
85
- expect(sequenceCount).toBe(domain);
95
+ expect(index).toBe(domain);
86
96
 
87
97
  expect(() => characterSetCreator.create(length, domain, exclusion)).toThrow(`Value ${domain} must be less than ${domain}`);
88
98
 
89
- const sparseSequence = Iterator.from(characterSetCreator.create(length, new Sequence(domain - 1, -domain), exclusion, 123456n));
99
+ const sparseSequence = characterSetCreator.create(length, new Sequence(domain - 1, -domain), exclusion, 123456n);
90
100
 
91
101
  let sequential = true;
92
102
  previousS = "~";
93
103
 
94
104
  const sequenceSet = new Set<string>();
95
105
 
96
- sequenceCount = 0;
106
+ index = 0;
97
107
 
98
- sparseSequence.forEach((s, index) => {
108
+ for (const s of sparseSequence) {
99
109
  sequential &&= s < previousS;
100
110
  previousS = s;
101
111
 
@@ -104,13 +114,16 @@ function testCharacterSetCreator(name: string, characterSetCreator: CharacterSet
104
114
  expect(sequenceSet.has(s)).toBe(false);
105
115
  sequenceSet.add(s);
106
116
 
117
+ expect(() => {
118
+ characterSetValidator.validate(s);
119
+ }).not.toThrow(RangeError);
107
120
  expect(characterSetCreator.valueFor(s, exclusion, 123456n)).toBe(BigInt(domain - index - 1));
108
121
 
109
- sequenceCount++;
110
- });
122
+ index++;
123
+ }
111
124
 
112
125
  expect(sequential).toBe(false);
113
- expect(sequenceCount).toBe(domain);
126
+ expect(index).toBe(domain);
114
127
 
115
128
  const randomValues = new Array<bigint>();
116
129
  const straightRandomValues = new Array<string>();
@@ -137,12 +150,18 @@ function testCharacterSetCreator(name: string, characterSetCreator: CharacterSet
137
150
  expect(() => characterSetCreator.create(41, 0)).toThrow("Length 41 must be less than or equal to 40");
138
151
  });
139
152
 
140
- test("Create sequence", () => {
153
+ test("Create sequence", {
154
+ // Test can take a moderate amount of time.
155
+ timeout: 10 * 1000
156
+ }, () => {
141
157
  testCreate(Exclusion.None);
142
158
  });
143
159
 
144
160
  if (excludeFirstZero) {
145
- test("Create sequence, exclude first zero", () => {
161
+ test("Create sequence, exclude first zero", {
162
+ // Test can take a moderate amount of time.
163
+ timeout: 10 * 1000
164
+ }, () => {
146
165
  testCreate(Exclusion.FirstZero);
147
166
 
148
167
  expect(() => characterSetCreator.valueFor("0000", Exclusion.FirstZero)).toThrow("Invalid character '0' at position 1");
@@ -151,7 +170,10 @@ function testCharacterSetCreator(name: string, characterSetCreator: CharacterSet
151
170
  }
152
171
 
153
172
  if (excludeAllNumeric) {
154
- test("Create sequence, exclude all numeric", () => {
173
+ test("Create sequence, exclude all numeric", {
174
+ // Test can take a moderate amount of time.
175
+ timeout: 10 * 1000
176
+ }, () => {
155
177
  testCreate(Exclusion.AllNumeric);
156
178
 
157
179
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- Nine is known to be present in the character set.
@@ -189,12 +211,15 @@ describe("Exclusion", () => {
189
211
  });
190
212
  });
191
213
 
192
- testCharacterSetCreator("Numeric", NUMERIC_CREATOR, 10, 4, true, false);
193
- testCharacterSetCreator("Hexadecimal", HEXADECIMAL_CREATOR, 16, 4, true, true);
194
- testCharacterSetCreator("Alphabetic", ALPHABETIC_CREATOR, 26, 3, false, false);
195
- testCharacterSetCreator("Alphanumeric", ALPHANUMERIC_CREATOR, 36, 3, true, true);
196
- testCharacterSetCreator("Middle numeric", new CharacterSetCreator([
214
+ testCharacterSet("Numeric", NUMERIC_CREATOR, NUMERIC_VALIDATOR, 10, 4, true, false);
215
+ testCharacterSet("Hexadecimal", HEXADECIMAL_CREATOR, HEXADECIMAL_VALIDATOR, 16, 4, true, true);
216
+ testCharacterSet("Alphabetic", ALPHABETIC_CREATOR, ALPHABETIC_VALIDATOR, 26, 3, false, false);
217
+ testCharacterSet("Alphanumeric", ALPHANUMERIC_CREATOR, ALPHANUMERIC_VALIDATOR, 36, 3, true, true);
218
+
219
+ const middleNumericCreator = new CharacterSetCreator([
197
220
  "(", ")",
198
221
  "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
199
222
  "<", ">"
200
- ], Exclusion.AllNumeric), 14, 4, false, true);
223
+ ], Exclusion.AllNumeric);
224
+
225
+ testCharacterSet("Middle numeric", middleNumericCreator, middleNumericCreator as CharacterSetValidator, 14, 4, false, true);
@@ -1,6 +1,6 @@
1
1
  import { I18NEnvironment } from "@aidc-toolkit/core";
2
2
  import { describe, expect, test } from "vitest";
3
- import { i18nUtilityInit, RecordValidator } from "../src/index.js";
3
+ import { i18nUtilityInit, RecordValidator } from "../src";
4
4
 
5
5
  await i18nUtilityInit(I18NEnvironment.CLI);
6
6
 
@@ -1,6 +1,6 @@
1
1
  import { I18NEnvironment } from "@aidc-toolkit/core";
2
2
  import { describe, expect, test } from "vitest";
3
- import { i18nUtilityInit, RegExpValidator } from "../src/index.js";
3
+ import { i18nUtilityInit, RegExpValidator } from "../src";
4
4
 
5
5
  await i18nUtilityInit(I18NEnvironment.CLI);
6
6
 
@@ -1,6 +1,6 @@
1
1
  import { I18NEnvironment } from "@aidc-toolkit/core";
2
2
  import { describe, expect, test } from "vitest";
3
- import { i18nUtilityInit, Sequence } from "../src/index.js";
3
+ import { i18nUtilityInit, Sequence } from "../src";
4
4
 
5
5
  await i18nUtilityInit(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 Iterator.from(sequence1)) {
32
+ for (const value of sequence1) {
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 Iterator.from(sequence2)) {
44
+ for (const value of sequence2) {
45
45
  expect(value).toBe(expectedValue);
46
46
 
47
47
  expectedValue--;
@@ -1,6 +1,6 @@
1
1
  import { I18NEnvironment } from "@aidc-toolkit/core";
2
- import { describe, expect, test } from "vitest";
3
- import { EncryptionTransformer, i18nUtilityInit, IdentityTransformer, Sequence, Transformer } from "../src/index.js";
2
+ import { afterEach, describe, expect, test } from "vitest";
3
+ import { EncryptionTransformer, i18nUtilityInit, IdentityTransformer, Sequence, Transformer } from "../src";
4
4
 
5
5
  await i18nUtilityInit(I18NEnvironment.CLI);
6
6
 
@@ -11,22 +11,24 @@ function testTransformer(domain: number, tweak?: number, callback?: (value: bigi
11
11
 
12
12
  const transformedValuesSet = new Set<bigint>();
13
13
 
14
- Iterator.from(transformer.forward(new Sequence(0n, domain))).forEach((transformedValue, index) => {
15
- const indexN = BigInt(index);
14
+ let index = 0n;
16
15
 
17
- if (sequential && transformedValue !== indexN) {
16
+ for (const transformedValue of transformer.forward(new Sequence(0n, domain))) {
17
+ if (sequential && transformedValue !== index) {
18
18
  sequential = false;
19
19
  }
20
20
 
21
21
  expect(transformedValuesSet.has(transformedValue)).toBe(false);
22
- expect(transformer.reverse(transformedValue)).toBe(indexN);
22
+ expect(transformer.reverse(transformedValue)).toBe(index);
23
23
 
24
24
  transformedValuesSet.add(transformedValue);
25
25
 
26
26
  if (callback !== undefined) {
27
- callback(indexN, transformedValue);
27
+ callback(index, transformedValue);
28
28
  }
29
- });
29
+
30
+ index++;
31
+ }
30
32
 
31
33
  expect(sequential).toBe(tweak === undefined);
32
34
 
@@ -50,6 +52,12 @@ function testTransformer(domain: number, tweak?: number, callback?: (value: bigi
50
52
  expect(() => transformer.forward(new Sequence(-1, -1))).toThrow("Minimum value -1 must be greater than or equal to 0");
51
53
  }
52
54
 
55
+ // TODO Remove when https://github.com/vitest-dev/vitest/discussions/6511 resolved.
56
+ afterEach(async () => {
57
+ // eslint-disable-next-line promise/avoid-new -- Patch.
58
+ await new Promise(resolve => setImmediate(resolve));
59
+ });
60
+
53
61
  describe("Identity", () => {
54
62
  test("Get", () => {
55
63
  const transformer = Transformer.get(1000);
@@ -57,7 +65,7 @@ describe("Identity", () => {
57
65
  expect(transformer instanceof IdentityTransformer).toBe(true);
58
66
  expect(Transformer.get(1000n)).toBe(transformer);
59
67
 
60
- expect(transformer.domain).toBe(BigInt(1000n));
68
+ expect(transformer.domain).toBe(1000n);
61
69
  });
62
70
 
63
71
  test("Reversible", () => {
@@ -82,7 +90,7 @@ describe("Encryption", () => {
82
90
  expect(transformer instanceof EncryptionTransformer).toBe(true);
83
91
  expect(Transformer.get(1000n, 1234n)).toBe(transformer);
84
92
 
85
- expect(transformer.domain).toBe(BigInt(1000n));
93
+ expect(transformer.domain).toBe(1000n);
86
94
 
87
95
  const transformer0 = Transformer.get(1000, 0);
88
96
 
package/typedoc.json CHANGED
@@ -4,8 +4,6 @@
4
4
  "@aidc-toolkit/dev/typedoc.json"
5
5
  ],
6
6
  "name": "Utility",
7
- "entryPoints": [
8
- "src/index.ts"
9
- ],
7
+ "tsconfig": "node_modules/@aidc-toolkit/dev/tsconfig-build-dev.json",
10
8
  "gitRevision": "main"
11
9
  }
package/utility.iml ADDED
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$" />
6
+ <orderEntry type="inheritedJdk" />
7
+ <orderEntry type="sourceFolder" forTests="false" />
8
+ </component>
9
+ </module>