1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const fs_1 = require("fs");
|
5 | const glob_1 = tslib_1.__importDefault(require("glob"));
|
6 | const path_1 = require("path");
|
7 | const tinspector_1 = require("tinspector");
|
8 | String.prototype.format = function (...args) {
|
9 | return this.replace(/{(\d+)}/g, (m, i) => typeof args[i] != 'undefined' ? args[i] : m);
|
10 | };
|
11 | Array.prototype.flatten = function () {
|
12 | return this.reduce((a, b) => a.concat(b), []);
|
13 | };
|
14 | function hasKeyOf(opt, key) {
|
15 | return key in opt;
|
16 | }
|
17 | exports.hasKeyOf = hasKeyOf;
|
18 | function isCustomClass(type) {
|
19 | switch (Array.isArray(type) ? type[0] : type) {
|
20 | case undefined:
|
21 | case Boolean:
|
22 | case String:
|
23 | case Array:
|
24 | case Number:
|
25 | case Object:
|
26 | case Date:
|
27 | return false;
|
28 | default:
|
29 | return true;
|
30 | }
|
31 | }
|
32 | exports.isCustomClass = isCustomClass;
|
33 | function resolvePath(path) {
|
34 | const removeExtension = (x) => x.replace(/\.[^/.]+$/, "");
|
35 | if (fs_1.existsSync(`${path}.js`))
|
36 | return [removeExtension(path)];
|
37 | else if (fs_1.existsSync(`${path}.ts`))
|
38 | return [removeExtension(path)];
|
39 |
|
40 | else if (fs_1.lstatSync(path).isDirectory()) {
|
41 | const files = glob_1.default.sync(`${path}/**/*+(.js|.ts)`)
|
42 |
|
43 | .filter(x => [".js", ".ts"].some(ext => path_1.extname(x) == ext))
|
44 |
|
45 | .map(x => removeExtension(x));
|
46 | return Array.from(new Set(files));
|
47 | }
|
48 | else
|
49 | return [path];
|
50 | }
|
51 | exports.resolvePath = resolvePath;
|
52 | function reflectPath(path) {
|
53 | if (Array.isArray(path))
|
54 | return path.map(x => tinspector_1.reflect(x));
|
55 | else if (typeof path === "string")
|
56 | return resolvePath(path)
|
57 | .map(x => tinspector_1.reflect(x))
|
58 | .map(x => x.members)
|
59 | .flatten();
|
60 | else
|
61 | return [tinspector_1.reflect(path)];
|
62 | }
|
63 | exports.reflectPath = reflectPath;
|
64 | const log = console.log;
|
65 | var consoleLog;
|
66 | (function (consoleLog) {
|
67 | function startMock() {
|
68 | console.log = jest.fn(message => { });
|
69 | }
|
70 | consoleLog.startMock = startMock;
|
71 | function clearMock() {
|
72 | console.log = log;
|
73 | }
|
74 | consoleLog.clearMock = clearMock;
|
75 | })(consoleLog = exports.consoleLog || (exports.consoleLog = {}));
|
76 | function getChildValue(object, path, defaultValue) {
|
77 | return path
|
78 | .split(/[\.\[\]\'\"]/)
|
79 | .filter(p => p)
|
80 | .reduce((o, p) => o ? o[p] : defaultValue, object);
|
81 | }
|
82 | exports.getChildValue = getChildValue;
|
83 | function createRoute(...args) {
|
84 | return "/" + args
|
85 | .filter(x => !!x)
|
86 | .map(x => x.toLowerCase())
|
87 | .map(x => x.startsWith("/") ? x.slice(1) : x)
|
88 | .filter(x => !!x)
|
89 | .join("/");
|
90 | }
|
91 | exports.createRoute = createRoute;
|
92 | function mkdirp(path) {
|
93 | var dir = path_1.dirname(path);
|
94 | if (!fs_1.existsSync(dir)) {
|
95 | mkdirp(dir);
|
96 | }
|
97 | fs_1.mkdirSync(path);
|
98 | }
|
99 | exports.mkdirp = mkdirp;
|
100 |
|
101 | function safeToString(value) {
|
102 | try {
|
103 | return value.toString();
|
104 | }
|
105 | catch (e) {
|
106 | return "[object Object]";
|
107 | }
|
108 | }
|
109 | exports.safeToString = safeToString;
|