@nestia/e2e 7.0.0 → 7.0.1
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/README.md +2 -1
- package/lib/ArrayUtil.d.ts +227 -2
- package/lib/ArrayUtil.js +227 -30
- package/lib/ArrayUtil.js.map +1 -1
- package/lib/GaffComparator.d.ts +229 -14
- package/lib/GaffComparator.js +229 -14
- package/lib/GaffComparator.js.map +1 -1
- package/lib/RandomGenerator.d.ts +332 -35
- package/lib/RandomGenerator.js +337 -50
- package/lib/RandomGenerator.js.map +1 -1
- package/lib/TestValidator.d.ts +301 -34
- package/lib/TestValidator.js +222 -57
- package/lib/TestValidator.js.map +1 -1
- package/package.json +1 -1
- package/src/ArrayUtil.ts +227 -3
- package/src/GaffComparator.ts +230 -14
- package/src/RandomGenerator.ts +339 -50
- package/src/TestValidator.ts +304 -57
package/README.md
CHANGED
|
@@ -22,7 +22,8 @@ Nestia is a set of helper libraries for NestJS, supporting below features:
|
|
|
22
22
|
- `@nestia/e2e`: Test program utilizing e2e test functions
|
|
23
23
|
- `@nestia/benchmark`: Benchmark program using e2e test functions
|
|
24
24
|
- `@nestia/editor`: Swagger-UI with Online TypeScript Editor
|
|
25
|
-
- `@agentica
|
|
25
|
+
- [`@agentica`](https://github.com/wrtnlabs/agentica): Agentic AI library specialized in LLM function calling
|
|
26
|
+
- [`@autobe`](https://github.com/wrtnlabs/autobe): Vibe coding agent generating NestJS application
|
|
26
27
|
- `nestia`: Just CLI (command line interface) tool
|
|
27
28
|
|
|
28
29
|
> [!NOTE]
|
package/lib/ArrayUtil.d.ts
CHANGED
|
@@ -1,15 +1,240 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* A namespace providing utility functions for array manipulation.
|
|
3
|
+
*
|
|
4
|
+
* This namespace contains utility functions for array operations including
|
|
5
|
+
* asynchronous processing, filtering, mapping, and repetition tasks implemented
|
|
6
|
+
* in functional programming style. All functions are implemented using currying
|
|
7
|
+
* to enhance reusability and composability.
|
|
3
8
|
*
|
|
4
9
|
* @author Jeongho Nam - https://github.com/samchon
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Asynchronous filtering example
|
|
13
|
+
* const numbers = [1, 2, 3, 4, 5];
|
|
14
|
+
* const evenNumbers = await ArrayUtil.asyncFilter(numbers)(
|
|
15
|
+
* async (num) => num % 2 === 0
|
|
16
|
+
* );
|
|
17
|
+
* console.log(evenNumbers); // [2, 4]
|
|
18
|
+
* ```;
|
|
5
19
|
*/
|
|
6
20
|
export declare namespace ArrayUtil {
|
|
21
|
+
/**
|
|
22
|
+
* Filters an array by applying an asynchronous predicate function to each
|
|
23
|
+
* element.
|
|
24
|
+
*
|
|
25
|
+
* This function is implemented in curried form, first taking an array and
|
|
26
|
+
* then a predicate function. Elements are processed sequentially, ensuring
|
|
27
|
+
* order is maintained.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const users = [
|
|
32
|
+
* { id: 1, name: 'Alice', active: true },
|
|
33
|
+
* { id: 2, name: 'Bob', active: false },
|
|
34
|
+
* { id: 3, name: 'Charlie', active: true }
|
|
35
|
+
* ];
|
|
36
|
+
*
|
|
37
|
+
* const activeUsers = await ArrayUtil.asyncFilter(users)(
|
|
38
|
+
* async (user) => {
|
|
39
|
+
* // Async validation logic (e.g., API call)
|
|
40
|
+
* await new Promise(resolve => setTimeout(resolve, 100));
|
|
41
|
+
* return user.active;
|
|
42
|
+
* }
|
|
43
|
+
* );
|
|
44
|
+
* console.log(activeUsers); // [{ id: 1, name: 'Alice', active: true }, { id: 3, name: 'Charlie', active: true }]
|
|
45
|
+
* ```;
|
|
46
|
+
*
|
|
47
|
+
* @template Input - The type of elements in the input array
|
|
48
|
+
* @param elements - The readonly array to filter
|
|
49
|
+
* @returns A function that takes a predicate and returns a Promise resolving
|
|
50
|
+
* to the filtered array
|
|
51
|
+
*/
|
|
7
52
|
const asyncFilter: <Input>(elements: readonly Input[]) => (pred: (elem: Input, index: number, array: readonly Input[]) => Promise<boolean>) => Promise<Input[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Executes an asynchronous function for each element in an array
|
|
55
|
+
* sequentially.
|
|
56
|
+
*
|
|
57
|
+
* Unlike JavaScript's native forEach, this function processes asynchronous
|
|
58
|
+
* functions sequentially and waits for all operations to complete. It
|
|
59
|
+
* performs sequential processing rather than parallel processing, making it
|
|
60
|
+
* suitable for operations where order matters.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const urls = ['url1', 'url2', 'url3'];
|
|
65
|
+
*
|
|
66
|
+
* await ArrayUtil.asyncForEach(urls)(async (url, index) => {
|
|
67
|
+
* console.log(`Processing ${index}: ${url}`);
|
|
68
|
+
* const data = await fetch(url);
|
|
69
|
+
* await processData(data);
|
|
70
|
+
* console.log(`Completed ${index}: ${url}`);
|
|
71
|
+
* });
|
|
72
|
+
* console.log('All URLs processed sequentially');
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @template Input - The type of elements in the input array
|
|
76
|
+
* @param elements - The readonly array to process
|
|
77
|
+
* @returns A function that takes an async closure and returns a Promise<void>
|
|
78
|
+
*/
|
|
8
79
|
const asyncForEach: <Input>(elements: readonly Input[]) => (closure: (elem: Input, index: number, array: readonly Input[]) => Promise<any>) => Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Transforms each element of an array using an asynchronous function to
|
|
82
|
+
* create a new array.
|
|
83
|
+
*
|
|
84
|
+
* Similar to JavaScript's native map but processes asynchronous functions
|
|
85
|
+
* sequentially. Each element's transformation is completed before proceeding
|
|
86
|
+
* to the next element, ensuring order is maintained.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const userIds = [1, 2, 3, 4, 5];
|
|
91
|
+
*
|
|
92
|
+
* const userDetails = await ArrayUtil.asyncMap(userIds)(
|
|
93
|
+
* async (id, index) => {
|
|
94
|
+
* console.log(`Fetching user ${id} (${index + 1}/${userIds.length})`);
|
|
95
|
+
* const response = await fetch(`/api/users/${id}`);
|
|
96
|
+
* return await response.json();
|
|
97
|
+
* }
|
|
98
|
+
* );
|
|
99
|
+
* console.log('All users fetched:', userDetails);
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @template Input - The type of elements in the input array
|
|
103
|
+
* @template Output - The type of elements in the output array
|
|
104
|
+
* @param elements - The readonly array to transform
|
|
105
|
+
* @returns A function that takes a transformation function and returns a
|
|
106
|
+
* Promise resolving to the transformed array
|
|
107
|
+
*/
|
|
9
108
|
const asyncMap: <Input>(elements: readonly Input[]) => <Output>(closure: (elem: Input, index: number, array: readonly Input[]) => Promise<Output>) => Promise<Output[]>;
|
|
109
|
+
/**
|
|
110
|
+
* Executes an asynchronous function a specified number of times sequentially.
|
|
111
|
+
*
|
|
112
|
+
* Executes the function with indices from 0 to count-1 incrementally. Each
|
|
113
|
+
* execution is performed sequentially, and all results are collected into an
|
|
114
|
+
* array.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* // Generate random data 5 times
|
|
119
|
+
* const randomData = await ArrayUtil.asyncRepeat(5)(async (index) => {
|
|
120
|
+
* await new Promise(resolve => setTimeout(resolve, 100)); // Wait 0.1 seconds
|
|
121
|
+
* return {
|
|
122
|
+
* id: index,
|
|
123
|
+
* value: Math.random(),
|
|
124
|
+
* timestamp: new Date().toISOString()
|
|
125
|
+
* };
|
|
126
|
+
* });
|
|
127
|
+
* console.log('Generated data:', randomData);
|
|
128
|
+
* ```;
|
|
129
|
+
*
|
|
130
|
+
* @param count - The number of times to repeat (non-negative integer)
|
|
131
|
+
* @returns A function that takes an async closure and returns a Promise
|
|
132
|
+
* resolving to an array of results
|
|
133
|
+
*/
|
|
10
134
|
const asyncRepeat: (count: number) => <T>(closure: (index: number) => Promise<T>) => Promise<T[]>;
|
|
135
|
+
/**
|
|
136
|
+
* Checks if at least one element in the array satisfies the given condition.
|
|
137
|
+
*
|
|
138
|
+
* Similar to JavaScript's native some() method but implemented in curried
|
|
139
|
+
* form for better compatibility with functional programming style. Returns
|
|
140
|
+
* true immediately when the first element satisfying the condition is found.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* const numbers = [1, 3, 5, 7, 8, 9];
|
|
145
|
+
* const products = [
|
|
146
|
+
* { name: 'Apple', price: 100, inStock: true },
|
|
147
|
+
* { name: 'Banana', price: 50, inStock: false },
|
|
148
|
+
* { name: 'Orange', price: 80, inStock: true }
|
|
149
|
+
* ];
|
|
150
|
+
*
|
|
151
|
+
* const hasEvenNumber = ArrayUtil.has(numbers)(num => num % 2 === 0);
|
|
152
|
+
* console.log(hasEvenNumber); // true (8 exists)
|
|
153
|
+
*
|
|
154
|
+
* const hasExpensiveItem = ArrayUtil.has(products)(product => product.price > 90);
|
|
155
|
+
* console.log(hasExpensiveItem); // true (Apple costs 100)
|
|
156
|
+
*
|
|
157
|
+
* const hasOutOfStock = ArrayUtil.has(products)(product => !product.inStock);
|
|
158
|
+
* console.log(hasOutOfStock); // true (Banana is out of stock)
|
|
159
|
+
* ```;
|
|
160
|
+
*
|
|
161
|
+
* @template T - The type of elements in the array
|
|
162
|
+
* @param elements - The readonly array to check
|
|
163
|
+
* @returns A function that takes a predicate and returns a boolean
|
|
164
|
+
*/
|
|
11
165
|
const has: <T>(elements: readonly T[]) => (pred: (elem: T) => boolean) => boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Executes a function a specified number of times and collects the results
|
|
168
|
+
* into an array.
|
|
169
|
+
*
|
|
170
|
+
* A synchronous repetition function that executes the given function for each
|
|
171
|
+
* index (from 0 to count-1) and collects the results into an array.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* // Generate an array of squares from 1 to 5
|
|
176
|
+
* const squares = ArrayUtil.repeat(5)(index => (index + 1) ** 2);
|
|
177
|
+
* console.log(squares); // [1, 4, 9, 16, 25]
|
|
178
|
+
*
|
|
179
|
+
* // Generate an array of default user objects
|
|
180
|
+
* const users = ArrayUtil.repeat(3)(index => ({
|
|
181
|
+
* id: index + 1,
|
|
182
|
+
* name: `User${index + 1}`,
|
|
183
|
+
* email: `user${index + 1}@example.com`
|
|
184
|
+
* }));
|
|
185
|
+
* console.log(users);
|
|
186
|
+
* // [
|
|
187
|
+
* // { id: 1, name: 'User1', email: 'user1@example.com' },
|
|
188
|
+
* // { id: 2, name: 'User2', email: 'user2@example.com' },
|
|
189
|
+
* // { id: 3, name: 'User3', email: 'user3@example.com' }
|
|
190
|
+
* // ]
|
|
191
|
+
* ```
|
|
192
|
+
*
|
|
193
|
+
* @param count - The number of times to repeat (non-negative integer)
|
|
194
|
+
* @returns A function that takes a closure and returns an array of results
|
|
195
|
+
*/
|
|
12
196
|
const repeat: (count: number) => <T>(closure: (index: number) => T) => T[];
|
|
13
|
-
|
|
197
|
+
/**
|
|
198
|
+
* Generates all possible subsets of a given array.
|
|
199
|
+
*
|
|
200
|
+
* Implements the mathematical concept of power set, generating 2^n subsets
|
|
201
|
+
* from an array of n elements. Uses depth-first search (DFS) algorithm to
|
|
202
|
+
* calculate all possible combinations of including or excluding each
|
|
203
|
+
* element.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* const numbers = [1, 2, 3];
|
|
208
|
+
* const allSubsets = ArrayUtil.subsets(numbers);
|
|
209
|
+
* console.log(allSubsets);
|
|
210
|
+
* // [
|
|
211
|
+
* // [], // empty set
|
|
212
|
+
* // [3], // {3}
|
|
213
|
+
* // [2], // {2}
|
|
214
|
+
* // [2, 3], // {2, 3}
|
|
215
|
+
* // [1], // {1}
|
|
216
|
+
* // [1, 3], // {1, 3}
|
|
217
|
+
* // [1, 2], // {1, 2}
|
|
218
|
+
* // [1, 2, 3] // {1, 2, 3}
|
|
219
|
+
* // ]
|
|
220
|
+
*
|
|
221
|
+
* const colors = ['red', 'blue'];
|
|
222
|
+
* const colorSubsets = ArrayUtil.subsets(colors);
|
|
223
|
+
* console.log(colorSubsets);
|
|
224
|
+
* // [
|
|
225
|
+
* // [],
|
|
226
|
+
* // ['blue'],
|
|
227
|
+
* // ['red'],
|
|
228
|
+
* // ['red', 'blue']
|
|
229
|
+
* // ]
|
|
230
|
+
*
|
|
231
|
+
* // Warning: Result size grows exponentially with array size
|
|
232
|
+
* // Example: 10 elements → 1,024 subsets, 20 elements → 1,048,576 subsets
|
|
233
|
+
* ```;
|
|
234
|
+
*
|
|
235
|
+
* @template T - The type of elements in the array
|
|
236
|
+
* @param array - The array to generate subsets from
|
|
237
|
+
* @returns An array containing all possible subsets
|
|
238
|
+
*/
|
|
14
239
|
const subsets: <T>(array: T[]) => T[][];
|
|
15
240
|
}
|
package/lib/ArrayUtil.js
CHANGED
|
@@ -46,41 +46,61 @@ var __values = (this && this.__values) || function(o) {
|
|
|
46
46
|
};
|
|
47
47
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
48
|
};
|
|
49
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
50
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
51
|
-
if (!m) return o;
|
|
52
|
-
var i = m.call(o), r, ar = [], e;
|
|
53
|
-
try {
|
|
54
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
55
|
-
}
|
|
56
|
-
catch (error) { e = { error: error }; }
|
|
57
|
-
finally {
|
|
58
|
-
try {
|
|
59
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
60
|
-
}
|
|
61
|
-
finally { if (e) throw e.error; }
|
|
62
|
-
}
|
|
63
|
-
return ar;
|
|
64
|
-
};
|
|
65
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
66
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
67
|
-
if (ar || !(i in from)) {
|
|
68
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
69
|
-
ar[i] = from[i];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
73
|
-
};
|
|
74
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
75
50
|
exports.ArrayUtil = void 0;
|
|
76
51
|
/**
|
|
77
|
-
*
|
|
52
|
+
* A namespace providing utility functions for array manipulation.
|
|
53
|
+
*
|
|
54
|
+
* This namespace contains utility functions for array operations including
|
|
55
|
+
* asynchronous processing, filtering, mapping, and repetition tasks implemented
|
|
56
|
+
* in functional programming style. All functions are implemented using currying
|
|
57
|
+
* to enhance reusability and composability.
|
|
78
58
|
*
|
|
79
59
|
* @author Jeongho Nam - https://github.com/samchon
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* // Asynchronous filtering example
|
|
63
|
+
* const numbers = [1, 2, 3, 4, 5];
|
|
64
|
+
* const evenNumbers = await ArrayUtil.asyncFilter(numbers)(
|
|
65
|
+
* async (num) => num % 2 === 0
|
|
66
|
+
* );
|
|
67
|
+
* console.log(evenNumbers); // [2, 4]
|
|
68
|
+
* ```;
|
|
80
69
|
*/
|
|
81
70
|
var ArrayUtil;
|
|
82
71
|
(function (ArrayUtil) {
|
|
83
72
|
var _this = this;
|
|
73
|
+
/**
|
|
74
|
+
* Filters an array by applying an asynchronous predicate function to each
|
|
75
|
+
* element.
|
|
76
|
+
*
|
|
77
|
+
* This function is implemented in curried form, first taking an array and
|
|
78
|
+
* then a predicate function. Elements are processed sequentially, ensuring
|
|
79
|
+
* order is maintained.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const users = [
|
|
84
|
+
* { id: 1, name: 'Alice', active: true },
|
|
85
|
+
* { id: 2, name: 'Bob', active: false },
|
|
86
|
+
* { id: 3, name: 'Charlie', active: true }
|
|
87
|
+
* ];
|
|
88
|
+
*
|
|
89
|
+
* const activeUsers = await ArrayUtil.asyncFilter(users)(
|
|
90
|
+
* async (user) => {
|
|
91
|
+
* // Async validation logic (e.g., API call)
|
|
92
|
+
* await new Promise(resolve => setTimeout(resolve, 100));
|
|
93
|
+
* return user.active;
|
|
94
|
+
* }
|
|
95
|
+
* );
|
|
96
|
+
* console.log(activeUsers); // [{ id: 1, name: 'Alice', active: true }, { id: 3, name: 'Charlie', active: true }]
|
|
97
|
+
* ```;
|
|
98
|
+
*
|
|
99
|
+
* @template Input - The type of elements in the input array
|
|
100
|
+
* @param elements - The readonly array to filter
|
|
101
|
+
* @returns A function that takes a predicate and returns a Promise resolving
|
|
102
|
+
* to the filtered array
|
|
103
|
+
*/
|
|
84
104
|
ArrayUtil.asyncFilter = function (elements) {
|
|
85
105
|
return function (pred) { return __awaiter(_this, void 0, void 0, function () {
|
|
86
106
|
var ret;
|
|
@@ -109,6 +129,32 @@ var ArrayUtil;
|
|
|
109
129
|
});
|
|
110
130
|
}); };
|
|
111
131
|
};
|
|
132
|
+
/**
|
|
133
|
+
* Executes an asynchronous function for each element in an array
|
|
134
|
+
* sequentially.
|
|
135
|
+
*
|
|
136
|
+
* Unlike JavaScript's native forEach, this function processes asynchronous
|
|
137
|
+
* functions sequentially and waits for all operations to complete. It
|
|
138
|
+
* performs sequential processing rather than parallel processing, making it
|
|
139
|
+
* suitable for operations where order matters.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* const urls = ['url1', 'url2', 'url3'];
|
|
144
|
+
*
|
|
145
|
+
* await ArrayUtil.asyncForEach(urls)(async (url, index) => {
|
|
146
|
+
* console.log(`Processing ${index}: ${url}`);
|
|
147
|
+
* const data = await fetch(url);
|
|
148
|
+
* await processData(data);
|
|
149
|
+
* console.log(`Completed ${index}: ${url}`);
|
|
150
|
+
* });
|
|
151
|
+
* console.log('All URLs processed sequentially');
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @template Input - The type of elements in the input array
|
|
155
|
+
* @param elements - The readonly array to process
|
|
156
|
+
* @returns A function that takes an async closure and returns a Promise<void>
|
|
157
|
+
*/
|
|
112
158
|
ArrayUtil.asyncForEach = function (elements) {
|
|
113
159
|
return function (closure) { return __awaiter(_this, void 0, void 0, function () {
|
|
114
160
|
return __generator(this, function (_a) {
|
|
@@ -123,6 +169,34 @@ var ArrayUtil;
|
|
|
123
169
|
});
|
|
124
170
|
}); };
|
|
125
171
|
};
|
|
172
|
+
/**
|
|
173
|
+
* Transforms each element of an array using an asynchronous function to
|
|
174
|
+
* create a new array.
|
|
175
|
+
*
|
|
176
|
+
* Similar to JavaScript's native map but processes asynchronous functions
|
|
177
|
+
* sequentially. Each element's transformation is completed before proceeding
|
|
178
|
+
* to the next element, ensuring order is maintained.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const userIds = [1, 2, 3, 4, 5];
|
|
183
|
+
*
|
|
184
|
+
* const userDetails = await ArrayUtil.asyncMap(userIds)(
|
|
185
|
+
* async (id, index) => {
|
|
186
|
+
* console.log(`Fetching user ${id} (${index + 1}/${userIds.length})`);
|
|
187
|
+
* const response = await fetch(`/api/users/${id}`);
|
|
188
|
+
* return await response.json();
|
|
189
|
+
* }
|
|
190
|
+
* );
|
|
191
|
+
* console.log('All users fetched:', userDetails);
|
|
192
|
+
* ```
|
|
193
|
+
*
|
|
194
|
+
* @template Input - The type of elements in the input array
|
|
195
|
+
* @template Output - The type of elements in the output array
|
|
196
|
+
* @param elements - The readonly array to transform
|
|
197
|
+
* @returns A function that takes a transformation function and returns a
|
|
198
|
+
* Promise resolving to the transformed array
|
|
199
|
+
*/
|
|
126
200
|
ArrayUtil.asyncMap = function (elements) {
|
|
127
201
|
return function (closure) { return __awaiter(_this, void 0, void 0, function () {
|
|
128
202
|
var ret;
|
|
@@ -150,6 +224,31 @@ var ArrayUtil;
|
|
|
150
224
|
});
|
|
151
225
|
}); };
|
|
152
226
|
};
|
|
227
|
+
/**
|
|
228
|
+
* Executes an asynchronous function a specified number of times sequentially.
|
|
229
|
+
*
|
|
230
|
+
* Executes the function with indices from 0 to count-1 incrementally. Each
|
|
231
|
+
* execution is performed sequentially, and all results are collected into an
|
|
232
|
+
* array.
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```typescript
|
|
236
|
+
* // Generate random data 5 times
|
|
237
|
+
* const randomData = await ArrayUtil.asyncRepeat(5)(async (index) => {
|
|
238
|
+
* await new Promise(resolve => setTimeout(resolve, 100)); // Wait 0.1 seconds
|
|
239
|
+
* return {
|
|
240
|
+
* id: index,
|
|
241
|
+
* value: Math.random(),
|
|
242
|
+
* timestamp: new Date().toISOString()
|
|
243
|
+
* };
|
|
244
|
+
* });
|
|
245
|
+
* console.log('Generated data:', randomData);
|
|
246
|
+
* ```;
|
|
247
|
+
*
|
|
248
|
+
* @param count - The number of times to repeat (non-negative integer)
|
|
249
|
+
* @returns A function that takes an async closure and returns a Promise
|
|
250
|
+
* resolving to an array of results
|
|
251
|
+
*/
|
|
153
252
|
ArrayUtil.asyncRepeat = function (count) {
|
|
154
253
|
return function (closure) { return __awaiter(_this, void 0, void 0, function () {
|
|
155
254
|
var indexes, output, indexes_1, indexes_1_1, index, _a, _b, e_1_1;
|
|
@@ -193,20 +292,118 @@ var ArrayUtil;
|
|
|
193
292
|
});
|
|
194
293
|
}); };
|
|
195
294
|
};
|
|
295
|
+
/**
|
|
296
|
+
* Checks if at least one element in the array satisfies the given condition.
|
|
297
|
+
*
|
|
298
|
+
* Similar to JavaScript's native some() method but implemented in curried
|
|
299
|
+
* form for better compatibility with functional programming style. Returns
|
|
300
|
+
* true immediately when the first element satisfying the condition is found.
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* ```typescript
|
|
304
|
+
* const numbers = [1, 3, 5, 7, 8, 9];
|
|
305
|
+
* const products = [
|
|
306
|
+
* { name: 'Apple', price: 100, inStock: true },
|
|
307
|
+
* { name: 'Banana', price: 50, inStock: false },
|
|
308
|
+
* { name: 'Orange', price: 80, inStock: true }
|
|
309
|
+
* ];
|
|
310
|
+
*
|
|
311
|
+
* const hasEvenNumber = ArrayUtil.has(numbers)(num => num % 2 === 0);
|
|
312
|
+
* console.log(hasEvenNumber); // true (8 exists)
|
|
313
|
+
*
|
|
314
|
+
* const hasExpensiveItem = ArrayUtil.has(products)(product => product.price > 90);
|
|
315
|
+
* console.log(hasExpensiveItem); // true (Apple costs 100)
|
|
316
|
+
*
|
|
317
|
+
* const hasOutOfStock = ArrayUtil.has(products)(product => !product.inStock);
|
|
318
|
+
* console.log(hasOutOfStock); // true (Banana is out of stock)
|
|
319
|
+
* ```;
|
|
320
|
+
*
|
|
321
|
+
* @template T - The type of elements in the array
|
|
322
|
+
* @param elements - The readonly array to check
|
|
323
|
+
* @returns A function that takes a predicate and returns a boolean
|
|
324
|
+
*/
|
|
196
325
|
ArrayUtil.has = function (elements) {
|
|
197
326
|
return function (pred) {
|
|
198
327
|
return elements.find(pred) !== undefined;
|
|
199
328
|
};
|
|
200
329
|
};
|
|
330
|
+
/**
|
|
331
|
+
* Executes a function a specified number of times and collects the results
|
|
332
|
+
* into an array.
|
|
333
|
+
*
|
|
334
|
+
* A synchronous repetition function that executes the given function for each
|
|
335
|
+
* index (from 0 to count-1) and collects the results into an array.
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* ```typescript
|
|
339
|
+
* // Generate an array of squares from 1 to 5
|
|
340
|
+
* const squares = ArrayUtil.repeat(5)(index => (index + 1) ** 2);
|
|
341
|
+
* console.log(squares); // [1, 4, 9, 16, 25]
|
|
342
|
+
*
|
|
343
|
+
* // Generate an array of default user objects
|
|
344
|
+
* const users = ArrayUtil.repeat(3)(index => ({
|
|
345
|
+
* id: index + 1,
|
|
346
|
+
* name: `User${index + 1}`,
|
|
347
|
+
* email: `user${index + 1}@example.com`
|
|
348
|
+
* }));
|
|
349
|
+
* console.log(users);
|
|
350
|
+
* // [
|
|
351
|
+
* // { id: 1, name: 'User1', email: 'user1@example.com' },
|
|
352
|
+
* // { id: 2, name: 'User2', email: 'user2@example.com' },
|
|
353
|
+
* // { id: 3, name: 'User3', email: 'user3@example.com' }
|
|
354
|
+
* // ]
|
|
355
|
+
* ```
|
|
356
|
+
*
|
|
357
|
+
* @param count - The number of times to repeat (non-negative integer)
|
|
358
|
+
* @returns A function that takes a closure and returns an array of results
|
|
359
|
+
*/
|
|
201
360
|
ArrayUtil.repeat = function (count) {
|
|
202
361
|
return function (closure) {
|
|
203
362
|
return new Array(count).fill("").map(function (_, index) { return closure(index); });
|
|
204
363
|
};
|
|
205
364
|
};
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
365
|
+
/**
|
|
366
|
+
* Generates all possible subsets of a given array.
|
|
367
|
+
*
|
|
368
|
+
* Implements the mathematical concept of power set, generating 2^n subsets
|
|
369
|
+
* from an array of n elements. Uses depth-first search (DFS) algorithm to
|
|
370
|
+
* calculate all possible combinations of including or excluding each
|
|
371
|
+
* element.
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* ```typescript
|
|
375
|
+
* const numbers = [1, 2, 3];
|
|
376
|
+
* const allSubsets = ArrayUtil.subsets(numbers);
|
|
377
|
+
* console.log(allSubsets);
|
|
378
|
+
* // [
|
|
379
|
+
* // [], // empty set
|
|
380
|
+
* // [3], // {3}
|
|
381
|
+
* // [2], // {2}
|
|
382
|
+
* // [2, 3], // {2, 3}
|
|
383
|
+
* // [1], // {1}
|
|
384
|
+
* // [1, 3], // {1, 3}
|
|
385
|
+
* // [1, 2], // {1, 2}
|
|
386
|
+
* // [1, 2, 3] // {1, 2, 3}
|
|
387
|
+
* // ]
|
|
388
|
+
*
|
|
389
|
+
* const colors = ['red', 'blue'];
|
|
390
|
+
* const colorSubsets = ArrayUtil.subsets(colors);
|
|
391
|
+
* console.log(colorSubsets);
|
|
392
|
+
* // [
|
|
393
|
+
* // [],
|
|
394
|
+
* // ['blue'],
|
|
395
|
+
* // ['red'],
|
|
396
|
+
* // ['red', 'blue']
|
|
397
|
+
* // ]
|
|
398
|
+
*
|
|
399
|
+
* // Warning: Result size grows exponentially with array size
|
|
400
|
+
* // Example: 10 elements → 1,024 subsets, 20 elements → 1,048,576 subsets
|
|
401
|
+
* ```;
|
|
402
|
+
*
|
|
403
|
+
* @template T - The type of elements in the array
|
|
404
|
+
* @param array - The array to generate subsets from
|
|
405
|
+
* @returns An array containing all possible subsets
|
|
406
|
+
*/
|
|
210
407
|
ArrayUtil.subsets = function (array) {
|
|
211
408
|
var check = new Array(array.length).fill(false);
|
|
212
409
|
var output = [];
|
package/lib/ArrayUtil.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArrayUtil.js","sourceRoot":"","sources":["../src/ArrayUtil.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ArrayUtil.js","sourceRoot":"","sources":["../src/ArrayUtil.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,IAAiB,SAAS,CA8SzB;AA9SD,WAAiB,SAAS;;IACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACU,qBAAW,GACtB,UAAQ,QAA0B;QAClC,OAAA,UACE,IAIqB;;;;;;wBAEf,GAAG,GAAY,EAAE,CAAC;wBACxB,qBAAM,UAAA,YAAY,CAAC,QAAQ,CAAC,CAAC,UAAO,IAAI,EAAE,KAAK,EAAE,KAAK;;;;gDAC9B,qBAAM,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,EAAA;;4CAA9C,IAAI,GAAY,SAA8B;4CACpD,IAAI,IAAI,KAAK,IAAI;gDAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;;;iCACnC,CAAC,EAAA;;wBAHF,S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