@nestia/e2e 7.0.0-dev.20250608 → 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/LICENSE +21 -21
- package/README.md +93 -92
- 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 +322 -98
- package/src/DynamicExecutor.ts +296 -296
- package/src/GaffComparator.ts +280 -64
- package/src/RandomGenerator.ts +451 -162
- package/src/TestValidator.ts +594 -347
- package/src/index.ts +4 -4
- package/src/internal/json_equal_to.ts +35 -35
- package/src/module.ts +5 -5
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Jeongho Nam
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Jeongho Nam
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,92 +1,93 @@
|
|
|
1
|
-
# Nestia
|
|
2
|
-

|
|
3
|
-
|
|
4
|
-
[](https://github.com/samchon/nestia/blob/master/LICENSE)
|
|
5
|
-
[](https://www.npmjs.com/package/@nestia/fetcher)
|
|
6
|
-
[](https://www.npmjs.com/package/@nestia/fetcher)
|
|
7
|
-
[](https://github.com/samchon/nestia/actions?query=workflow%3Abuild)
|
|
8
|
-
[](https://nestia.io/docs/)
|
|
9
|
-
[](https://gurubase.io/g/nestia)
|
|
10
|
-
[](https://discord.gg/E94XhzrUCZ)
|
|
11
|
-
|
|
12
|
-
Nestia is a set of helper libraries for NestJS, supporting below features:
|
|
13
|
-
|
|
14
|
-
- `@nestia/core`:
|
|
15
|
-
- Super-fast/easy decorators
|
|
16
|
-
- Advanced WebSocket routes
|
|
17
|
-
- `@nestia/sdk`:
|
|
18
|
-
- Swagger generator, more evolved than ever
|
|
19
|
-
- SDK library generator for clients
|
|
20
|
-
- Mockup Simulator for client applications
|
|
21
|
-
- Automatic E2E test functions generator
|
|
22
|
-
- `@nestia/e2e`: Test program utilizing e2e test functions
|
|
23
|
-
- `@nestia/benchmark`: Benchmark program using e2e test functions
|
|
24
|
-
- `@nestia/editor`: Swagger-UI with Online TypeScript Editor
|
|
25
|
-
- `@agentica
|
|
26
|
-
- `
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
>
|
|
30
|
-
>
|
|
31
|
-
> -
|
|
32
|
-
>
|
|
33
|
-
> -
|
|
34
|
-
>
|
|
35
|
-
>
|
|
36
|
-
> -
|
|
37
|
-
>
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
- [
|
|
62
|
-
- [
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
- [`@
|
|
68
|
-
- [
|
|
69
|
-
- [
|
|
70
|
-
- [`@
|
|
71
|
-
- [`@
|
|
72
|
-
- [`@
|
|
73
|
-
- [`@
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
- [
|
|
77
|
-
- [
|
|
78
|
-
- [
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
- [
|
|
82
|
-
- [
|
|
83
|
-
- [
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
- [
|
|
87
|
-
- [
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
- [
|
|
92
|
-
- [⇲
|
|
1
|
+
# Nestia
|
|
2
|
+

|
|
3
|
+
|
|
4
|
+
[](https://github.com/samchon/nestia/blob/master/LICENSE)
|
|
5
|
+
[](https://www.npmjs.com/package/@nestia/fetcher)
|
|
6
|
+
[](https://www.npmjs.com/package/@nestia/fetcher)
|
|
7
|
+
[](https://github.com/samchon/nestia/actions?query=workflow%3Abuild)
|
|
8
|
+
[](https://nestia.io/docs/)
|
|
9
|
+
[](https://gurubase.io/g/nestia)
|
|
10
|
+
[](https://discord.gg/E94XhzrUCZ)
|
|
11
|
+
|
|
12
|
+
Nestia is a set of helper libraries for NestJS, supporting below features:
|
|
13
|
+
|
|
14
|
+
- `@nestia/core`:
|
|
15
|
+
- Super-fast/easy decorators
|
|
16
|
+
- Advanced WebSocket routes
|
|
17
|
+
- `@nestia/sdk`:
|
|
18
|
+
- Swagger generator, more evolved than ever
|
|
19
|
+
- SDK library generator for clients
|
|
20
|
+
- Mockup Simulator for client applications
|
|
21
|
+
- Automatic E2E test functions generator
|
|
22
|
+
- `@nestia/e2e`: Test program utilizing e2e test functions
|
|
23
|
+
- `@nestia/benchmark`: Benchmark program using e2e test functions
|
|
24
|
+
- `@nestia/editor`: Swagger-UI with Online TypeScript Editor
|
|
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
|
|
27
|
+
- `nestia`: Just CLI (command line interface) tool
|
|
28
|
+
|
|
29
|
+
> [!NOTE]
|
|
30
|
+
>
|
|
31
|
+
> - **Only one line** required, with pure TypeScript type
|
|
32
|
+
> - Enhance performance **30x** up
|
|
33
|
+
> - Runtime validator is **20,000x faster** than `class-validator`
|
|
34
|
+
> - JSON serialization is **200x faster** than `class-transformer`
|
|
35
|
+
> - Software Development Kit
|
|
36
|
+
> - Collection of typed `fetch` functions with DTO structures like [tRPC](https://trpc.io/)
|
|
37
|
+
> - Mockup simulator means embedded backend simulator in the SDK
|
|
38
|
+
> - similar with [msw](https://mswjs.io/), but fully automated
|
|
39
|
+
|
|
40
|
+

|
|
41
|
+
|
|
42
|
+
> Left is NestJS server code, and right is client (frontend) code utilizing SDK
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## Sponsors and Backers
|
|
48
|
+
Thanks for your support.
|
|
49
|
+
|
|
50
|
+
Your donation would encourage `nestia` development.
|
|
51
|
+
|
|
52
|
+
[](https://opencollective.com/nestia)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
## Guide Documents
|
|
58
|
+
Check out the document in the [website](https://nestia.io/docs/):
|
|
59
|
+
|
|
60
|
+
### 🏠 Home
|
|
61
|
+
- [Introduction](https://nestia.io/docs/)
|
|
62
|
+
- [Setup](https://nestia.io/docs/setup/)
|
|
63
|
+
- [Pure TypeScript](https://nestia.io/docs/pure)
|
|
64
|
+
|
|
65
|
+
### 📖 Features
|
|
66
|
+
- Core Library
|
|
67
|
+
- [`@WebSocketRoute`](https://nestia.io/docs/core/WebSocketRoute)
|
|
68
|
+
- [`@TypedRoute`](https://nestia.io/docs/core/TypedRoute/)
|
|
69
|
+
- [**`@TypedBody`**](https://nestia.io/docs/core/TypedBody/)
|
|
70
|
+
- [`@TypedParam`](https://nestia.io/docs/core/TypedParam/)
|
|
71
|
+
- [`@TypedQuery`](https://nestia.io/docs/core/TypedQuery/)
|
|
72
|
+
- [`@TypedFormData`](https://nestia.io/docs/core/TypedFormData/)
|
|
73
|
+
- [`@TypedHeaders`](https://nestia.io/docs/core/TypedHeaders/)
|
|
74
|
+
- [`@TypedException`](https://nestia.io/docs/core/TypedException/)
|
|
75
|
+
- Software Development Kit
|
|
76
|
+
- [SDK Builder](https://nestia.io/docs/sdk/)
|
|
77
|
+
- [Mockup Simulator](https://nestia.io/docs/sdk/simulate/)
|
|
78
|
+
- [E2E Test Functions](https://nestia.io/docs/sdk/e2e/)
|
|
79
|
+
- [Distribution](https://nestia.io/docs/sdk/distribute/)
|
|
80
|
+
- Swagger Document
|
|
81
|
+
- [Swagger Builder](https://nestia.io/docs/swagger/)
|
|
82
|
+
- [**AI Chatbot Development**](https://nestia.io/docs/swagger/chat/)
|
|
83
|
+
- [Cloud Swagger Editor](https://nestia.io/docs/swagger/editor/)
|
|
84
|
+
- [Documentation Strategy](https://nestia.io/docs/swagger/strategy/)
|
|
85
|
+
- E2E Testing
|
|
86
|
+
- [Why E2E Test?](https://nestia.io/docs/e2e/why/)
|
|
87
|
+
- [Test Program Development](https://nestia.io/docs/e2e/development/)
|
|
88
|
+
- [Performance Benchmark](https://nestia.io/docs/e2e/benchmark/)
|
|
89
|
+
|
|
90
|
+
### 🔗 Appendix
|
|
91
|
+
- [API Documents](https://nestia.io/api)
|
|
92
|
+
- [⇲ Benchmark Result](https://github.com/samchon/nestia/tree/master/benchmark/results/11th%20Gen%20Intel(R)%20Core(TM)%20i5-1135G7%20%40%202.40GHz)
|
|
93
|
+
- [⇲ `dev.to` Articles](https://dev.to/samchon/series/22751)
|
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
|
}
|