@nestia/e2e 7.3.3 → 8.0.0-dev.20250829
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 -93
- package/lib/ArrayUtil.d.ts +47 -43
- package/lib/ArrayUtil.js +122 -134
- package/lib/ArrayUtil.js.map +1 -1
- package/lib/GaffComparator.d.ts +19 -12
- package/lib/GaffComparator.js +19 -12
- package/lib/GaffComparator.js.map +1 -1
- package/lib/MapUtil.d.ts +79 -0
- package/lib/MapUtil.js +92 -0
- package/lib/MapUtil.js.map +1 -0
- package/lib/RandomGenerator.d.ts +107 -71
- package/lib/RandomGenerator.js +124 -109
- package/lib/RandomGenerator.js.map +1 -1
- package/lib/TestValidator.d.ts +107 -145
- package/lib/TestValidator.js +308 -351
- package/lib/TestValidator.js.map +1 -1
- package/lib/module.d.ts +2 -1
- package/lib/module.js +2 -1
- package/lib/module.js.map +1 -1
- package/package.json +1 -1
- package/src/ArrayUtil.ts +87 -88
- package/src/GaffComparator.ts +19 -12
- package/src/MapUtil.ts +86 -0
- package/src/RandomGenerator.ts +138 -101
- package/src/TestValidator.ts +251 -294
- package/src/module.ts +3 -1
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,93 +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`](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)
|
|
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
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This namespace contains utility functions for array operations including
|
|
5
5
|
* asynchronous processing, filtering, mapping, and repetition tasks implemented
|
|
6
|
-
* in functional programming style.
|
|
7
|
-
*
|
|
6
|
+
* in functional programming style. Functions use direct parameter passing for
|
|
7
|
+
* simplicity while maintaining functional programming principles.
|
|
8
8
|
*
|
|
9
9
|
* @author Jeongho Nam - https://github.com/samchon
|
|
10
10
|
* @example
|
|
11
11
|
* ```typescript
|
|
12
12
|
* // Asynchronous filtering example
|
|
13
13
|
* const numbers = [1, 2, 3, 4, 5];
|
|
14
|
-
* const evenNumbers = await ArrayUtil.asyncFilter(numbers
|
|
14
|
+
* const evenNumbers = await ArrayUtil.asyncFilter(numbers,
|
|
15
15
|
* async (num) => num % 2 === 0
|
|
16
16
|
* );
|
|
17
17
|
* console.log(evenNumbers); // [2, 4]
|
|
@@ -22,9 +22,9 @@ export declare namespace ArrayUtil {
|
|
|
22
22
|
* Filters an array by applying an asynchronous predicate function to each
|
|
23
23
|
* element.
|
|
24
24
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
25
|
+
* Elements are processed sequentially, ensuring order is maintained. The
|
|
26
|
+
* predicate function receives the element, index, and the full array as
|
|
27
|
+
* parameters.
|
|
28
28
|
*
|
|
29
29
|
* @example
|
|
30
30
|
* ```typescript
|
|
@@ -34,7 +34,7 @@ export declare namespace ArrayUtil {
|
|
|
34
34
|
* { id: 3, name: 'Charlie', active: true }
|
|
35
35
|
* ];
|
|
36
36
|
*
|
|
37
|
-
* const activeUsers = await ArrayUtil.asyncFilter(users
|
|
37
|
+
* const activeUsers = await ArrayUtil.asyncFilter(users,
|
|
38
38
|
* async (user) => {
|
|
39
39
|
* // Async validation logic (e.g., API call)
|
|
40
40
|
* await new Promise(resolve => setTimeout(resolve, 100));
|
|
@@ -46,10 +46,10 @@ export declare namespace ArrayUtil {
|
|
|
46
46
|
*
|
|
47
47
|
* @template Input - The type of elements in the input array
|
|
48
48
|
* @param elements - The readonly array to filter
|
|
49
|
-
* @
|
|
50
|
-
*
|
|
49
|
+
* @param pred - The asynchronous predicate function to test each element
|
|
50
|
+
* @returns A Promise resolving to the filtered array
|
|
51
51
|
*/
|
|
52
|
-
const asyncFilter: <Input>(elements: readonly Input[]
|
|
52
|
+
const asyncFilter: <Input>(elements: readonly Input[], pred: (elem: Input, index: number, array: readonly Input[]) => Promise<boolean>) => Promise<Input[]>;
|
|
53
53
|
/**
|
|
54
54
|
* Executes an asynchronous function for each element in an array
|
|
55
55
|
* sequentially.
|
|
@@ -63,44 +63,45 @@ export declare namespace ArrayUtil {
|
|
|
63
63
|
* ```typescript
|
|
64
64
|
* const urls = ['url1', 'url2', 'url3'];
|
|
65
65
|
*
|
|
66
|
-
* await ArrayUtil.asyncForEach(urls
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
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
71
|
* });
|
|
72
72
|
* console.log('All URLs processed sequentially');
|
|
73
73
|
* ```
|
|
74
74
|
*
|
|
75
75
|
* @template Input - The type of elements in the input array
|
|
76
76
|
* @param elements - The readonly array to process
|
|
77
|
-
* @
|
|
77
|
+
* @param closure - The asynchronous function to execute for each element
|
|
78
|
+
* @returns A Promise<void> that resolves when all operations complete
|
|
78
79
|
*/
|
|
79
|
-
const asyncForEach: <Input>(elements: readonly Input[]
|
|
80
|
+
const asyncForEach: <Input>(elements: readonly Input[], closure: (elem: Input, index: number, array: readonly Input[]) => Promise<any>) => Promise<void>;
|
|
80
81
|
/**
|
|
81
82
|
* Transforms each element of an array using an asynchronous function to
|
|
82
83
|
* create a new array.
|
|
83
84
|
*
|
|
84
85
|
* Similar to JavaScript's native map but processes asynchronous functions
|
|
85
86
|
* sequentially. Each element's transformation is completed before proceeding
|
|
86
|
-
* to the next element, ensuring order is maintained.
|
|
87
|
+
* to the next element, ensuring order is maintained. This function still
|
|
88
|
+
* maintains the currying pattern for composition.
|
|
87
89
|
*
|
|
88
90
|
* @example
|
|
89
91
|
* ```typescript
|
|
90
92
|
* const userIds = [1, 2, 3, 4, 5];
|
|
91
93
|
*
|
|
92
94
|
* const userDetails = await ArrayUtil.asyncMap(userIds)(
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
95
|
+
* async (id, index) => {
|
|
96
|
+
* console.log(`Fetching user ${id} (${index + 1}/${userIds.length})`);
|
|
97
|
+
* const response = await fetch(`/api/users/${id}`);
|
|
98
|
+
* return await response.json();
|
|
99
|
+
* }
|
|
98
100
|
* );
|
|
99
101
|
* console.log('All users fetched:', userDetails);
|
|
100
102
|
* ```
|
|
101
103
|
*
|
|
102
104
|
* @template Input - The type of elements in the input array
|
|
103
|
-
* @template Output - The type of elements in the output array
|
|
104
105
|
* @param elements - The readonly array to transform
|
|
105
106
|
* @returns A function that takes a transformation function and returns a
|
|
106
107
|
* Promise resolving to the transformed array
|
|
@@ -116,7 +117,7 @@ export declare namespace ArrayUtil {
|
|
|
116
117
|
* @example
|
|
117
118
|
* ```typescript
|
|
118
119
|
* // Generate random data 5 times
|
|
119
|
-
* const randomData = await ArrayUtil.asyncRepeat(5
|
|
120
|
+
* const randomData = await ArrayUtil.asyncRepeat(5, async (index) => {
|
|
120
121
|
* await new Promise(resolve => setTimeout(resolve, 100)); // Wait 0.1 seconds
|
|
121
122
|
* return {
|
|
122
123
|
* id: index,
|
|
@@ -127,17 +128,17 @@ export declare namespace ArrayUtil {
|
|
|
127
128
|
* console.log('Generated data:', randomData);
|
|
128
129
|
* ```;
|
|
129
130
|
*
|
|
131
|
+
* @template T - The type of the result from each execution
|
|
130
132
|
* @param count - The number of times to repeat (non-negative integer)
|
|
131
|
-
* @
|
|
132
|
-
*
|
|
133
|
+
* @param closure - The asynchronous function to execute repeatedly
|
|
134
|
+
* @returns A Promise resolving to an array of results
|
|
133
135
|
*/
|
|
134
|
-
const asyncRepeat: (count: number
|
|
136
|
+
const asyncRepeat: <T>(count: number, closure: (index: number) => Promise<T>) => Promise<T[]>;
|
|
135
137
|
/**
|
|
136
138
|
* Checks if at least one element in the array satisfies the given condition.
|
|
137
139
|
*
|
|
138
|
-
* Similar to JavaScript's native some() method
|
|
139
|
-
*
|
|
140
|
-
* true immediately when the first element satisfying the condition is found.
|
|
140
|
+
* Similar to JavaScript's native some() method. Returns true immediately
|
|
141
|
+
* when the first element satisfying the condition is found.
|
|
141
142
|
*
|
|
142
143
|
* @example
|
|
143
144
|
* ```typescript
|
|
@@ -148,21 +149,22 @@ export declare namespace ArrayUtil {
|
|
|
148
149
|
* { name: 'Orange', price: 80, inStock: true }
|
|
149
150
|
* ];
|
|
150
151
|
*
|
|
151
|
-
* const hasEvenNumber = ArrayUtil.has(numbers
|
|
152
|
+
* const hasEvenNumber = ArrayUtil.has(numbers, num => num % 2 === 0);
|
|
152
153
|
* console.log(hasEvenNumber); // true (8 exists)
|
|
153
154
|
*
|
|
154
|
-
* const hasExpensiveItem = ArrayUtil.has(products
|
|
155
|
+
* const hasExpensiveItem = ArrayUtil.has(products, product => product.price > 90);
|
|
155
156
|
* console.log(hasExpensiveItem); // true (Apple costs 100)
|
|
156
157
|
*
|
|
157
|
-
* const hasOutOfStock = ArrayUtil.has(products
|
|
158
|
+
* const hasOutOfStock = ArrayUtil.has(products, product => !product.inStock);
|
|
158
159
|
* console.log(hasOutOfStock); // true (Banana is out of stock)
|
|
159
160
|
* ```;
|
|
160
161
|
*
|
|
161
162
|
* @template T - The type of elements in the array
|
|
162
163
|
* @param elements - The readonly array to check
|
|
163
|
-
* @
|
|
164
|
+
* @param pred - The predicate function to test elements
|
|
165
|
+
* @returns Boolean indicating if any element satisfies the condition
|
|
164
166
|
*/
|
|
165
|
-
const has: <T>(elements: readonly T[]
|
|
167
|
+
const has: <T>(elements: readonly T[], pred: (elem: T) => boolean) => boolean;
|
|
166
168
|
/**
|
|
167
169
|
* Executes a function a specified number of times and collects the results
|
|
168
170
|
* into an array.
|
|
@@ -173,14 +175,14 @@ export declare namespace ArrayUtil {
|
|
|
173
175
|
* @example
|
|
174
176
|
* ```typescript
|
|
175
177
|
* // Generate an array of squares from 1 to 5
|
|
176
|
-
* const squares = ArrayUtil.repeat(5
|
|
178
|
+
* const squares = ArrayUtil.repeat(5, index => (index + 1) ** 2);
|
|
177
179
|
* console.log(squares); // [1, 4, 9, 16, 25]
|
|
178
180
|
*
|
|
179
181
|
* // Generate an array of default user objects
|
|
180
|
-
* const users = ArrayUtil.repeat(3
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
182
|
+
* const users = ArrayUtil.repeat(3, index => ({
|
|
183
|
+
* id: index + 1,
|
|
184
|
+
* name: `User${index + 1}`,
|
|
185
|
+
* email: `user${index + 1}@example.com`
|
|
184
186
|
* }));
|
|
185
187
|
* console.log(users);
|
|
186
188
|
* // [
|
|
@@ -190,10 +192,12 @@ export declare namespace ArrayUtil {
|
|
|
190
192
|
* // ]
|
|
191
193
|
* ```
|
|
192
194
|
*
|
|
195
|
+
* @template T - The type of the result from each execution
|
|
193
196
|
* @param count - The number of times to repeat (non-negative integer)
|
|
194
|
-
* @
|
|
197
|
+
* @param closure - The function to execute repeatedly
|
|
198
|
+
* @returns An array of results
|
|
195
199
|
*/
|
|
196
|
-
const repeat: (count: number
|
|
200
|
+
const repeat: <T>(count: number, closure: (index: number) => T) => T[];
|
|
197
201
|
/**
|
|
198
202
|
* Generates all possible subsets of a given array.
|
|
199
203
|
*
|