@coderzz/mocker-data-generator 3.0.5 → 3.0.6
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/CHANGELOG.md +41 -0
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/build/main/array-includes.d.ts +0 -0
- package/build/main/array-includes.js +45 -45
- package/build/main/index.d.ts +7 -7
- package/build/main/index.js +12 -12
- package/build/main/index.spec.d.ts +1 -1
- package/build/main/index.spec.js +16 -16
- package/build/main/lib/Generator.d.ts +61 -61
- package/build/main/lib/Generator.js +134 -134
- package/build/main/lib/Mocker.d.ts +22 -22
- package/build/main/lib/Mocker.js +76 -76
- package/build/main/lib/Schema.d.ts +9 -9
- package/build/main/lib/Schema.js +210 -210
- package/build/main/lib/types.d.ts +8 -8
- package/build/main/lib/types.js +2 -2
- package/build/main/lib/utils.d.ts +10 -10
- package/build/main/lib/utils.js +222 -222
- package/build/main/tests/Generator.db.spec.d.ts +1 -1
- package/build/main/tests/Generator.db.spec.js +33 -33
- package/build/main/tests/Generator.eval.spec.d.ts +1 -1
- package/build/main/tests/Generator.eval.spec.js +21 -21
- package/build/main/tests/Generator.function.spec.d.ts +1 -1
- package/build/main/tests/Generator.function.spec.js +48 -48
- package/build/main/tests/Generator.generator.spec.d.ts +1 -1
- package/build/main/tests/Generator.generator.spec.js +187 -187
- package/build/main/tests/Generator.hasMany.spec.d.ts +1 -1
- package/build/main/tests/Generator.hasMany.spec.js +115 -115
- package/build/main/tests/Generator.hasOne.spec.d.ts +1 -1
- package/build/main/tests/Generator.hasOne.spec.js +146 -146
- package/build/main/tests/Generator.incrementalId.spec.d.ts +1 -1
- package/build/main/tests/Generator.incrementalId.spec.js +26 -26
- package/build/main/tests/Generator.self.spec.d.ts +1 -1
- package/build/main/tests/Generator.self.spec.js +24 -24
- package/build/main/tests/Generator.static.spec.d.ts +1 -1
- package/build/main/tests/Generator.static.spec.js +15 -15
- package/build/main/tests/Generator.values.spec.d.ts +1 -1
- package/build/main/tests/Generator.values.spec.js +16 -16
- package/build/main/tests/Mocker.build.spec.d.ts +1 -1
- package/build/main/tests/Mocker.build.spec.js +196 -196
- package/build/main/tests/Mocker.reset.spec.d.ts +1 -1
- package/build/main/tests/Mocker.reset.spec.js +17 -17
- package/build/main/tests/Mocker.restart.spec.d.ts +1 -1
- package/build/main/tests/Mocker.restart.spec.js +24 -24
- package/build/main/tests/Mocker.schema.spec.d.ts +1 -1
- package/build/main/tests/Mocker.schema.spec.js +18 -18
- package/build/main/tests/Mocker.seed.spec.d.ts +1 -1
- package/build/main/tests/Mocker.seed.spec.js +42 -42
- package/build/main/tests/Schema.Array.spec.d.ts +1 -1
- package/build/main/tests/Schema.Array.spec.js +332 -332
- package/build/main/tests/Schema.BuildSingle.spec.d.ts +1 -1
- package/build/main/tests/Schema.BuildSingle.spec.js +13 -13
- package/build/main/tests/mocker.spec.d.ts +1 -1
- package/build/main/tests/mocker.spec.js +405 -405
- package/build/module/array-includes.js +45 -45
- package/build/module/index.js +7 -7
- package/build/module/lib/Generator.js +131 -131
- package/build/module/lib/Mocker.js +73 -73
- package/build/module/lib/Schema.js +207 -207
- package/build/module/lib/types.js +1 -1
- package/build/module/lib/utils.js +209 -209
- package/package.json +1 -1
@@ -1,10 +1,10 @@
|
|
1
|
-
export declare const isArray: (arg: any) => boolean;
|
2
|
-
export declare const isObject: (arg: any) => boolean;
|
3
|
-
export declare const evalWithContextData: (key: string, object: {}, db: {}, generators: {}) => any;
|
4
|
-
export declare const fieldArrayCalcLength: (config: any, fixedArrayLength: any, schema: any) => any;
|
5
|
-
export declare const iamLastChild: (parent: any, k: any) => boolean;
|
6
|
-
export declare const iamLastParent: (obj: any) => boolean;
|
7
|
-
export declare const isConditional: (str: any) => boolean;
|
8
|
-
export declare const cleanVirtuals: (paths: any, object: any, options: any) => any;
|
9
|
-
export declare const stringToPathOrCall: (name: any, fn: any, cfg: any) => any;
|
10
|
-
export declare const loopInside: (object: any, path: string) => any;
|
1
|
+
export declare const isArray: (arg: any) => boolean;
|
2
|
+
export declare const isObject: (arg: any) => boolean;
|
3
|
+
export declare const evalWithContextData: (key: string, object: {}, db: {}, generators: {}) => any;
|
4
|
+
export declare const fieldArrayCalcLength: (config: any, fixedArrayLength: any, schema: any) => any;
|
5
|
+
export declare const iamLastChild: (parent: any, k: any) => boolean;
|
6
|
+
export declare const iamLastParent: (obj: any) => boolean;
|
7
|
+
export declare const isConditional: (str: any) => boolean;
|
8
|
+
export declare const cleanVirtuals: (paths: any, object: any, options: any) => any;
|
9
|
+
export declare const stringToPathOrCall: (name: any, fn: any, cfg: any) => any;
|
10
|
+
export declare const loopInside: (object: any, path: string) => any;
|
package/build/main/lib/utils.js
CHANGED
@@ -1,222 +1,222 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.loopInside = exports.stringToPathOrCall = exports.cleanVirtuals = exports.isConditional = exports.iamLastParent = exports.iamLastChild = exports.fieldArrayCalcLength = exports.evalWithContextData = exports.isObject = exports.isArray = void 0;
|
4
|
-
var tslib_1 = require("tslib");
|
5
|
-
var isArray = function (arg) {
|
6
|
-
return Object.prototype.toString.call(arg) === '[object Array]';
|
7
|
-
};
|
8
|
-
exports.isArray = isArray;
|
9
|
-
var isObject = function (arg) {
|
10
|
-
return Object.prototype.toString.call(arg) === '[object Object]';
|
11
|
-
};
|
12
|
-
exports.isObject = isObject;
|
13
|
-
var evalWithContextData = function (key, object, db, generators) {
|
14
|
-
// In this (way, we can pass object and use inside the eval string
|
15
|
-
return eval(key);
|
16
|
-
};
|
17
|
-
exports.evalWithContextData = evalWithContextData;
|
18
|
-
var fieldArrayCalcLength = function (config, fixedArrayLength, schema) {
|
19
|
-
var length;
|
20
|
-
if (typeof config.length === 'function') {
|
21
|
-
length = config.length.call(schema);
|
22
|
-
}
|
23
|
-
else if (config.fixedLength) {
|
24
|
-
length = config.length - fixedArrayLength;
|
25
|
-
}
|
26
|
-
else {
|
27
|
-
length = Math.floor(Math.random() * config.length + 1);
|
28
|
-
}
|
29
|
-
return length;
|
30
|
-
};
|
31
|
-
exports.fieldArrayCalcLength = fieldArrayCalcLength;
|
32
|
-
var iamLastChild = function (parent, k) {
|
33
|
-
if ((0, exports.isArray)(parent[k])) {
|
34
|
-
var last = false;
|
35
|
-
if (parent[k].length === 0) {
|
36
|
-
return true;
|
37
|
-
}
|
38
|
-
for (var i = 0; i < parent[k].length; i++) {
|
39
|
-
var el = parent[k][i];
|
40
|
-
last = !(0, exports.isObject)(el);
|
41
|
-
if (last) {
|
42
|
-
break;
|
43
|
-
}
|
44
|
-
}
|
45
|
-
return last;
|
46
|
-
}
|
47
|
-
else {
|
48
|
-
return !(0, exports.isObject)(parent[k]);
|
49
|
-
}
|
50
|
-
};
|
51
|
-
exports.iamLastChild = iamLastChild;
|
52
|
-
var iamLastParent = function (obj) {
|
53
|
-
var last = false;
|
54
|
-
if ((0, exports.isObject)(obj)) {
|
55
|
-
var ks = Object.keys(obj);
|
56
|
-
for (var i = 0; i < ks.length; i++) {
|
57
|
-
var k = ks[i];
|
58
|
-
last = (0, exports.iamLastChild)(obj, k);
|
59
|
-
if (!last) {
|
60
|
-
break;
|
61
|
-
}
|
62
|
-
}
|
63
|
-
}
|
64
|
-
else {
|
65
|
-
last = true;
|
66
|
-
}
|
67
|
-
return last;
|
68
|
-
};
|
69
|
-
exports.iamLastParent = iamLastParent;
|
70
|
-
var isConditional = function (str) {
|
71
|
-
var arr = str.split(',');
|
72
|
-
return arr.length > 1;
|
73
|
-
};
|
74
|
-
exports.isConditional = isConditional;
|
75
|
-
var cleanVirtuals = function (paths, object, options) {
|
76
|
-
// clean specific paths
|
77
|
-
var objectCleaner = function (path, obj, options) {
|
78
|
-
var lvls, dest, i, field;
|
79
|
-
return tslib_1.__generator(this, function (_a) {
|
80
|
-
switch (_a.label) {
|
81
|
-
case 0:
|
82
|
-
lvls = path.split(options.symbol);
|
83
|
-
dest = obj;
|
84
|
-
if (!lvls || lvls.length === 0) {
|
85
|
-
return [2 /*return*/];
|
86
|
-
}
|
87
|
-
if (!obj) {
|
88
|
-
return [2 /*return*/];
|
89
|
-
}
|
90
|
-
for (i = 0; i < lvls.length; i++) {
|
91
|
-
field = lvls[i];
|
92
|
-
if (i === lvls.length - 1 && dest[field]) {
|
93
|
-
if (Object.getOwnPropertyNames(dest[field]).length < 1) {
|
94
|
-
delete dest[field];
|
95
|
-
break;
|
96
|
-
}
|
97
|
-
}
|
98
|
-
else {
|
99
|
-
dest = dest[field];
|
100
|
-
}
|
101
|
-
}
|
102
|
-
lvls.pop();
|
103
|
-
if (!(lvls.length > 0)) return [3 /*break*/, 2];
|
104
|
-
return [5 /*yield**/, tslib_1.__values(objectCleaner(lvls.join(options.symbol), obj, options))];
|
105
|
-
case 1:
|
106
|
-
_a.sent();
|
107
|
-
return [3 /*break*/, 3];
|
108
|
-
case 2: return [2 /*return*/];
|
109
|
-
case 3: return [2 /*return*/];
|
110
|
-
}
|
111
|
-
});
|
112
|
-
};
|
113
|
-
var forEachPath = function (path, object, options) {
|
114
|
-
var lvls, dest, i, field;
|
115
|
-
return tslib_1.__generator(this, function (_a) {
|
116
|
-
switch (_a.label) {
|
117
|
-
case 0:
|
118
|
-
lvls = path.split(options.symbol);
|
119
|
-
dest = object;
|
120
|
-
i = 0;
|
121
|
-
_a.label = 1;
|
122
|
-
case 1:
|
123
|
-
if (!(i < lvls.length)) return [3 /*break*/, 5];
|
124
|
-
field = lvls[i];
|
125
|
-
if (!(i === lvls.length - 1)) return [3 /*break*/, 3];
|
126
|
-
// delete specific path
|
127
|
-
delete dest[field];
|
128
|
-
// clean specific path
|
129
|
-
return [5 /*yield**/, tslib_1.__values(objectCleaner(path, object, options))];
|
130
|
-
case 2:
|
131
|
-
// clean specific path
|
132
|
-
_a.sent();
|
133
|
-
return [3 /*break*/, 4];
|
134
|
-
case 3:
|
135
|
-
dest = dest[field];
|
136
|
-
_a.label = 4;
|
137
|
-
case 4:
|
138
|
-
i++;
|
139
|
-
return [3 /*break*/, 1];
|
140
|
-
case 5: return [2 /*return*/];
|
141
|
-
}
|
142
|
-
});
|
143
|
-
};
|
144
|
-
var forPaths = function (paths, object, options) {
|
145
|
-
var i, path;
|
146
|
-
return tslib_1.__generator(this, function (_a) {
|
147
|
-
switch (_a.label) {
|
148
|
-
case 0:
|
149
|
-
i = 0;
|
150
|
-
_a.label = 1;
|
151
|
-
case 1:
|
152
|
-
if (!(i < paths.length)) return [3 /*break*/, 4];
|
153
|
-
path = paths[i];
|
154
|
-
return [5 /*yield**/, tslib_1.__values(Array.from(forEachPath(path, object, options)))];
|
155
|
-
case 2:
|
156
|
-
_a.sent();
|
157
|
-
_a.label = 3;
|
158
|
-
case 3:
|
159
|
-
i++;
|
160
|
-
return [3 /*break*/, 1];
|
161
|
-
case 4: return [2 /*return*/];
|
162
|
-
}
|
163
|
-
});
|
164
|
-
};
|
165
|
-
for (var _i = 0, _a = Array.from(forPaths(paths, object, options)); _i < _a.length; _i++) {
|
166
|
-
var res = _a[_i];
|
167
|
-
}
|
168
|
-
return object;
|
169
|
-
};
|
170
|
-
exports.cleanVirtuals = cleanVirtuals;
|
171
|
-
var stringToPathOrCall = function (name, fn, cfg) {
|
172
|
-
var _a = cfg.split('('), body = _a[0], args = _a[1];
|
173
|
-
body = body.split('.');
|
174
|
-
var func = body.reduce(function (acc, val) {
|
175
|
-
if (!acc[val]) {
|
176
|
-
throw "This ".concat(name, " method doesnt exists '").concat(cfg, "'.");
|
177
|
-
}
|
178
|
-
return acc[val];
|
179
|
-
}, fn);
|
180
|
-
if (!args) {
|
181
|
-
if (typeof func === 'function') {
|
182
|
-
return func.call(this);
|
183
|
-
}
|
184
|
-
else {
|
185
|
-
return func;
|
186
|
-
}
|
187
|
-
}
|
188
|
-
var _b = args.split(')'), args2 = _b[0], mods = _b[1];
|
189
|
-
args = args2
|
190
|
-
? args2[0] === '{'
|
191
|
-
? [JSON.parse(args2)]
|
192
|
-
: args2
|
193
|
-
.split(',')
|
194
|
-
.map(function (e) { return (/^\d+$/.test(e) ? Number.parseInt(e) : e); })
|
195
|
-
: [];
|
196
|
-
var result = func.call.apply(func, tslib_1.__spreadArray([this], args, false));
|
197
|
-
if (!mods || mods === '') {
|
198
|
-
return result;
|
199
|
-
}
|
200
|
-
mods = mods
|
201
|
-
.split('[')
|
202
|
-
.filter(function (i) { return i !== ''; })
|
203
|
-
.map(function (i) { return i.slice(0, -1); })
|
204
|
-
.map(function (i) { return (i[0] === '"' ? i.slice(1, -1) : parseInt(i, 10)); });
|
205
|
-
return mods.reduce(function (acc, val) {
|
206
|
-
if (!acc[val]) {
|
207
|
-
throw "'".concat(acc, "' doesnt have key '").concat(val, "'.");
|
208
|
-
}
|
209
|
-
return acc[val];
|
210
|
-
}, result);
|
211
|
-
};
|
212
|
-
exports.stringToPathOrCall = stringToPathOrCall;
|
213
|
-
var loopInside = function (object, path) {
|
214
|
-
var p = path.split('.');
|
215
|
-
return p.reduce(function (acc, val) {
|
216
|
-
if (acc[val] === null) {
|
217
|
-
throw "'".concat(acc, "' doesnt have key '").concat(val, "'.");
|
218
|
-
}
|
219
|
-
return acc[val];
|
220
|
-
}, object);
|
221
|
-
};
|
222
|
-
exports.loopInside = loopInside;
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.loopInside = exports.stringToPathOrCall = exports.cleanVirtuals = exports.isConditional = exports.iamLastParent = exports.iamLastChild = exports.fieldArrayCalcLength = exports.evalWithContextData = exports.isObject = exports.isArray = void 0;
|
4
|
+
var tslib_1 = require("tslib");
|
5
|
+
var isArray = function (arg) {
|
6
|
+
return Object.prototype.toString.call(arg) === '[object Array]';
|
7
|
+
};
|
8
|
+
exports.isArray = isArray;
|
9
|
+
var isObject = function (arg) {
|
10
|
+
return Object.prototype.toString.call(arg) === '[object Object]';
|
11
|
+
};
|
12
|
+
exports.isObject = isObject;
|
13
|
+
var evalWithContextData = function (key, object, db, generators) {
|
14
|
+
// In this (way, we can pass object and use inside the eval string
|
15
|
+
return eval(key);
|
16
|
+
};
|
17
|
+
exports.evalWithContextData = evalWithContextData;
|
18
|
+
var fieldArrayCalcLength = function (config, fixedArrayLength, schema) {
|
19
|
+
var length;
|
20
|
+
if (typeof config.length === 'function') {
|
21
|
+
length = config.length.call(schema);
|
22
|
+
}
|
23
|
+
else if (config.fixedLength) {
|
24
|
+
length = config.length - fixedArrayLength;
|
25
|
+
}
|
26
|
+
else {
|
27
|
+
length = Math.floor(Math.random() * config.length + 1);
|
28
|
+
}
|
29
|
+
return length;
|
30
|
+
};
|
31
|
+
exports.fieldArrayCalcLength = fieldArrayCalcLength;
|
32
|
+
var iamLastChild = function (parent, k) {
|
33
|
+
if ((0, exports.isArray)(parent[k])) {
|
34
|
+
var last = false;
|
35
|
+
if (parent[k].length === 0) {
|
36
|
+
return true;
|
37
|
+
}
|
38
|
+
for (var i = 0; i < parent[k].length; i++) {
|
39
|
+
var el = parent[k][i];
|
40
|
+
last = !(0, exports.isObject)(el);
|
41
|
+
if (last) {
|
42
|
+
break;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
return last;
|
46
|
+
}
|
47
|
+
else {
|
48
|
+
return !(0, exports.isObject)(parent[k]);
|
49
|
+
}
|
50
|
+
};
|
51
|
+
exports.iamLastChild = iamLastChild;
|
52
|
+
var iamLastParent = function (obj) {
|
53
|
+
var last = false;
|
54
|
+
if ((0, exports.isObject)(obj)) {
|
55
|
+
var ks = Object.keys(obj);
|
56
|
+
for (var i = 0; i < ks.length; i++) {
|
57
|
+
var k = ks[i];
|
58
|
+
last = (0, exports.iamLastChild)(obj, k);
|
59
|
+
if (!last) {
|
60
|
+
break;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
else {
|
65
|
+
last = true;
|
66
|
+
}
|
67
|
+
return last;
|
68
|
+
};
|
69
|
+
exports.iamLastParent = iamLastParent;
|
70
|
+
var isConditional = function (str) {
|
71
|
+
var arr = str.split(',');
|
72
|
+
return arr.length > 1;
|
73
|
+
};
|
74
|
+
exports.isConditional = isConditional;
|
75
|
+
var cleanVirtuals = function (paths, object, options) {
|
76
|
+
// clean specific paths
|
77
|
+
var objectCleaner = function (path, obj, options) {
|
78
|
+
var lvls, dest, i, field;
|
79
|
+
return tslib_1.__generator(this, function (_a) {
|
80
|
+
switch (_a.label) {
|
81
|
+
case 0:
|
82
|
+
lvls = path.split(options.symbol);
|
83
|
+
dest = obj;
|
84
|
+
if (!lvls || lvls.length === 0) {
|
85
|
+
return [2 /*return*/];
|
86
|
+
}
|
87
|
+
if (!obj) {
|
88
|
+
return [2 /*return*/];
|
89
|
+
}
|
90
|
+
for (i = 0; i < lvls.length; i++) {
|
91
|
+
field = lvls[i];
|
92
|
+
if (i === lvls.length - 1 && dest[field]) {
|
93
|
+
if (Object.getOwnPropertyNames(dest[field]).length < 1) {
|
94
|
+
delete dest[field];
|
95
|
+
break;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
else {
|
99
|
+
dest = dest[field];
|
100
|
+
}
|
101
|
+
}
|
102
|
+
lvls.pop();
|
103
|
+
if (!(lvls.length > 0)) return [3 /*break*/, 2];
|
104
|
+
return [5 /*yield**/, tslib_1.__values(objectCleaner(lvls.join(options.symbol), obj, options))];
|
105
|
+
case 1:
|
106
|
+
_a.sent();
|
107
|
+
return [3 /*break*/, 3];
|
108
|
+
case 2: return [2 /*return*/];
|
109
|
+
case 3: return [2 /*return*/];
|
110
|
+
}
|
111
|
+
});
|
112
|
+
};
|
113
|
+
var forEachPath = function (path, object, options) {
|
114
|
+
var lvls, dest, i, field;
|
115
|
+
return tslib_1.__generator(this, function (_a) {
|
116
|
+
switch (_a.label) {
|
117
|
+
case 0:
|
118
|
+
lvls = path.split(options.symbol);
|
119
|
+
dest = object;
|
120
|
+
i = 0;
|
121
|
+
_a.label = 1;
|
122
|
+
case 1:
|
123
|
+
if (!(i < lvls.length)) return [3 /*break*/, 5];
|
124
|
+
field = lvls[i];
|
125
|
+
if (!(i === lvls.length - 1)) return [3 /*break*/, 3];
|
126
|
+
// delete specific path
|
127
|
+
delete dest[field];
|
128
|
+
// clean specific path
|
129
|
+
return [5 /*yield**/, tslib_1.__values(objectCleaner(path, object, options))];
|
130
|
+
case 2:
|
131
|
+
// clean specific path
|
132
|
+
_a.sent();
|
133
|
+
return [3 /*break*/, 4];
|
134
|
+
case 3:
|
135
|
+
dest = dest[field];
|
136
|
+
_a.label = 4;
|
137
|
+
case 4:
|
138
|
+
i++;
|
139
|
+
return [3 /*break*/, 1];
|
140
|
+
case 5: return [2 /*return*/];
|
141
|
+
}
|
142
|
+
});
|
143
|
+
};
|
144
|
+
var forPaths = function (paths, object, options) {
|
145
|
+
var i, path;
|
146
|
+
return tslib_1.__generator(this, function (_a) {
|
147
|
+
switch (_a.label) {
|
148
|
+
case 0:
|
149
|
+
i = 0;
|
150
|
+
_a.label = 1;
|
151
|
+
case 1:
|
152
|
+
if (!(i < paths.length)) return [3 /*break*/, 4];
|
153
|
+
path = paths[i];
|
154
|
+
return [5 /*yield**/, tslib_1.__values(Array.from(forEachPath(path, object, options)))];
|
155
|
+
case 2:
|
156
|
+
_a.sent();
|
157
|
+
_a.label = 3;
|
158
|
+
case 3:
|
159
|
+
i++;
|
160
|
+
return [3 /*break*/, 1];
|
161
|
+
case 4: return [2 /*return*/];
|
162
|
+
}
|
163
|
+
});
|
164
|
+
};
|
165
|
+
for (var _i = 0, _a = Array.from(forPaths(paths, object, options)); _i < _a.length; _i++) {
|
166
|
+
var res = _a[_i];
|
167
|
+
}
|
168
|
+
return object;
|
169
|
+
};
|
170
|
+
exports.cleanVirtuals = cleanVirtuals;
|
171
|
+
var stringToPathOrCall = function (name, fn, cfg) {
|
172
|
+
var _a = cfg.split('('), body = _a[0], args = _a[1];
|
173
|
+
body = body.split('.');
|
174
|
+
var func = body.reduce(function (acc, val) {
|
175
|
+
if (!acc[val]) {
|
176
|
+
throw "This ".concat(name, " method doesnt exists '").concat(cfg, "'.");
|
177
|
+
}
|
178
|
+
return acc[val];
|
179
|
+
}, fn);
|
180
|
+
if (!args) {
|
181
|
+
if (typeof func === 'function') {
|
182
|
+
return func.call(this);
|
183
|
+
}
|
184
|
+
else {
|
185
|
+
return func;
|
186
|
+
}
|
187
|
+
}
|
188
|
+
var _b = args.split(')'), args2 = _b[0], mods = _b[1];
|
189
|
+
args = args2
|
190
|
+
? args2[0] === '{'
|
191
|
+
? [JSON.parse(args2)]
|
192
|
+
: args2
|
193
|
+
.split(',')
|
194
|
+
.map(function (e) { return (/^\d+$/.test(e) ? Number.parseInt(e) : e); })
|
195
|
+
: [];
|
196
|
+
var result = func.call.apply(func, tslib_1.__spreadArray([this], args, false));
|
197
|
+
if (!mods || mods === '') {
|
198
|
+
return result;
|
199
|
+
}
|
200
|
+
mods = mods
|
201
|
+
.split('[')
|
202
|
+
.filter(function (i) { return i !== ''; })
|
203
|
+
.map(function (i) { return i.slice(0, -1); })
|
204
|
+
.map(function (i) { return (i[0] === '"' ? i.slice(1, -1) : parseInt(i, 10)); });
|
205
|
+
return mods.reduce(function (acc, val) {
|
206
|
+
if (!acc[val]) {
|
207
|
+
throw "'".concat(acc, "' doesnt have key '").concat(val, "'.");
|
208
|
+
}
|
209
|
+
return acc[val];
|
210
|
+
}, result);
|
211
|
+
};
|
212
|
+
exports.stringToPathOrCall = stringToPathOrCall;
|
213
|
+
var loopInside = function (object, path) {
|
214
|
+
var p = path.split('.');
|
215
|
+
return p.reduce(function (acc, val) {
|
216
|
+
if (acc[val] === null) {
|
217
|
+
throw "'".concat(acc, "' doesnt have key '").concat(val, "'.");
|
218
|
+
}
|
219
|
+
return acc[val];
|
220
|
+
}, object);
|
221
|
+
};
|
222
|
+
exports.loopInside = loopInside;
|
@@ -1 +1 @@
|
|
1
|
-
export {};
|
1
|
+
export {};
|
@@ -1,33 +1,33 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
var tslib_1 = require("tslib");
|
4
|
-
var ava_1 = require("ava");
|
5
|
-
var __1 = require("..");
|
6
|
-
var gen = new __1.Generator();
|
7
|
-
(0, ava_1.default)('Should have access to db', function (t) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
8
|
-
var res;
|
9
|
-
return tslib_1.__generator(this, function (_a) {
|
10
|
-
gen.DB = { hello: 'world' };
|
11
|
-
res = gen.db({ db: 'hello' });
|
12
|
-
t.true(res === 'world');
|
13
|
-
return [2 /*return*/];
|
14
|
-
});
|
15
|
-
}); });
|
16
|
-
(0, ava_1.default)('[eval] Should have access to db', function (t) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
17
|
-
var res;
|
18
|
-
return tslib_1.__generator(this, function (_a) {
|
19
|
-
gen.DB = { hello: 'world' };
|
20
|
-
res = gen.db({ db: 'hello', eval: true });
|
21
|
-
t.true(res === 'world');
|
22
|
-
return [2 /*return*/];
|
23
|
-
});
|
24
|
-
}); });
|
25
|
-
(0, ava_1.default)('Should have access to db (.0 syntax)', function (t) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
26
|
-
var res;
|
27
|
-
return tslib_1.__generator(this, function (_a) {
|
28
|
-
gen.DB = { hello: ['hello', 'world'] };
|
29
|
-
res = gen.db({ db: 'hello.0' });
|
30
|
-
t.true(res === 'hello');
|
31
|
-
return [2 /*return*/];
|
32
|
-
});
|
33
|
-
}); });
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
var tslib_1 = require("tslib");
|
4
|
+
var ava_1 = require("ava");
|
5
|
+
var __1 = require("..");
|
6
|
+
var gen = new __1.Generator();
|
7
|
+
(0, ava_1.default)('Should have access to db', function (t) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
8
|
+
var res;
|
9
|
+
return tslib_1.__generator(this, function (_a) {
|
10
|
+
gen.DB = { hello: 'world' };
|
11
|
+
res = gen.db({ db: 'hello' });
|
12
|
+
t.true(res === 'world');
|
13
|
+
return [2 /*return*/];
|
14
|
+
});
|
15
|
+
}); });
|
16
|
+
(0, ava_1.default)('[eval] Should have access to db', function (t) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
17
|
+
var res;
|
18
|
+
return tslib_1.__generator(this, function (_a) {
|
19
|
+
gen.DB = { hello: 'world' };
|
20
|
+
res = gen.db({ db: 'hello', eval: true });
|
21
|
+
t.true(res === 'world');
|
22
|
+
return [2 /*return*/];
|
23
|
+
});
|
24
|
+
}); });
|
25
|
+
(0, ava_1.default)('Should have access to db (.0 syntax)', function (t) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
26
|
+
var res;
|
27
|
+
return tslib_1.__generator(this, function (_a) {
|
28
|
+
gen.DB = { hello: ['hello', 'world'] };
|
29
|
+
res = gen.db({ db: 'hello.0' });
|
30
|
+
t.true(res === 'hello');
|
31
|
+
return [2 /*return*/];
|
32
|
+
});
|
33
|
+
}); });
|
@@ -1 +1 @@
|
|
1
|
-
export {};
|
1
|
+
export {};
|
@@ -1,21 +1,21 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
var tslib_1 = require("tslib");
|
4
|
-
var ava_1 = require("ava");
|
5
|
-
var __1 = require("..");
|
6
|
-
var gen = new __1.Generator();
|
7
|
-
gen.generators = {};
|
8
|
-
(0, ava_1.default)('Should have context {object, db, generators}', function (t) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
9
|
-
var ctx;
|
10
|
-
return tslib_1.__generator(this, function (_a) {
|
11
|
-
gen.DB = {};
|
12
|
-
gen.object = {};
|
13
|
-
ctx = ['object', 'db', 'generators'];
|
14
|
-
ctx.forEach(function (c) {
|
15
|
-
var res = gen.eval({ eval: c });
|
16
|
-
t.true(res !== undefined);
|
17
|
-
t.true(res !== null);
|
18
|
-
});
|
19
|
-
return [2 /*return*/];
|
20
|
-
});
|
21
|
-
}); });
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
var tslib_1 = require("tslib");
|
4
|
+
var ava_1 = require("ava");
|
5
|
+
var __1 = require("..");
|
6
|
+
var gen = new __1.Generator();
|
7
|
+
gen.generators = {};
|
8
|
+
(0, ava_1.default)('Should have context {object, db, generators}', function (t) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
9
|
+
var ctx;
|
10
|
+
return tslib_1.__generator(this, function (_a) {
|
11
|
+
gen.DB = {};
|
12
|
+
gen.object = {};
|
13
|
+
ctx = ['object', 'db', 'generators'];
|
14
|
+
ctx.forEach(function (c) {
|
15
|
+
var res = gen.eval({ eval: c });
|
16
|
+
t.true(res !== undefined);
|
17
|
+
t.true(res !== null);
|
18
|
+
});
|
19
|
+
return [2 /*return*/];
|
20
|
+
});
|
21
|
+
}); });
|
@@ -1 +1 @@
|
|
1
|
-
export {};
|
1
|
+
export {};
|