@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/lib/MapUtil.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MapUtil = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A namespace providing utility functions for Map manipulation.
|
|
6
|
+
*
|
|
7
|
+
* This namespace contains helper functions for working with JavaScript Map
|
|
8
|
+
* objects, providing convenient methods for common Map operations like
|
|
9
|
+
* retrieving values with lazy initialization.
|
|
10
|
+
*
|
|
11
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Create a cache with lazy initialization
|
|
15
|
+
* const cache = new Map<string, ExpensiveObject>();
|
|
16
|
+
*
|
|
17
|
+
* const obj = MapUtil.take(cache, "key1", () => {
|
|
18
|
+
* console.log("Creating expensive object...");
|
|
19
|
+
* return new ExpensiveObject();
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Subsequent calls return cached value without re-creating
|
|
23
|
+
* const sameObj = MapUtil.take(cache, "key1", () => new ExpensiveObject());
|
|
24
|
+
* console.log(obj === sameObj); // true
|
|
25
|
+
* ```;
|
|
26
|
+
*/
|
|
27
|
+
var MapUtil;
|
|
28
|
+
(function (MapUtil) {
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves a value from a Map or creates it using a lazy initialization
|
|
31
|
+
* function.
|
|
32
|
+
*
|
|
33
|
+
* This function implements the "get or create" pattern for Maps. If the key
|
|
34
|
+
* exists in the Map, it returns the existing value. Otherwise, it calls the
|
|
35
|
+
* provided factory function to create a new value, stores it in the Map, and
|
|
36
|
+
* returns it. The factory function is only called when the key doesn't exist,
|
|
37
|
+
* enabling lazy initialization and caching patterns.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* // Simple caching example
|
|
42
|
+
* const userCache = new Map<number, User>();
|
|
43
|
+
*
|
|
44
|
+
* const user = MapUtil.take(userCache, userId, () => {
|
|
45
|
+
* // This expensive operation only runs if userId is not cached
|
|
46
|
+
* return fetchUserFromDatabase(userId);
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* // Configuration object caching
|
|
50
|
+
* const configs = new Map<string, Config>();
|
|
51
|
+
*
|
|
52
|
+
* const dbConfig = MapUtil.take(configs, "database", () => ({
|
|
53
|
+
* host: "localhost",
|
|
54
|
+
* port: 5432,
|
|
55
|
+
* database: "myapp"
|
|
56
|
+
* }));
|
|
57
|
+
*
|
|
58
|
+
* // Lazy computation results
|
|
59
|
+
* const computationCache = new Map<string, number>();
|
|
60
|
+
*
|
|
61
|
+
* const result = MapUtil.take(computationCache, "fibonacci-40", () => {
|
|
62
|
+
* console.log("Computing fibonacci(40)...");
|
|
63
|
+
* return fibonacci(40); // Only computed once
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* // Using with complex keys
|
|
67
|
+
* const cache = new Map<[number, number], Matrix>();
|
|
68
|
+
* const key: [number, number] = [rows, cols];
|
|
69
|
+
*
|
|
70
|
+
* const matrix = MapUtil.take(cache, key, () =>
|
|
71
|
+
* generateIdentityMatrix(rows, cols)
|
|
72
|
+
* );
|
|
73
|
+
* ```;
|
|
74
|
+
*
|
|
75
|
+
* @template K - The type of keys in the Map
|
|
76
|
+
* @template V - The type of values in the Map
|
|
77
|
+
* @param map - The Map to retrieve from or update
|
|
78
|
+
* @param key - The key to look up in the Map
|
|
79
|
+
* @param value - A factory function that creates the value if key doesn't exist
|
|
80
|
+
* @returns The existing value if found, or the newly created value
|
|
81
|
+
*/
|
|
82
|
+
function take(map, key, value) {
|
|
83
|
+
if (map.has(key)) {
|
|
84
|
+
return map.get(key);
|
|
85
|
+
}
|
|
86
|
+
var newValue = value();
|
|
87
|
+
map.set(key, newValue);
|
|
88
|
+
return newValue;
|
|
89
|
+
}
|
|
90
|
+
MapUtil.take = take;
|
|
91
|
+
})(MapUtil || (exports.MapUtil = MapUtil = {}));
|
|
92
|
+
//# sourceMappingURL=MapUtil.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapUtil.js","sourceRoot":"","sources":["../src/MapUtil.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,IAAiB,OAAO,CA8DvB;AA9DD,WAAiB,OAAO;IACtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoDG;IACH,SAAgB,IAAI,CAAO,GAAc,EAAE,GAAM,EAAE,KAAc;QAC/D,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACjB,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,CAAM,CAAC;QAC3B,CAAC;QACD,IAAM,QAAQ,GAAG,KAAK,EAAE,CAAC;QACzB,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QACvB,OAAO,QAAQ,CAAC;IAClB,CAAC;IAPe,YAAI,OAOnB,CAAA;AACH,CAAC,EA9DgB,OAAO,uBAAP,OAAO,QA8DvB"}
|
package/lib/RandomGenerator.d.ts
CHANGED
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
* const testUser = {
|
|
21
21
|
* id: RandomGenerator.alphaNumeric(8),
|
|
22
22
|
* name: RandomGenerator.name(),
|
|
23
|
-
* bio: RandomGenerator.paragraph(3
|
|
23
|
+
* bio: RandomGenerator.paragraph({ sentences: 3, wordMin: 5, wordMax: 10 }),
|
|
24
24
|
* phone: RandomGenerator.mobile(),
|
|
25
|
-
* createdAt: RandomGenerator.date(new Date()
|
|
25
|
+
* createdAt: RandomGenerator.date(new Date(), 1000 * 60 * 60 * 24 * 30) // 30 days
|
|
26
26
|
* };
|
|
27
27
|
*
|
|
28
28
|
* // Sample data for testing
|
|
29
|
-
* const testSample = RandomGenerator.sample(allUsers
|
|
29
|
+
* const testSample = RandomGenerator.sample(allUsers, 5);
|
|
30
30
|
* ```;
|
|
31
31
|
*/
|
|
32
32
|
export declare namespace RandomGenerator {
|
|
@@ -41,9 +41,9 @@ export declare namespace RandomGenerator {
|
|
|
41
41
|
*
|
|
42
42
|
* @example
|
|
43
43
|
* ```typescript
|
|
44
|
-
* RandomGenerator.alphabets(5); // "
|
|
45
|
-
* RandomGenerator.alphabets(3); // "
|
|
46
|
-
* RandomGenerator.alphabets(10); // "
|
|
44
|
+
* RandomGenerator.alphabets(5); // e.g. "kxqpw"
|
|
45
|
+
* RandomGenerator.alphabets(3); // e.g. "mzr"
|
|
46
|
+
* RandomGenerator.alphabets(10); // e.g. "qwertasdfg"
|
|
47
47
|
*
|
|
48
48
|
* // Generate random CSS class names
|
|
49
49
|
* const className = `test-${RandomGenerator.alphabets(6)}`;
|
|
@@ -67,8 +67,8 @@ export declare namespace RandomGenerator {
|
|
|
67
67
|
*
|
|
68
68
|
* @example
|
|
69
69
|
* ```typescript
|
|
70
|
-
* RandomGenerator.alphaNumeric(8); // "a1b2c3d4"
|
|
71
|
-
* RandomGenerator.alphaNumeric(12); // "x9y8z7w6v5u4"
|
|
70
|
+
* RandomGenerator.alphaNumeric(8); // e.g. "a1b2c3d4"
|
|
71
|
+
* RandomGenerator.alphaNumeric(12); // e.g. "x9y8z7w6v5u4"
|
|
72
72
|
*
|
|
73
73
|
* // Generate random API keys
|
|
74
74
|
* const apiKey = RandomGenerator.alphaNumeric(32);
|
|
@@ -95,9 +95,9 @@ export declare namespace RandomGenerator {
|
|
|
95
95
|
*
|
|
96
96
|
* @example
|
|
97
97
|
* ```typescript
|
|
98
|
-
* RandomGenerator.name(); // "
|
|
99
|
-
* RandomGenerator.name(1); // "
|
|
100
|
-
* RandomGenerator.name(3); // "
|
|
98
|
+
* RandomGenerator.name(); // e.g. "lorem ipsum" (2-3 words)
|
|
99
|
+
* RandomGenerator.name(1); // e.g. "dolor" (single word)
|
|
100
|
+
* RandomGenerator.name(3); // e.g. "sit amet consectetur" (3 words)
|
|
101
101
|
*
|
|
102
102
|
* // Generate test user names
|
|
103
103
|
* const users = Array.from({ length: 10 }, () => ({
|
|
@@ -111,7 +111,7 @@ export declare namespace RandomGenerator {
|
|
|
111
111
|
* ```
|
|
112
112
|
*
|
|
113
113
|
* @param length - Number of words in the name (default: random between 2-3)
|
|
114
|
-
* @returns A space-separated string
|
|
114
|
+
* @returns A space-separated string of random words (each 3-7 chars by default)
|
|
115
115
|
*/
|
|
116
116
|
const name: (length?: number) => string;
|
|
117
117
|
/**
|
|
@@ -119,77 +119,112 @@ export declare namespace RandomGenerator {
|
|
|
119
119
|
*
|
|
120
120
|
* Creates a paragraph consisting of a specified number of "sentences"
|
|
121
121
|
* (words). Each sentence is a random alphabetic string, and sentences are
|
|
122
|
-
* joined with spaces.
|
|
123
|
-
*
|
|
122
|
+
* joined with spaces. Accepts an optional configuration object for fine-tuned
|
|
123
|
+
* control over the paragraph structure.
|
|
124
124
|
*
|
|
125
125
|
* @example
|
|
126
126
|
* ```typescript
|
|
127
|
-
* // Generate with
|
|
128
|
-
* RandomGenerator.paragraph(
|
|
129
|
-
*
|
|
127
|
+
* // Generate with defaults (random 2-5 words, 3-7 characters each)
|
|
128
|
+
* RandomGenerator.paragraph(); // e.g. "lorem ipsum dolor"
|
|
129
|
+
*
|
|
130
|
+
* // Specific number of sentences
|
|
131
|
+
* RandomGenerator.paragraph({ sentences: 5 }); // "lorem ipsum dolor sit amet"
|
|
130
132
|
*
|
|
131
133
|
* // Custom word length ranges
|
|
132
|
-
* RandomGenerator.paragraph(4
|
|
133
|
-
*
|
|
134
|
+
* RandomGenerator.paragraph({ sentences: 4, wordMin: 2, wordMax: 5 });
|
|
135
|
+
* // "ab cd ef gh"
|
|
134
136
|
*
|
|
135
137
|
* // Generate product descriptions
|
|
136
|
-
* const description = RandomGenerator.paragraph(
|
|
138
|
+
* const description = RandomGenerator.paragraph({
|
|
139
|
+
* sentences: 8,
|
|
140
|
+
* wordMin: 4,
|
|
141
|
+
* wordMax: 8
|
|
142
|
+
* });
|
|
137
143
|
*
|
|
138
144
|
* // Create test content for forms
|
|
139
|
-
* const placeholder = RandomGenerator.paragraph(
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
* );
|
|
145
|
+
* const placeholder = RandomGenerator.paragraph({
|
|
146
|
+
* sentences: 3,
|
|
147
|
+
* wordMin: 5,
|
|
148
|
+
* wordMax: 10
|
|
149
|
+
* });
|
|
145
150
|
* ```;
|
|
146
151
|
*
|
|
147
|
-
* @param
|
|
148
|
-
*
|
|
149
|
-
* @returns A
|
|
152
|
+
* @param props - Optional configuration object with sentences count and word
|
|
153
|
+
* length ranges
|
|
154
|
+
* @returns A string containing the generated paragraph
|
|
150
155
|
*/
|
|
151
|
-
const paragraph: (
|
|
156
|
+
const paragraph: (props?: Partial<{
|
|
157
|
+
sentences: number;
|
|
158
|
+
wordMin: number;
|
|
159
|
+
wordMax: number;
|
|
160
|
+
}>) => string;
|
|
152
161
|
/**
|
|
153
162
|
* Generates random multi-paragraph content with customizable structure.
|
|
154
163
|
*
|
|
155
164
|
* Creates content consisting of multiple paragraphs separated by double
|
|
156
|
-
* newlines.
|
|
157
|
-
*
|
|
165
|
+
* newlines. Accepts an optional configuration object to control content
|
|
166
|
+
* structure including paragraph count, sentences per paragraph, and word
|
|
158
167
|
* character lengths. Ideal for generating realistic-looking text content for
|
|
159
168
|
* testing.
|
|
160
169
|
*
|
|
161
170
|
* @example
|
|
162
171
|
* ```typescript
|
|
163
172
|
* // Generate with all defaults
|
|
164
|
-
* const article = RandomGenerator.content()
|
|
173
|
+
* const article = RandomGenerator.content();
|
|
165
174
|
*
|
|
166
175
|
* // Specific structure: 5 paragraphs, 15-25 sentences each, 4-8 char words
|
|
167
|
-
* const longContent = RandomGenerator.content(
|
|
176
|
+
* const longContent = RandomGenerator.content({
|
|
177
|
+
* paragraphs: 5,
|
|
178
|
+
* sentenceMin: 15,
|
|
179
|
+
* sentenceMax: 25,
|
|
180
|
+
* wordMin: 4,
|
|
181
|
+
* wordMax: 8
|
|
182
|
+
* });
|
|
168
183
|
*
|
|
169
184
|
* // Short content with brief sentences
|
|
170
|
-
* const shortContent = RandomGenerator.content(
|
|
185
|
+
* const shortContent = RandomGenerator.content({
|
|
186
|
+
* paragraphs: 2,
|
|
187
|
+
* sentenceMin: 5,
|
|
188
|
+
* sentenceMax: 8,
|
|
189
|
+
* wordMin: 2,
|
|
190
|
+
* wordMax: 4
|
|
191
|
+
* });
|
|
171
192
|
*
|
|
172
193
|
* // Generate blog post content
|
|
173
194
|
* const blogPost = {
|
|
174
195
|
* title: RandomGenerator.name(3),
|
|
175
|
-
* content: RandomGenerator.content(
|
|
176
|
-
*
|
|
196
|
+
* content: RandomGenerator.content({
|
|
197
|
+
* paragraphs: 4,
|
|
198
|
+
* sentenceMin: 10,
|
|
199
|
+
* sentenceMax: 20,
|
|
200
|
+
* wordMin: 3,
|
|
201
|
+
* wordMax: 7
|
|
202
|
+
* }),
|
|
203
|
+
* summary: RandomGenerator.paragraph({ sentences: 2 })
|
|
177
204
|
* };
|
|
178
205
|
*
|
|
179
206
|
* // Create test data for CMS
|
|
180
207
|
* const pages = Array.from({ length: 10 }, () => ({
|
|
181
208
|
* id: RandomGenerator.alphaNumeric(8),
|
|
182
|
-
* content: RandomGenerator.content(
|
|
209
|
+
* content: RandomGenerator.content({
|
|
210
|
+
* paragraphs: randint(2, 6),
|
|
211
|
+
* sentenceMin: 8,
|
|
212
|
+
* sentenceMax: 15
|
|
213
|
+
* })
|
|
183
214
|
* }));
|
|
184
|
-
*
|
|
185
|
-
* // Generate email content for testing
|
|
186
|
-
* const emailBody = RandomGenerator.content(3)(5, 12)(3, 8);
|
|
187
215
|
* ```;
|
|
188
216
|
*
|
|
189
|
-
* @param
|
|
190
|
-
*
|
|
217
|
+
* @param props - Optional configuration object with paragraph, sentence, and
|
|
218
|
+
* word parameters
|
|
219
|
+
* @returns A string containing the generated multi-paragraph content
|
|
191
220
|
*/
|
|
192
|
-
const content: (
|
|
221
|
+
const content: (props?: Partial<{
|
|
222
|
+
paragraphs: number;
|
|
223
|
+
sentenceMin: number;
|
|
224
|
+
sentenceMax: number;
|
|
225
|
+
wordMin: number;
|
|
226
|
+
wordMax: number;
|
|
227
|
+
}>) => string;
|
|
193
228
|
/**
|
|
194
229
|
* Extracts a random substring from the provided content string.
|
|
195
230
|
*
|
|
@@ -202,9 +237,9 @@ export declare namespace RandomGenerator {
|
|
|
202
237
|
* ```typescript
|
|
203
238
|
* const text = "The quick brown fox jumps over the lazy dog";
|
|
204
239
|
*
|
|
205
|
-
* RandomGenerator.substring(text); // "quick brown fox"
|
|
206
|
-
* RandomGenerator.substring(text); // "jumps over"
|
|
207
|
-
* RandomGenerator.substring(text); // "fox jumps over the lazy"
|
|
240
|
+
* RandomGenerator.substring(text); // e.g. "quick brown fox"
|
|
241
|
+
* RandomGenerator.substring(text); // e.g. "jumps over"
|
|
242
|
+
* RandomGenerator.substring(text); // e.g. "fox jumps over the lazy"
|
|
208
243
|
*
|
|
209
244
|
* // Generate search terms from content
|
|
210
245
|
* const searchQuery = RandomGenerator.substring(articleContent);
|
|
@@ -234,9 +269,9 @@ export declare namespace RandomGenerator {
|
|
|
234
269
|
*
|
|
235
270
|
* @example
|
|
236
271
|
* ```typescript
|
|
237
|
-
* RandomGenerator.mobile(); // "0103341234"
|
|
238
|
-
* RandomGenerator.mobile("011"); // "0119876543"
|
|
239
|
-
* RandomGenerator.mobile("+82"); // "+
|
|
272
|
+
* RandomGenerator.mobile(); // e.g. "0103341234" or "01012345678"
|
|
273
|
+
* RandomGenerator.mobile("011"); // e.g. "0119876543" or "01112345678"
|
|
274
|
+
* RandomGenerator.mobile("+82"); // e.g. "+823341234" or "+8212345678"
|
|
240
275
|
*
|
|
241
276
|
* // Generate test user phone numbers
|
|
242
277
|
* const testUsers = Array.from({ length: 100 }, () => ({
|
|
@@ -262,8 +297,7 @@ export declare namespace RandomGenerator {
|
|
|
262
297
|
/**
|
|
263
298
|
* Generates a random date within a specified range from a starting point.
|
|
264
299
|
*
|
|
265
|
-
*
|
|
266
|
-
* returns a random date between the start date and start date + range. The
|
|
300
|
+
* Returns a random date between the start date and start date + range. The
|
|
267
301
|
* range represents the maximum number of milliseconds to add to the starting
|
|
268
302
|
* date. Useful for generating timestamps, creation dates, or scheduling test
|
|
269
303
|
* data.
|
|
@@ -275,30 +309,31 @@ export declare namespace RandomGenerator {
|
|
|
275
309
|
* const oneMonth = 30 * oneDay;
|
|
276
310
|
*
|
|
277
311
|
* // Random date within the next 30 days
|
|
278
|
-
* const futureDate = RandomGenerator.date(now
|
|
312
|
+
* const futureDate = RandomGenerator.date(now, oneMonth);
|
|
279
313
|
*
|
|
280
314
|
* // Random date within the past week
|
|
281
315
|
* const pastWeek = new Date(now.getTime() - 7 * oneDay);
|
|
282
|
-
* const recentDate = RandomGenerator.date(pastWeek
|
|
316
|
+
* const recentDate = RandomGenerator.date(pastWeek, 7 * oneDay);
|
|
283
317
|
*
|
|
284
318
|
* // Generate random creation dates for test data
|
|
285
319
|
* const startOfYear = new Date(2024, 0, 1);
|
|
286
320
|
* const endOfYear = new Date(2024, 11, 31).getTime() - startOfYear.getTime();
|
|
287
|
-
* const randomCreationDate = RandomGenerator.date(startOfYear
|
|
321
|
+
* const randomCreationDate = RandomGenerator.date(startOfYear, endOfYear);
|
|
288
322
|
*
|
|
289
323
|
* // Create test events with random timestamps
|
|
290
324
|
* const events = Array.from({ length: 50 }, () => ({
|
|
291
325
|
* id: RandomGenerator.alphaNumeric(8),
|
|
292
326
|
* title: RandomGenerator.name(2),
|
|
293
|
-
* createdAt: RandomGenerator.date(new Date()
|
|
294
|
-
* scheduledFor: RandomGenerator.date(new Date()
|
|
327
|
+
* createdAt: RandomGenerator.date(new Date(), oneMonth),
|
|
328
|
+
* scheduledFor: RandomGenerator.date(new Date(), oneMonth * 3)
|
|
295
329
|
* }));
|
|
296
330
|
* ```;
|
|
297
331
|
*
|
|
298
332
|
* @param from - The starting date for the random range
|
|
299
|
-
* @
|
|
333
|
+
* @param range - The range in milliseconds from the starting date
|
|
334
|
+
* @returns A random date within the specified range
|
|
300
335
|
*/
|
|
301
|
-
const date: (from: Date
|
|
336
|
+
const date: (from: Date, range: number) => Date;
|
|
302
337
|
/**
|
|
303
338
|
* Randomly samples a specified number of unique elements from an array.
|
|
304
339
|
*
|
|
@@ -312,30 +347,31 @@ export declare namespace RandomGenerator {
|
|
|
312
347
|
* ```typescript
|
|
313
348
|
* const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
314
349
|
*
|
|
315
|
-
* RandomGenerator.sample(numbers
|
|
316
|
-
* RandomGenerator.sample(numbers
|
|
317
|
-
* RandomGenerator.sample(numbers
|
|
350
|
+
* RandomGenerator.sample(numbers, 3); // e.g. [2, 7, 9]
|
|
351
|
+
* RandomGenerator.sample(numbers, 5); // e.g. [1, 4, 6, 8, 10]
|
|
352
|
+
* RandomGenerator.sample(numbers, 15); // returns all 10 elements (capped at array length)
|
|
318
353
|
*
|
|
319
354
|
* // Sample users for testing
|
|
320
355
|
* const allUsers = await getUsersFromDatabase();
|
|
321
|
-
* const testUsers = RandomGenerator.sample(allUsers
|
|
356
|
+
* const testUsers = RandomGenerator.sample(allUsers, 10);
|
|
322
357
|
*
|
|
323
358
|
* // Create random product selections
|
|
324
|
-
* const featuredProducts = RandomGenerator.sample(allProducts
|
|
359
|
+
* const featuredProducts = RandomGenerator.sample(allProducts, 5);
|
|
325
360
|
*
|
|
326
361
|
* // Generate test data subsets
|
|
327
|
-
* const validationSet = RandomGenerator.sample(trainingData
|
|
362
|
+
* const validationSet = RandomGenerator.sample(trainingData, 100);
|
|
328
363
|
*
|
|
329
364
|
* // Random A/B testing groups
|
|
330
|
-
* const groupA = RandomGenerator.sample(allParticipants
|
|
365
|
+
* const groupA = RandomGenerator.sample(allParticipants, 50);
|
|
331
366
|
* const remaining = allParticipants.filter(p => !groupA.includes(p));
|
|
332
|
-
* const groupB = RandomGenerator.sample(remaining
|
|
367
|
+
* const groupB = RandomGenerator.sample(remaining, 50);
|
|
333
368
|
* ```;
|
|
334
369
|
*
|
|
335
370
|
* @param array - The source array to sample from
|
|
336
|
-
* @
|
|
371
|
+
* @param count - The number of elements to sample
|
|
372
|
+
* @returns An array containing the randomly selected elements
|
|
337
373
|
*/
|
|
338
|
-
const sample: <T>(array: T[]
|
|
374
|
+
const sample: <T>(array: T[], count: number) => T[];
|
|
339
375
|
/**
|
|
340
376
|
* Randomly selects a single element from an array.
|
|
341
377
|
*
|
|
@@ -349,8 +385,8 @@ export declare namespace RandomGenerator {
|
|
|
349
385
|
* const colors = ['red', 'blue', 'green', 'yellow', 'purple'];
|
|
350
386
|
* const fruits = ['apple', 'banana', 'orange', 'grape', 'kiwi'];
|
|
351
387
|
*
|
|
352
|
-
* RandomGenerator.pick(colors); // "blue"
|
|
353
|
-
* RandomGenerator.pick(fruits); // "apple"
|
|
388
|
+
* RandomGenerator.pick(colors); // e.g. "blue"
|
|
389
|
+
* RandomGenerator.pick(fruits); // e.g. "apple"
|
|
354
390
|
*
|
|
355
391
|
* // Select random configuration options
|
|
356
392
|
* const randomTheme = RandomGenerator.pick(['light', 'dark', 'auto']);
|