@nestia/e2e 0.1.1 → 0.1.2
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/lib/DynamicExecutor.d.ts +7 -0
- package/lib/DynamicExecutor.js +103 -109
- package/lib/DynamicExecutor.js.map +1 -1
- package/package.json +52 -52
- package/src/ArrayUtil.ts +87 -87
- package/src/DynamicExecutor.ts +267 -270
- package/src/GaffComparator.ts +69 -69
- package/src/RandomGenerator.ts +178 -178
- package/src/StopWatch.ts +36 -36
- package/src/TestValidator.ts +145 -145
- package/src/index.ts +4 -4
- package/src/module.ts +6 -6
package/lib/DynamicExecutor.d.ts
CHANGED
|
@@ -40,6 +40,13 @@ export declare namespace DynamicExecutor {
|
|
|
40
40
|
* @returns Parameters
|
|
41
41
|
*/
|
|
42
42
|
parameters: (name: string) => Parameters;
|
|
43
|
+
/**
|
|
44
|
+
* Filter function whether to run or not.
|
|
45
|
+
*
|
|
46
|
+
* @param name Function name
|
|
47
|
+
* @returns Whether to run or not
|
|
48
|
+
*/
|
|
49
|
+
filter?: (name: string) => boolean;
|
|
43
50
|
/**
|
|
44
51
|
* Wrapper of test function.
|
|
45
52
|
*
|
package/lib/DynamicExecutor.js
CHANGED
|
@@ -100,7 +100,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
100
100
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
101
101
|
exports.DynamicExecutor = void 0;
|
|
102
102
|
var chalk_1 = __importDefault(require("chalk"));
|
|
103
|
-
var cli_1 = __importDefault(require("cli"));
|
|
104
103
|
var fs_1 = __importDefault(require("fs"));
|
|
105
104
|
var path_1 = __importDefault(require("path"));
|
|
106
105
|
var StopWatch_1 = require("./StopWatch");
|
|
@@ -164,17 +163,16 @@ var DynamicExecutor;
|
|
|
164
163
|
var main = function (options) {
|
|
165
164
|
return function (assert) {
|
|
166
165
|
return function (path) { return __awaiter(_this, void 0, void 0, function () {
|
|
167
|
-
var
|
|
166
|
+
var report, executor, iterator;
|
|
168
167
|
return __generator(this, function (_a) {
|
|
169
168
|
switch (_a.label) {
|
|
170
169
|
case 0:
|
|
171
|
-
command = cli_1.default.parse();
|
|
172
170
|
report = {
|
|
173
171
|
location: path,
|
|
174
172
|
time: Date.now(),
|
|
175
173
|
executions: [],
|
|
176
174
|
};
|
|
177
|
-
executor = execute(options)(
|
|
175
|
+
executor = execute(options)(report)(assert);
|
|
178
176
|
iterator = iterate(executor);
|
|
179
177
|
return [4 /*yield*/, iterator(path)];
|
|
180
178
|
case 1:
|
|
@@ -245,111 +243,107 @@ var DynamicExecutor;
|
|
|
245
243
|
return visitor;
|
|
246
244
|
};
|
|
247
245
|
var execute = function (options) {
|
|
248
|
-
return function (
|
|
249
|
-
return function (
|
|
250
|
-
return function (
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
}); };
|
|
352
|
-
};
|
|
246
|
+
return function (report) {
|
|
247
|
+
return function (assert) {
|
|
248
|
+
return function (location, modulo) { return __awaiter(_this, void 0, void 0, function () {
|
|
249
|
+
var _loop_1, _a, _b, _c, _i, key, state_1;
|
|
250
|
+
var _this = this;
|
|
251
|
+
return __generator(this, function (_d) {
|
|
252
|
+
switch (_d.label) {
|
|
253
|
+
case 0:
|
|
254
|
+
_loop_1 = function (key) {
|
|
255
|
+
var closure, func, label, result, _e, exp_1;
|
|
256
|
+
return __generator(this, function (_f) {
|
|
257
|
+
switch (_f.label) {
|
|
258
|
+
case 0:
|
|
259
|
+
if (key.substring(0, options.prefix.length) !== options.prefix)
|
|
260
|
+
return [2 /*return*/, "continue"];
|
|
261
|
+
else if (!(modulo[key] instanceof Function))
|
|
262
|
+
return [2 /*return*/, "continue"];
|
|
263
|
+
else if (options.filter && options.filter(key) === false)
|
|
264
|
+
return [2 /*return*/, "continue"];
|
|
265
|
+
closure = modulo[key];
|
|
266
|
+
func = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
267
|
+
return __generator(this, function (_a) {
|
|
268
|
+
switch (_a.label) {
|
|
269
|
+
case 0:
|
|
270
|
+
if (!(options.wrapper !== undefined)) return [3 /*break*/, 2];
|
|
271
|
+
return [4 /*yield*/, options.wrapper(key, closure)];
|
|
272
|
+
case 1:
|
|
273
|
+
_a.sent();
|
|
274
|
+
return [3 /*break*/, 4];
|
|
275
|
+
case 2: return [4 /*yield*/, closure.apply(void 0, __spreadArray([], __read(options.parameters(key)), false))];
|
|
276
|
+
case 3:
|
|
277
|
+
_a.sent();
|
|
278
|
+
_a.label = 4;
|
|
279
|
+
case 4: return [2 /*return*/];
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}); };
|
|
283
|
+
label = chalk_1.default.greenBright(key);
|
|
284
|
+
result = {
|
|
285
|
+
name: key,
|
|
286
|
+
location: location,
|
|
287
|
+
error: null,
|
|
288
|
+
time: Date.now(),
|
|
289
|
+
};
|
|
290
|
+
report.executions.push(result);
|
|
291
|
+
_f.label = 1;
|
|
292
|
+
case 1:
|
|
293
|
+
_f.trys.push([1, 6, , 7]);
|
|
294
|
+
if (!(options.showElapsedTime === false)) return [3 /*break*/, 3];
|
|
295
|
+
return [4 /*yield*/, func()];
|
|
296
|
+
case 2:
|
|
297
|
+
_f.sent();
|
|
298
|
+
result.time = Date.now() - result.time;
|
|
299
|
+
console.log(" - ".concat(label));
|
|
300
|
+
return [3 /*break*/, 5];
|
|
301
|
+
case 3:
|
|
302
|
+
_e = result;
|
|
303
|
+
return [4 /*yield*/, StopWatch_1.StopWatch.measure(func)];
|
|
304
|
+
case 4:
|
|
305
|
+
_e.time = _f.sent();
|
|
306
|
+
console.log(" - ".concat(label, ": ").concat(chalk_1.default.yellowBright(result.time.toLocaleString()), " ms"));
|
|
307
|
+
_f.label = 5;
|
|
308
|
+
case 5: return [3 /*break*/, 7];
|
|
309
|
+
case 6:
|
|
310
|
+
exp_1 = _f.sent();
|
|
311
|
+
if (!(exp_1 instanceof Error))
|
|
312
|
+
return [2 /*return*/, { value: void 0 }];
|
|
313
|
+
result.time = Date.now() - result.time;
|
|
314
|
+
result.error = exp_1;
|
|
315
|
+
console.log(" - ".concat(label, " -> ").concat(chalk_1.default.redBright(exp_1.name)));
|
|
316
|
+
if (assert === true)
|
|
317
|
+
throw exp_1;
|
|
318
|
+
return [3 /*break*/, 7];
|
|
319
|
+
case 7: return [2 /*return*/];
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
};
|
|
323
|
+
_a = modulo;
|
|
324
|
+
_b = [];
|
|
325
|
+
for (_c in _a)
|
|
326
|
+
_b.push(_c);
|
|
327
|
+
_i = 0;
|
|
328
|
+
_d.label = 1;
|
|
329
|
+
case 1:
|
|
330
|
+
if (!(_i < _b.length)) return [3 /*break*/, 4];
|
|
331
|
+
_c = _b[_i];
|
|
332
|
+
if (!(_c in _a)) return [3 /*break*/, 3];
|
|
333
|
+
key = _c;
|
|
334
|
+
return [5 /*yield**/, _loop_1(key)];
|
|
335
|
+
case 2:
|
|
336
|
+
state_1 = _d.sent();
|
|
337
|
+
if (typeof state_1 === "object")
|
|
338
|
+
return [2 /*return*/, state_1.value];
|
|
339
|
+
_d.label = 3;
|
|
340
|
+
case 3:
|
|
341
|
+
_i++;
|
|
342
|
+
return [3 /*break*/, 1];
|
|
343
|
+
case 4: return [2 /*return*/];
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
}); };
|
|
353
347
|
};
|
|
354
348
|
};
|
|
355
349
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynamicExecutor.js","sourceRoot":"","sources":["../src/DynamicExecutor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA0B;AAC1B,
|
|
1
|
+
{"version":3,"file":"DynamicExecutor.js","sourceRoot":"","sources":["../src/DynamicExecutor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC;gDACvC,MAAM,CAAC,KAAK,GAAG,KAAG,CAAC;gDAEnB,OAAO,CAAC,GAAG,CAAC,cAAO,KAAK,iBAAO,eAAK,CAAC,SAAS,CAAC,KAAG,CAAC,IAAI,CAAC,CAAE,CAAC,CAAC;gDAC5D,IAAI,MAAM,KAAK,IAAI;oDAAE,MAAM,KAAG,CAAC;;;;;;qCA3CrB,MAAM;;;;;;;;;;;8DAAb,GAAG;;;;;;;;;;;;qBA8CjB;YA/CD,CA+CC;QAhDD,CAgDC;IAjDD,CAiDC,CAAC;IAKN,IAAM,SAAS,GAAW,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC1E,CAAC,EAvPgB,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAuP/B"}
|
package/package.json
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@nestia/e2e",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "E2E test utilify functions",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build": "rimraf lib && tsc",
|
|
8
|
-
"dev": "npm run build -- --watch",
|
|
9
|
-
"prettier": "prettier --write ./src/**/*.ts",
|
|
10
|
-
"test": "node lib/test"
|
|
11
|
-
},
|
|
12
|
-
"repository": {
|
|
13
|
-
"type": "git",
|
|
14
|
-
"url": "https://github.com/samchon/nestia"
|
|
15
|
-
},
|
|
16
|
-
"keywords": [
|
|
17
|
-
"e2e",
|
|
18
|
-
"nestia",
|
|
19
|
-
"nestjs",
|
|
20
|
-
"test",
|
|
21
|
-
"tdd",
|
|
22
|
-
"utility"
|
|
23
|
-
],
|
|
24
|
-
"author": "Jeongho Nam",
|
|
25
|
-
"license": "MIT",
|
|
26
|
-
"bugs": {
|
|
27
|
-
"url": "https://github.com/samchon/nestia/issues"
|
|
28
|
-
},
|
|
29
|
-
"homepage": "https://github.com/samchon/nestia#readme",
|
|
30
|
-
"devDependencies": {
|
|
31
|
-
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
|
|
32
|
-
"@types/cli": "^0.11.21",
|
|
33
|
-
"@types/node": "^18.11.18",
|
|
34
|
-
"prettier": "^2.8.3",
|
|
35
|
-
"rimraf": "^4.1.2",
|
|
36
|
-
"typescript": "^4.9.5"
|
|
37
|
-
},
|
|
38
|
-
"dependencies": {
|
|
39
|
-
"chalk": "^4.1.2",
|
|
40
|
-
"cli": "^1.0.1",
|
|
41
|
-
"tstl": "^2.5.13"
|
|
42
|
-
},
|
|
43
|
-
"files": [
|
|
44
|
-
"lib",
|
|
45
|
-
"src",
|
|
46
|
-
"!lib/test",
|
|
47
|
-
"!src/test",
|
|
48
|
-
"README.md",
|
|
49
|
-
"LICENSE",
|
|
50
|
-
"package.json"
|
|
51
|
-
]
|
|
52
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@nestia/e2e",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "E2E test utilify functions",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "rimraf lib && tsc",
|
|
8
|
+
"dev": "npm run build -- --watch",
|
|
9
|
+
"prettier": "prettier --write ./src/**/*.ts",
|
|
10
|
+
"test": "node lib/test"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/samchon/nestia"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"e2e",
|
|
18
|
+
"nestia",
|
|
19
|
+
"nestjs",
|
|
20
|
+
"test",
|
|
21
|
+
"tdd",
|
|
22
|
+
"utility"
|
|
23
|
+
],
|
|
24
|
+
"author": "Jeongho Nam",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/samchon/nestia/issues"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/samchon/nestia#readme",
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
|
|
32
|
+
"@types/cli": "^0.11.21",
|
|
33
|
+
"@types/node": "^18.11.18",
|
|
34
|
+
"prettier": "^2.8.3",
|
|
35
|
+
"rimraf": "^4.1.2",
|
|
36
|
+
"typescript": "^4.9.5"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"chalk": "^4.1.2",
|
|
40
|
+
"cli": "^1.0.1",
|
|
41
|
+
"tstl": "^2.5.13"
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"lib",
|
|
45
|
+
"src",
|
|
46
|
+
"!lib/test",
|
|
47
|
+
"!src/test",
|
|
48
|
+
"README.md",
|
|
49
|
+
"LICENSE",
|
|
50
|
+
"package.json"
|
|
51
|
+
]
|
|
52
|
+
}
|
package/src/ArrayUtil.ts
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility functions for arrays.
|
|
3
|
-
*
|
|
4
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
5
|
-
*/
|
|
6
|
-
export namespace ArrayUtil {
|
|
7
|
-
export async function asyncFilter<Input>(
|
|
8
|
-
elements: readonly Input[],
|
|
9
|
-
pred: (
|
|
10
|
-
elem: Input,
|
|
11
|
-
index: number,
|
|
12
|
-
array: readonly Input[],
|
|
13
|
-
) => Promise<boolean>,
|
|
14
|
-
): Promise<Input[]> {
|
|
15
|
-
const ret: Input[] = [];
|
|
16
|
-
await asyncForEach(elements, async (elem, index, array) => {
|
|
17
|
-
const flag: boolean = await pred(elem, index, array);
|
|
18
|
-
if (flag === true) ret.push(elem);
|
|
19
|
-
});
|
|
20
|
-
return ret;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function asyncForEach<Input>(
|
|
24
|
-
elements: readonly Input[],
|
|
25
|
-
closure: (
|
|
26
|
-
elem: Input,
|
|
27
|
-
index: number,
|
|
28
|
-
array: readonly Input[],
|
|
29
|
-
) => Promise<any>,
|
|
30
|
-
): Promise<void> {
|
|
31
|
-
await asyncRepeat(elements.length, (index) =>
|
|
32
|
-
closure(elements[index], index, elements),
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export async function asyncMap<Input, Output>(
|
|
37
|
-
elements: readonly Input[],
|
|
38
|
-
closure: (
|
|
39
|
-
elem: Input,
|
|
40
|
-
index: number,
|
|
41
|
-
array: readonly Input[],
|
|
42
|
-
) => Promise<Output>,
|
|
43
|
-
): Promise<Output[]> {
|
|
44
|
-
const ret: Output[] = [];
|
|
45
|
-
await asyncForEach(elements, async (elem, index, array) => {
|
|
46
|
-
const output: Output = await closure(elem, index, array);
|
|
47
|
-
ret.push(output);
|
|
48
|
-
});
|
|
49
|
-
return ret;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export async function asyncRepeat<T>(
|
|
53
|
-
count: number,
|
|
54
|
-
closure: (index: number) => Promise<T>,
|
|
55
|
-
): Promise<T[]> {
|
|
56
|
-
const indexes: number[] = new Array(count)
|
|
57
|
-
.fill(1)
|
|
58
|
-
.map((_, index) => index);
|
|
59
|
-
|
|
60
|
-
const output: T[] = [];
|
|
61
|
-
for (const index of indexes) output.push(await closure(index));
|
|
62
|
-
|
|
63
|
-
return output;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function has<T>(
|
|
67
|
-
elements: readonly T[],
|
|
68
|
-
pred: (elem: T) => boolean,
|
|
69
|
-
): boolean {
|
|
70
|
-
return elements.find(pred) !== undefined;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function repeat<T>(
|
|
74
|
-
count: number,
|
|
75
|
-
closure: (index: number) => T,
|
|
76
|
-
): T[] {
|
|
77
|
-
return new Array(count).fill("").map((_, index) => closure(index));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function last<T>(array: T[]): T {
|
|
81
|
-
return array[array.length - 1];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function flat<T>(matrix: T[][]): T[] {
|
|
85
|
-
return ([] as T[]).concat(...matrix);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for arrays.
|
|
3
|
+
*
|
|
4
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
5
|
+
*/
|
|
6
|
+
export namespace ArrayUtil {
|
|
7
|
+
export async function asyncFilter<Input>(
|
|
8
|
+
elements: readonly Input[],
|
|
9
|
+
pred: (
|
|
10
|
+
elem: Input,
|
|
11
|
+
index: number,
|
|
12
|
+
array: readonly Input[],
|
|
13
|
+
) => Promise<boolean>,
|
|
14
|
+
): Promise<Input[]> {
|
|
15
|
+
const ret: Input[] = [];
|
|
16
|
+
await asyncForEach(elements, async (elem, index, array) => {
|
|
17
|
+
const flag: boolean = await pred(elem, index, array);
|
|
18
|
+
if (flag === true) ret.push(elem);
|
|
19
|
+
});
|
|
20
|
+
return ret;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function asyncForEach<Input>(
|
|
24
|
+
elements: readonly Input[],
|
|
25
|
+
closure: (
|
|
26
|
+
elem: Input,
|
|
27
|
+
index: number,
|
|
28
|
+
array: readonly Input[],
|
|
29
|
+
) => Promise<any>,
|
|
30
|
+
): Promise<void> {
|
|
31
|
+
await asyncRepeat(elements.length, (index) =>
|
|
32
|
+
closure(elements[index], index, elements),
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function asyncMap<Input, Output>(
|
|
37
|
+
elements: readonly Input[],
|
|
38
|
+
closure: (
|
|
39
|
+
elem: Input,
|
|
40
|
+
index: number,
|
|
41
|
+
array: readonly Input[],
|
|
42
|
+
) => Promise<Output>,
|
|
43
|
+
): Promise<Output[]> {
|
|
44
|
+
const ret: Output[] = [];
|
|
45
|
+
await asyncForEach(elements, async (elem, index, array) => {
|
|
46
|
+
const output: Output = await closure(elem, index, array);
|
|
47
|
+
ret.push(output);
|
|
48
|
+
});
|
|
49
|
+
return ret;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function asyncRepeat<T>(
|
|
53
|
+
count: number,
|
|
54
|
+
closure: (index: number) => Promise<T>,
|
|
55
|
+
): Promise<T[]> {
|
|
56
|
+
const indexes: number[] = new Array(count)
|
|
57
|
+
.fill(1)
|
|
58
|
+
.map((_, index) => index);
|
|
59
|
+
|
|
60
|
+
const output: T[] = [];
|
|
61
|
+
for (const index of indexes) output.push(await closure(index));
|
|
62
|
+
|
|
63
|
+
return output;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function has<T>(
|
|
67
|
+
elements: readonly T[],
|
|
68
|
+
pred: (elem: T) => boolean,
|
|
69
|
+
): boolean {
|
|
70
|
+
return elements.find(pred) !== undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function repeat<T>(
|
|
74
|
+
count: number,
|
|
75
|
+
closure: (index: number) => T,
|
|
76
|
+
): T[] {
|
|
77
|
+
return new Array(count).fill("").map((_, index) => closure(index));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function last<T>(array: T[]): T {
|
|
81
|
+
return array[array.length - 1];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function flat<T>(matrix: T[][]): T[] {
|
|
85
|
+
return ([] as T[]).concat(...matrix);
|
|
86
|
+
}
|
|
87
|
+
}
|