struct-fakerator 1.2.2 → 1.2.3
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/cjs/create_config.js +1 -1
- package/cjs/create_config.test.js +69 -0
- package/cjs/create_generator_fn.js +1 -1
- package/cjs/create_generator_fn.test.js +244 -0
- package/cjs/index.js +2 -2
- package/{src/create_config.js → esm/src/create_config.mjs} +1 -1
- package/{src/create_config.test.js → esm/src/create_config.test.mjs} +2 -2
- package/{src/create_generator_fn.js → esm/src/create_generator_fn.mjs} +1 -1
- package/{src/create_generator_fn.test.js → esm/src/create_generator_fn.test.mjs} +2 -2
- package/esm/src/index.mjs +2 -0
- package/package.json +4 -4
- package/src/config_scheme.mjs +45 -0
- package/src/create_config.mjs +97 -0
- package/src/create_config.test.mjs +72 -0
- package/src/create_generator_fn.mjs +140 -0
- package/src/create_generator_fn.test.mjs +192 -0
- package/src/index.mjs +2 -0
- package/{esm/type.js → src/type.mjs} +0 -1
- package/esm/config_scheme.js +0 -61
- package/esm/create_config.js +0 -98
- package/esm/create_generator_fn.js +0 -161
- package/esm/index.js +0 -27
- package/src/index.js +0 -2
- /package/{src/config_scheme.js → esm/src/config_scheme.mjs} +0 -0
- /package/{src/type.js → esm/src/type.mjs} +0 -0
package/cjs/create_config.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.createValueConfig = exports.createTupleConfig = exports.createSelectionConfig = exports.createObjectConfig = exports.createBoundedSeriesConfig = exports.createArrayConfig = void 0;
|
|
7
7
|
var _faker = require("@faker-js/faker");
|
|
8
|
-
var _config_scheme = require("./config_scheme.
|
|
8
|
+
var _config_scheme = require("./config_scheme.mjs");
|
|
9
9
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
10
10
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
11
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _create_config = require("./create_config.mjs");
|
|
5
|
+
var _create_generator_fn = require("./create_generator_fn.mjs");
|
|
6
|
+
(0, _vitest.test)("createValueConfig", function () {
|
|
7
|
+
var valueConfig = (0, _create_config.createValueConfig)(function () {
|
|
8
|
+
return 44;
|
|
9
|
+
});
|
|
10
|
+
(0, _vitest.expect)(valueConfig.type).toBe("value");
|
|
11
|
+
(0, _vitest.expect)(valueConfig.generateFn).toBeTypeOf("function");
|
|
12
|
+
});
|
|
13
|
+
(0, _vitest.test)("createSelectionConfig", function () {
|
|
14
|
+
var options = [1, 2, 3, 4];
|
|
15
|
+
var selectionConfig = (0, _create_config.createSelectionConfig)([1, 2, 3, 4]);
|
|
16
|
+
(0, _vitest.expect)(selectionConfig.type).toBe("select");
|
|
17
|
+
(0, _vitest.expect)(selectionConfig.items).toEqual(options);
|
|
18
|
+
});
|
|
19
|
+
(0, _vitest.test)("createArrayConfig", function () {
|
|
20
|
+
var valueConfig = (0, _create_config.createValueConfig)(function () {
|
|
21
|
+
return 44;
|
|
22
|
+
});
|
|
23
|
+
var arrConfig = (0, _create_config.createArrayConfig)(valueConfig, 20);
|
|
24
|
+
(0, _vitest.expect)(arrConfig.type).toBe("arr");
|
|
25
|
+
(0, _vitest.expect)(arrConfig.len).toBe(20);
|
|
26
|
+
(0, _vitest.expect)(arrConfig.item).toEqual(valueConfig);
|
|
27
|
+
});
|
|
28
|
+
(0, _vitest.test)("createTupleConfig", function () {
|
|
29
|
+
var value1Config = (0, _create_config.createValueConfig)(function () {
|
|
30
|
+
return 123;
|
|
31
|
+
});
|
|
32
|
+
var value2Config = (0, _create_config.createValueConfig)(function () {
|
|
33
|
+
return "hello";
|
|
34
|
+
});
|
|
35
|
+
var tupleConfig = (0, _create_config.createTupleConfig)([value1Config, value2Config]);
|
|
36
|
+
(0, _vitest.expect)(tupleConfig.type).toBe("tuple");
|
|
37
|
+
(0, _vitest.expect)(tupleConfig.configItems).toEqual([value1Config, value2Config]);
|
|
38
|
+
});
|
|
39
|
+
(0, _vitest.test)("createObjConfig", function () {
|
|
40
|
+
var value1Config = (0, _create_config.createValueConfig)(function () {
|
|
41
|
+
return 32;
|
|
42
|
+
});
|
|
43
|
+
var value2Config = (0, _create_config.createValueConfig)(function () {
|
|
44
|
+
return "frank";
|
|
45
|
+
});
|
|
46
|
+
var objConfig = (0, _create_config.createObjectConfig)({
|
|
47
|
+
name: value2Config,
|
|
48
|
+
age: value1Config
|
|
49
|
+
});
|
|
50
|
+
(0, _vitest.expect)(objConfig.type).toBe("obj");
|
|
51
|
+
(0, _vitest.expect)(objConfig.content).toEqual({
|
|
52
|
+
name: value2Config,
|
|
53
|
+
age: value1Config
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
(0, _vitest.test)("createBoundedSeriesConfig", function () {
|
|
57
|
+
var boundedSeriesConfig = (0, _create_config.createBoundedSeriesConfig)({
|
|
58
|
+
count: 1,
|
|
59
|
+
upperLimit: 1.2,
|
|
60
|
+
lowerLimit: 1.0,
|
|
61
|
+
createInitValue: function createInitValue() {
|
|
62
|
+
return 40;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
(0, _vitest.expect)(boundedSeriesConfig.type).toBe("bounded_series");
|
|
66
|
+
(0, _vitest.expect)(boundedSeriesConfig.upperLimit).toBe(1.2);
|
|
67
|
+
(0, _vitest.expect)(boundedSeriesConfig.lowerLimit).toBe(1.0);
|
|
68
|
+
(0, _vitest.expect)(boundedSeriesConfig.createInitValue).toBeTypeOf("function");
|
|
69
|
+
});
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.createValueGenerator = exports.createTupleGenerator = exports.createSelectionGenerator = exports.createObjectGenerator = exports.createGeneratorByType = exports.createBoundedSeriesGenerator = exports.createArrayGenerator = void 0;
|
|
7
7
|
var _faker = require("@faker-js/faker");
|
|
8
|
-
var _config_scheme = require("./config_scheme.
|
|
8
|
+
var _config_scheme = require("./config_scheme.mjs");
|
|
9
9
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
10
10
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
11
11
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _zod = require("zod");
|
|
5
|
+
var _create_generator_fn = require("./create_generator_fn.mjs");
|
|
6
|
+
var _create_config = require("./create_config.mjs");
|
|
7
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
8
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
10
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
11
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
12
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
13
|
+
(0, _vitest.describe)("createValueGenerator", function () {
|
|
14
|
+
(0, _vitest.test)("normal", function () {
|
|
15
|
+
var value = (0, _create_generator_fn.createValueGenerator)({
|
|
16
|
+
type: "value",
|
|
17
|
+
generateFn: function generateFn() {
|
|
18
|
+
return 50;
|
|
19
|
+
}
|
|
20
|
+
})();
|
|
21
|
+
(0, _vitest.expect)(value).toBe(50);
|
|
22
|
+
var value2 = (0, _create_generator_fn.createValueGenerator)({
|
|
23
|
+
type: "value",
|
|
24
|
+
generateFn: function generateFn() {
|
|
25
|
+
return {
|
|
26
|
+
age: 100,
|
|
27
|
+
name: "hello"
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
})();
|
|
31
|
+
(0, _vitest.expect)(value2).toEqual({
|
|
32
|
+
age: 100,
|
|
33
|
+
name: "hello"
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
(0, _vitest.describe)("createSelectionGenerator", function () {
|
|
38
|
+
(0, _vitest.test)("normal", function () {
|
|
39
|
+
var value = (0, _create_generator_fn.createSelectionGenerator)({
|
|
40
|
+
type: "select",
|
|
41
|
+
items: [1]
|
|
42
|
+
})();
|
|
43
|
+
(0, _vitest.expect)(value).toBe(1);
|
|
44
|
+
var value2 = (0, _create_generator_fn.createSelectionGenerator)({
|
|
45
|
+
type: "select",
|
|
46
|
+
items: [30, 30, 30, 30]
|
|
47
|
+
})();
|
|
48
|
+
(0, _vitest.expect)(value2).toBe(30);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
(0, _vitest.describe)("createArrayGenerator", function () {
|
|
52
|
+
(0, _vitest.test)("normal", function () {
|
|
53
|
+
var list = (0, _create_generator_fn.createArrayGenerator)({
|
|
54
|
+
type: "arr",
|
|
55
|
+
len: 5,
|
|
56
|
+
item: {
|
|
57
|
+
type: "value",
|
|
58
|
+
generateFn: function generateFn() {
|
|
59
|
+
return {
|
|
60
|
+
age: 42
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
})();
|
|
65
|
+
(0, _vitest.expect)(list).toEqual([{
|
|
66
|
+
age: 42
|
|
67
|
+
}, {
|
|
68
|
+
age: 42
|
|
69
|
+
}, {
|
|
70
|
+
age: 42
|
|
71
|
+
}, {
|
|
72
|
+
age: 42
|
|
73
|
+
}, {
|
|
74
|
+
age: 42
|
|
75
|
+
}]);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
(0, _vitest.describe)("createTupleGenerator", function () {
|
|
79
|
+
(0, _vitest.test)("normal", function () {
|
|
80
|
+
var tuple = (0, _create_generator_fn.createTupleGenerator)({
|
|
81
|
+
type: "tuple",
|
|
82
|
+
configItems: [{
|
|
83
|
+
type: "value",
|
|
84
|
+
generateFn: function generateFn() {
|
|
85
|
+
return 225;
|
|
86
|
+
}
|
|
87
|
+
}, {
|
|
88
|
+
type: "value",
|
|
89
|
+
generateFn: function generateFn() {
|
|
90
|
+
return "hello world";
|
|
91
|
+
}
|
|
92
|
+
}]
|
|
93
|
+
})();
|
|
94
|
+
(0, _vitest.expect)(tuple.length).toBe(2);
|
|
95
|
+
var _tuple = _slicedToArray(tuple, 2),
|
|
96
|
+
num = _tuple[0],
|
|
97
|
+
str = _tuple[1];
|
|
98
|
+
(0, _vitest.expect)(num).toBe(225);
|
|
99
|
+
(0, _vitest.expect)(str).toBe("hello world");
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
(0, _vitest.describe)("createObjectGenerator", function () {
|
|
103
|
+
(0, _vitest.test)("normal", function () {
|
|
104
|
+
var obj = (0, _create_generator_fn.createObjectGenerator)({
|
|
105
|
+
type: "obj",
|
|
106
|
+
content: {
|
|
107
|
+
name: {
|
|
108
|
+
type: "value",
|
|
109
|
+
generateFn: function generateFn() {
|
|
110
|
+
return "John";
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
age: {
|
|
114
|
+
type: "value",
|
|
115
|
+
generateFn: function generateFn() {
|
|
116
|
+
return 50;
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
location: {
|
|
120
|
+
type: "value",
|
|
121
|
+
generateFn: function generateFn() {
|
|
122
|
+
return "Taiwan";
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
})();
|
|
127
|
+
(0, _vitest.expect)(obj).toEqual({
|
|
128
|
+
name: "John",
|
|
129
|
+
age: 50,
|
|
130
|
+
location: "Taiwan"
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
(0, _vitest.describe)("createBoundedSeriesGenerator", function () {
|
|
135
|
+
(0, _vitest.test)("normal", function () {
|
|
136
|
+
var upperLimit = 1.1;
|
|
137
|
+
var lowerLimit = 0.9;
|
|
138
|
+
var initValue = 100;
|
|
139
|
+
var count = 100;
|
|
140
|
+
var list = (0, _create_generator_fn.createBoundedSeriesGenerator)({
|
|
141
|
+
type: "bounded_series",
|
|
142
|
+
upperLimit: upperLimit,
|
|
143
|
+
lowerLimit: lowerLimit,
|
|
144
|
+
createInitValue: function createInitValue() {
|
|
145
|
+
return initValue;
|
|
146
|
+
},
|
|
147
|
+
count: count
|
|
148
|
+
})();
|
|
149
|
+
for (var i = 0; i < count; i++) {
|
|
150
|
+
var value = list[i];
|
|
151
|
+
if (i === 0) {
|
|
152
|
+
var _ratio = value / initValue;
|
|
153
|
+
(0, _vitest.expect)(_ratio).toBeLessThanOrEqual(upperLimit);
|
|
154
|
+
(0, _vitest.expect)(_ratio).toBeGreaterThanOrEqual(lowerLimit);
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
var prevValue = list[i - 1];
|
|
158
|
+
var ratio = value / prevValue;
|
|
159
|
+
(0, _vitest.expect)(ratio).toBeLessThanOrEqual(upperLimit);
|
|
160
|
+
(0, _vitest.expect)(ratio).toBeGreaterThanOrEqual(lowerLimit);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
(0, _vitest.describe)("createGeneratorByType", function () {
|
|
165
|
+
(0, _vitest.test)("normal", function () {
|
|
166
|
+
var config = {
|
|
167
|
+
type: "obj",
|
|
168
|
+
content: {
|
|
169
|
+
name: {
|
|
170
|
+
type: "value",
|
|
171
|
+
generateFn: function generateFn() {
|
|
172
|
+
return "John";
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
age: {
|
|
176
|
+
type: "value",
|
|
177
|
+
generateFn: function generateFn() {
|
|
178
|
+
return 50;
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
locations: {
|
|
182
|
+
type: "arr",
|
|
183
|
+
item: {
|
|
184
|
+
type: "value",
|
|
185
|
+
generateFn: function generateFn() {
|
|
186
|
+
return "Taiwan";
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
len: 5
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
var result = (0, _create_generator_fn.createGeneratorByType)(config)();
|
|
194
|
+
(0, _vitest.expect)(result).toEqual({
|
|
195
|
+
name: "John",
|
|
196
|
+
age: 50,
|
|
197
|
+
locations: ["Taiwan", "Taiwan", "Taiwan", "Taiwan", "Taiwan"]
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
(0, _vitest.test)("with custom type match", function () {
|
|
201
|
+
var createIntValueConfig = function createIntValueConfig(option) {
|
|
202
|
+
return (0, _create_config.createValueConfig)(function () {
|
|
203
|
+
return 50;
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
var createEmailValueConfig = function createEmailValueConfig(option) {
|
|
207
|
+
return (0, _create_config.createValueConfig)(function () {
|
|
208
|
+
return "xxx@example.com";
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
var customTypeMatch = function customTypeMatch(config) {
|
|
212
|
+
if (config.type === "int") {
|
|
213
|
+
return createIntValueConfig(config.option);
|
|
214
|
+
}
|
|
215
|
+
if (config.type === "email") {
|
|
216
|
+
return createEmailValueConfig(config.option);
|
|
217
|
+
}
|
|
218
|
+
throw Error("error");
|
|
219
|
+
};
|
|
220
|
+
var config = {
|
|
221
|
+
type: "obj",
|
|
222
|
+
content: {
|
|
223
|
+
name: {
|
|
224
|
+
type: "value",
|
|
225
|
+
generateFn: function generateFn() {
|
|
226
|
+
return "John";
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
age: {
|
|
230
|
+
type: "int"
|
|
231
|
+
},
|
|
232
|
+
email: {
|
|
233
|
+
type: "email"
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
var result = (0, _create_generator_fn.createGeneratorByType)(config, customTypeMatch)();
|
|
238
|
+
(0, _vitest.expect)(result).toEqual({
|
|
239
|
+
name: "John",
|
|
240
|
+
age: 50,
|
|
241
|
+
email: "xxx@example.com"
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
});
|
package/cjs/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var _create_config = require("./create_config");
|
|
6
|
+
var _create_config = require("./create_config.mjs");
|
|
7
7
|
Object.keys(_create_config).forEach(function (key) {
|
|
8
8
|
if (key === "default" || key === "__esModule") return;
|
|
9
9
|
if (key in exports && exports[key] === _create_config[key]) return;
|
|
@@ -14,7 +14,7 @@ Object.keys(_create_config).forEach(function (key) {
|
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
});
|
|
17
|
-
var _create_generator_fn = require("./create_generator_fn");
|
|
17
|
+
var _create_generator_fn = require("./create_generator_fn.mjs");
|
|
18
18
|
Object.keys(_create_generator_fn).forEach(function (key) {
|
|
19
19
|
if (key === "default" || key === "__esModule") return;
|
|
20
20
|
if (key in exports && exports[key] === _create_generator_fn[key]) return;
|
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
createTupleConfig,
|
|
8
8
|
createObjectConfig,
|
|
9
9
|
createBoundedSeriesConfig,
|
|
10
|
-
} from "./create_config";
|
|
11
|
-
import { createGeneratorByType } from "./create_generator_fn";
|
|
10
|
+
} from "./create_config.mjs";
|
|
11
|
+
import { createGeneratorByType } from "./create_generator_fn.mjs";
|
|
12
12
|
|
|
13
13
|
test("createValueConfig", () => {
|
|
14
14
|
const valueConfig = createValueConfig(() => 44);
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
createObjectGenerator,
|
|
9
9
|
createBoundedSeriesGenerator,
|
|
10
10
|
createGeneratorByType,
|
|
11
|
-
} from "./create_generator_fn";
|
|
12
|
-
import { createValueConfig } from "./create_config";
|
|
11
|
+
} from "./create_generator_fn.mjs";
|
|
12
|
+
import { createValueConfig } from "./create_config.mjs";
|
|
13
13
|
|
|
14
14
|
describe("createValueGenerator", () => {
|
|
15
15
|
test("normal", () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "struct-fakerator",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"module": "esm/index.mjs",
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"start": "node src/index.js",
|
|
10
10
|
"dev": "node",
|
|
11
|
-
"build:cjs": "babel src --out-dir cjs --presets=@babel/preset-env",
|
|
12
|
-
"build:esm": "
|
|
11
|
+
"build:cjs": "babel src --out-dir cjs --presets=@babel/preset-env --plugins=@babel/plugin-transform-modules-commonjs",
|
|
12
|
+
"build:esm": "cp -r src esm",
|
|
13
13
|
"build": "pnpm build:cjs && pnpm build:esm",
|
|
14
|
-
"test": "vitest"
|
|
14
|
+
"test": "vitest src"
|
|
15
15
|
},
|
|
16
16
|
"keywords": [],
|
|
17
17
|
"author": "FizzyElt",
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const valueConfigScheme = z.object({
|
|
4
|
+
type: z.string().regex(/^value$/, { message: "invalid type string" }),
|
|
5
|
+
generateFn: z.function(),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export const selectionConfigScheme = z.object({
|
|
9
|
+
type: z.string().regex(/^select$/, { message: "invalid type string" }),
|
|
10
|
+
items: z.any().array().nonempty({ message: "items can not be empty" }),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export const arrayConfigScheme = z.object({
|
|
14
|
+
type: z.string().regex(/^arr$/, { message: "invalid type string" }),
|
|
15
|
+
item: z.object({}),
|
|
16
|
+
len: z.number().nonnegative(),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const tupleConfigScheme = z.object({
|
|
20
|
+
type: z.string().regex(/^tuple$/, { message: "invalid type string" }),
|
|
21
|
+
configItems: z.any().array(),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const objConfigScheme = z.object({
|
|
25
|
+
type: z.string().regex(/^obj$/, { message: "invalid type string" }),
|
|
26
|
+
content: z.object({}),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export const boundedSeriesScheme = z
|
|
30
|
+
.object({
|
|
31
|
+
type: z
|
|
32
|
+
.string()
|
|
33
|
+
.regex(/^bounded_series$/, { message: "invalid type string" }),
|
|
34
|
+
upperLimit: z.number().nonnegative(),
|
|
35
|
+
lowerLimit: z.number().nonnegative(),
|
|
36
|
+
createInitValue: z.function().args().returns(z.number()),
|
|
37
|
+
count: z.number().nonnegative(),
|
|
38
|
+
})
|
|
39
|
+
.refine(({ upperLimit, lowerLimit }) => upperLimit >= lowerLimit, {
|
|
40
|
+
message: "lowerLimit can not greater then upperLimit",
|
|
41
|
+
})
|
|
42
|
+
.refine(({ createInitValue }) => typeof createInitValue() === "number", {
|
|
43
|
+
message: "createInitValue is not return number",
|
|
44
|
+
path: ["createInitValue"],
|
|
45
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { faker } from "@faker-js/faker";
|
|
2
|
+
import {
|
|
3
|
+
valueConfigScheme,
|
|
4
|
+
arrayConfigScheme,
|
|
5
|
+
selectionConfigScheme,
|
|
6
|
+
tupleConfigScheme,
|
|
7
|
+
objConfigScheme,
|
|
8
|
+
boundedSeriesScheme,
|
|
9
|
+
} from "./config_scheme.mjs";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* value
|
|
13
|
+
* @param {function} generateFn - The function used to generate the value.
|
|
14
|
+
* @return {ValueConfig} The configuration object with the type "value" and the provided generate function.
|
|
15
|
+
*/
|
|
16
|
+
export const createValueConfig = (generateFn) => {
|
|
17
|
+
const config = {
|
|
18
|
+
type: "value",
|
|
19
|
+
generateFn,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
valueConfigScheme.parse(config);
|
|
23
|
+
|
|
24
|
+
return config;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* selection
|
|
29
|
+
* @param {Array} items - The array of items to choose from.
|
|
30
|
+
* @return {SelectionConfig} The configuration object with the type "select" and the provided items.
|
|
31
|
+
*/
|
|
32
|
+
export const createSelectionConfig = (items) => {
|
|
33
|
+
const config = { type: "select", items };
|
|
34
|
+
|
|
35
|
+
selectionConfigScheme.parse(config);
|
|
36
|
+
|
|
37
|
+
return config;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* object
|
|
42
|
+
* @param {object} content
|
|
43
|
+
* @return {ObjectConfig}
|
|
44
|
+
*/
|
|
45
|
+
export const createObjectConfig = (content) => {
|
|
46
|
+
const config = { type: "obj", content };
|
|
47
|
+
|
|
48
|
+
objConfigScheme.parse(config);
|
|
49
|
+
|
|
50
|
+
return config;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* array
|
|
55
|
+
* @param {object} item
|
|
56
|
+
* @param {number} len
|
|
57
|
+
* @return {ArrayConfig}
|
|
58
|
+
*/
|
|
59
|
+
export const createArrayConfig = (item, len) => {
|
|
60
|
+
const config = { type: "arr", item, len };
|
|
61
|
+
|
|
62
|
+
arrayConfigScheme.parse(config);
|
|
63
|
+
|
|
64
|
+
return config;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* tuple
|
|
69
|
+
* @param {Array} configItems
|
|
70
|
+
* @return {TupleConfig}
|
|
71
|
+
*/
|
|
72
|
+
export const createTupleConfig = (configItems) => {
|
|
73
|
+
const config = {
|
|
74
|
+
type: "tuple",
|
|
75
|
+
configItems,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
tupleConfigScheme.parse(config);
|
|
79
|
+
|
|
80
|
+
return config;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* bounded series
|
|
85
|
+
* @param {{ upperLimit: number, lowerLimit: number, createInitValue: () => number, count: number }} config
|
|
86
|
+
* @return {BoundedSeriesConfig}
|
|
87
|
+
*/
|
|
88
|
+
export const createBoundedSeriesConfig = (config) => {
|
|
89
|
+
const newConfig = {
|
|
90
|
+
type: "bounded_series",
|
|
91
|
+
...config,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
boundedSeriesScheme.parse(newConfig);
|
|
95
|
+
|
|
96
|
+
return newConfig;
|
|
97
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { expect, expectTypeOf, test } from "vitest";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createValueConfig,
|
|
5
|
+
createSelectionConfig,
|
|
6
|
+
createArrayConfig,
|
|
7
|
+
createTupleConfig,
|
|
8
|
+
createObjectConfig,
|
|
9
|
+
createBoundedSeriesConfig,
|
|
10
|
+
} from "./create_config.mjs";
|
|
11
|
+
import { createGeneratorByType } from "./create_generator_fn.mjs";
|
|
12
|
+
|
|
13
|
+
test("createValueConfig", () => {
|
|
14
|
+
const valueConfig = createValueConfig(() => 44);
|
|
15
|
+
|
|
16
|
+
expect(valueConfig.type).toBe("value");
|
|
17
|
+
expect(valueConfig.generateFn).toBeTypeOf("function");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("createSelectionConfig", () => {
|
|
21
|
+
const options = [1, 2, 3, 4];
|
|
22
|
+
const selectionConfig = createSelectionConfig([1, 2, 3, 4]);
|
|
23
|
+
|
|
24
|
+
expect(selectionConfig.type).toBe("select");
|
|
25
|
+
expect(selectionConfig.items).toEqual(options);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("createArrayConfig", () => {
|
|
29
|
+
const valueConfig = createValueConfig(() => 44);
|
|
30
|
+
const arrConfig = createArrayConfig(valueConfig, 20);
|
|
31
|
+
|
|
32
|
+
expect(arrConfig.type).toBe("arr");
|
|
33
|
+
expect(arrConfig.len).toBe(20);
|
|
34
|
+
expect(arrConfig.item).toEqual(valueConfig);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("createTupleConfig", () => {
|
|
38
|
+
const value1Config = createValueConfig(() => 123);
|
|
39
|
+
const value2Config = createValueConfig(() => "hello");
|
|
40
|
+
|
|
41
|
+
const tupleConfig = createTupleConfig([value1Config, value2Config]);
|
|
42
|
+
|
|
43
|
+
expect(tupleConfig.type).toBe("tuple");
|
|
44
|
+
expect(tupleConfig.configItems).toEqual([value1Config, value2Config]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("createObjConfig", () => {
|
|
48
|
+
const value1Config = createValueConfig(() => 32);
|
|
49
|
+
const value2Config = createValueConfig(() => "frank");
|
|
50
|
+
|
|
51
|
+
const objConfig = createObjectConfig({
|
|
52
|
+
name: value2Config,
|
|
53
|
+
age: value1Config,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
expect(objConfig.type).toBe("obj");
|
|
57
|
+
expect(objConfig.content).toEqual({ name: value2Config, age: value1Config });
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("createBoundedSeriesConfig", () => {
|
|
61
|
+
const boundedSeriesConfig = createBoundedSeriesConfig({
|
|
62
|
+
count: 1,
|
|
63
|
+
upperLimit: 1.2,
|
|
64
|
+
lowerLimit: 1.0,
|
|
65
|
+
createInitValue: () => 40,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
expect(boundedSeriesConfig.type).toBe("bounded_series");
|
|
69
|
+
expect(boundedSeriesConfig.upperLimit).toBe(1.2);
|
|
70
|
+
expect(boundedSeriesConfig.lowerLimit).toBe(1.0);
|
|
71
|
+
expect(boundedSeriesConfig.createInitValue).toBeTypeOf("function");
|
|
72
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { faker } from "@faker-js/faker";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
valueConfigScheme,
|
|
5
|
+
selectionConfigScheme,
|
|
6
|
+
arrayConfigScheme,
|
|
7
|
+
objConfigScheme,
|
|
8
|
+
boundedSeriesScheme,
|
|
9
|
+
tupleConfigScheme,
|
|
10
|
+
} from "./config_scheme.mjs";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* value
|
|
14
|
+
* @param {ValueConfig} config
|
|
15
|
+
* @return {function}
|
|
16
|
+
*/
|
|
17
|
+
export const createValueGenerator = (config) => {
|
|
18
|
+
valueConfigScheme.parse(config);
|
|
19
|
+
|
|
20
|
+
return config.generateFn;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* selection
|
|
25
|
+
* @param {SelectionConfig} config
|
|
26
|
+
* @return {function} The configuration object with the type "select" and the provided items.
|
|
27
|
+
*/
|
|
28
|
+
export const createSelectionGenerator = (config) => {
|
|
29
|
+
selectionConfigScheme.parse(config);
|
|
30
|
+
|
|
31
|
+
const { items } = config;
|
|
32
|
+
|
|
33
|
+
return () => items[faker.number.int(items.length - 1)];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* object
|
|
38
|
+
* @param {ObjectConfig} config
|
|
39
|
+
* @param {(() => ValueConfig)=} customTypeMatch
|
|
40
|
+
* @return {() => object}
|
|
41
|
+
*/
|
|
42
|
+
export const createObjectGenerator = (config, customTypeMatch) => {
|
|
43
|
+
objConfigScheme.parse(config);
|
|
44
|
+
|
|
45
|
+
const keyWithFns = Object.entries(config.content).map(([key, subConfig]) => [
|
|
46
|
+
key,
|
|
47
|
+
createGeneratorByType(subConfig, customTypeMatch),
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
return () => {
|
|
51
|
+
const result = {};
|
|
52
|
+
for (const [key, generateFn] of keyWithFns) {
|
|
53
|
+
result[key] = generateFn();
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* array
|
|
61
|
+
* @param {ArrayConfig} config
|
|
62
|
+
* @param {(() => ValueConfig)=} customTypeMatch
|
|
63
|
+
* @return {() => Array}
|
|
64
|
+
*/
|
|
65
|
+
export const createArrayGenerator = (config, customTypeMatch) => {
|
|
66
|
+
arrayConfigScheme.parse(config);
|
|
67
|
+
|
|
68
|
+
const itemGeneratorFn = createGeneratorByType(config.item, customTypeMatch);
|
|
69
|
+
|
|
70
|
+
return () => Array.from({ length: config.len ?? 0 }, itemGeneratorFn);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* tuple
|
|
75
|
+
* @param {TupleConfig} config
|
|
76
|
+
* @param {(() => ValueConfig)=} customTypeMatch
|
|
77
|
+
* @return {() => Array}
|
|
78
|
+
*/
|
|
79
|
+
export const createTupleGenerator = (config, customTypeMatch) => {
|
|
80
|
+
tupleConfigScheme.parse(config);
|
|
81
|
+
|
|
82
|
+
const itemsFns = config.configItems.map((configItem) =>
|
|
83
|
+
createGeneratorByType(configItem, customTypeMatch),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
return () => itemsFns.map((generateFn) => generateFn());
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* bounded series
|
|
91
|
+
* @param {BoundedSeriesConfig} config
|
|
92
|
+
* @return {() => Array<number>}
|
|
93
|
+
*/
|
|
94
|
+
export const createBoundedSeriesGenerator = (config) => {
|
|
95
|
+
boundedSeriesScheme.parse(config);
|
|
96
|
+
|
|
97
|
+
const { upperLimit, lowerLimit, createInitValue, count } = config;
|
|
98
|
+
|
|
99
|
+
return () => {
|
|
100
|
+
let value = createInitValue();
|
|
101
|
+
|
|
102
|
+
const boundedSeries = [];
|
|
103
|
+
|
|
104
|
+
for (let i = 0; i < count; i++) {
|
|
105
|
+
value = faker.number.float({ max: upperLimit, min: lowerLimit }) * value;
|
|
106
|
+
boundedSeries.push(value);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return boundedSeries;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
*
|
|
115
|
+
* @param {ValueConfig | SelectionConfig | ArrayConfig | ObjectConfig | TupleConfig | BoundedSeriesConfig} config
|
|
116
|
+
* @param {(() => ValueConfig)=} customTypeMatch
|
|
117
|
+
* @return {function}
|
|
118
|
+
*/
|
|
119
|
+
export const createGeneratorByType = (config, customTypeMatch) => {
|
|
120
|
+
switch (config.type) {
|
|
121
|
+
case "obj":
|
|
122
|
+
return createObjectGenerator(config, customTypeMatch);
|
|
123
|
+
case "arr":
|
|
124
|
+
return createArrayGenerator(config, customTypeMatch);
|
|
125
|
+
case "select":
|
|
126
|
+
return createSelectionGenerator(config);
|
|
127
|
+
case "tuple":
|
|
128
|
+
return createTupleGenerator(config, customTypeMatch);
|
|
129
|
+
case "value":
|
|
130
|
+
return createValueGenerator(config);
|
|
131
|
+
case "bounded_series":
|
|
132
|
+
return createBoundedSeriesGenerator(config);
|
|
133
|
+
default: {
|
|
134
|
+
if (customTypeMatch) {
|
|
135
|
+
return createValueGenerator(customTypeMatch(config));
|
|
136
|
+
}
|
|
137
|
+
throw Error(`config type "${config.type}" is not supported`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
};
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { describe, test, expect } from "vitest";
|
|
2
|
+
import { ZodError } from "zod";
|
|
3
|
+
import {
|
|
4
|
+
createValueGenerator,
|
|
5
|
+
createSelectionGenerator,
|
|
6
|
+
createArrayGenerator,
|
|
7
|
+
createTupleGenerator,
|
|
8
|
+
createObjectGenerator,
|
|
9
|
+
createBoundedSeriesGenerator,
|
|
10
|
+
createGeneratorByType,
|
|
11
|
+
} from "./create_generator_fn.mjs";
|
|
12
|
+
import { createValueConfig } from "./create_config.mjs";
|
|
13
|
+
|
|
14
|
+
describe("createValueGenerator", () => {
|
|
15
|
+
test("normal", () => {
|
|
16
|
+
const value = createValueGenerator({
|
|
17
|
+
type: "value",
|
|
18
|
+
generateFn: () => 50,
|
|
19
|
+
})();
|
|
20
|
+
|
|
21
|
+
expect(value).toBe(50);
|
|
22
|
+
|
|
23
|
+
const value2 = createValueGenerator({
|
|
24
|
+
type: "value",
|
|
25
|
+
generateFn: () => ({ age: 100, name: "hello" }),
|
|
26
|
+
})();
|
|
27
|
+
|
|
28
|
+
expect(value2).toEqual({ age: 100, name: "hello" });
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("createSelectionGenerator", () => {
|
|
33
|
+
test("normal", () => {
|
|
34
|
+
const value = createSelectionGenerator({
|
|
35
|
+
type: "select",
|
|
36
|
+
items: [1],
|
|
37
|
+
})();
|
|
38
|
+
|
|
39
|
+
expect(value).toBe(1);
|
|
40
|
+
|
|
41
|
+
const value2 = createSelectionGenerator({
|
|
42
|
+
type: "select",
|
|
43
|
+
items: [30, 30, 30, 30],
|
|
44
|
+
})();
|
|
45
|
+
|
|
46
|
+
expect(value2).toBe(30);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("createArrayGenerator", () => {
|
|
51
|
+
test("normal", () => {
|
|
52
|
+
const list = createArrayGenerator({
|
|
53
|
+
type: "arr",
|
|
54
|
+
len: 5,
|
|
55
|
+
item: { type: "value", generateFn: () => ({ age: 42 }) },
|
|
56
|
+
})();
|
|
57
|
+
|
|
58
|
+
expect(list).toEqual([
|
|
59
|
+
{ age: 42 },
|
|
60
|
+
{ age: 42 },
|
|
61
|
+
{ age: 42 },
|
|
62
|
+
{ age: 42 },
|
|
63
|
+
{ age: 42 },
|
|
64
|
+
]);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("createTupleGenerator", () => {
|
|
69
|
+
test("normal", () => {
|
|
70
|
+
const tuple = createTupleGenerator({
|
|
71
|
+
type: "tuple",
|
|
72
|
+
configItems: [
|
|
73
|
+
{ type: "value", generateFn: () => 225 },
|
|
74
|
+
{ type: "value", generateFn: () => "hello world" },
|
|
75
|
+
],
|
|
76
|
+
})();
|
|
77
|
+
|
|
78
|
+
expect(tuple.length).toBe(2);
|
|
79
|
+
const [num, str] = tuple;
|
|
80
|
+
expect(num).toBe(225);
|
|
81
|
+
expect(str).toBe("hello world");
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe("createObjectGenerator", () => {
|
|
86
|
+
test("normal", () => {
|
|
87
|
+
const obj = createObjectGenerator({
|
|
88
|
+
type: "obj",
|
|
89
|
+
content: {
|
|
90
|
+
name: { type: "value", generateFn: () => "John" },
|
|
91
|
+
age: { type: "value", generateFn: () => 50 },
|
|
92
|
+
location: { type: "value", generateFn: () => "Taiwan" },
|
|
93
|
+
},
|
|
94
|
+
})();
|
|
95
|
+
|
|
96
|
+
expect(obj).toEqual({ name: "John", age: 50, location: "Taiwan" });
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe("createBoundedSeriesGenerator", () => {
|
|
101
|
+
test("normal", () => {
|
|
102
|
+
const upperLimit = 1.1;
|
|
103
|
+
const lowerLimit = 0.9;
|
|
104
|
+
const initValue = 100;
|
|
105
|
+
const count = 100;
|
|
106
|
+
|
|
107
|
+
const list = createBoundedSeriesGenerator({
|
|
108
|
+
type: "bounded_series",
|
|
109
|
+
upperLimit,
|
|
110
|
+
lowerLimit,
|
|
111
|
+
createInitValue: () => initValue,
|
|
112
|
+
count,
|
|
113
|
+
})();
|
|
114
|
+
|
|
115
|
+
for (let i = 0; i < count; i++) {
|
|
116
|
+
const value = list[i];
|
|
117
|
+
if (i === 0) {
|
|
118
|
+
const ratio = value / initValue;
|
|
119
|
+
|
|
120
|
+
expect(ratio).toBeLessThanOrEqual(upperLimit);
|
|
121
|
+
expect(ratio).toBeGreaterThanOrEqual(lowerLimit);
|
|
122
|
+
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const prevValue = list[i - 1];
|
|
127
|
+
|
|
128
|
+
const ratio = value / prevValue;
|
|
129
|
+
|
|
130
|
+
expect(ratio).toBeLessThanOrEqual(upperLimit);
|
|
131
|
+
expect(ratio).toBeGreaterThanOrEqual(lowerLimit);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe("createGeneratorByType", () => {
|
|
137
|
+
test("normal", () => {
|
|
138
|
+
const config = {
|
|
139
|
+
type: "obj",
|
|
140
|
+
content: {
|
|
141
|
+
name: { type: "value", generateFn: () => "John" },
|
|
142
|
+
age: { type: "value", generateFn: () => 50 },
|
|
143
|
+
locations: {
|
|
144
|
+
type: "arr",
|
|
145
|
+
item: { type: "value", generateFn: () => "Taiwan" },
|
|
146
|
+
len: 5,
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
const result = createGeneratorByType(config)();
|
|
151
|
+
|
|
152
|
+
expect(result).toEqual({
|
|
153
|
+
name: "John",
|
|
154
|
+
age: 50,
|
|
155
|
+
locations: ["Taiwan", "Taiwan", "Taiwan", "Taiwan", "Taiwan"],
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test("with custom type match", () => {
|
|
160
|
+
const createIntValueConfig = (option) => createValueConfig(() => 50);
|
|
161
|
+
const createEmailValueConfig = (option) =>
|
|
162
|
+
createValueConfig(() => "xxx@example.com");
|
|
163
|
+
|
|
164
|
+
const customTypeMatch = (config) => {
|
|
165
|
+
if (config.type === "int") {
|
|
166
|
+
return createIntValueConfig(config.option);
|
|
167
|
+
}
|
|
168
|
+
if (config.type === "email") {
|
|
169
|
+
return createEmailValueConfig(config.option);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
throw Error("error");
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const config = {
|
|
176
|
+
type: "obj",
|
|
177
|
+
content: {
|
|
178
|
+
name: { type: "value", generateFn: () => "John" },
|
|
179
|
+
age: { type: "int" },
|
|
180
|
+
email: { type: "email" },
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const result = createGeneratorByType(config, customTypeMatch)();
|
|
185
|
+
|
|
186
|
+
expect(result).toEqual({
|
|
187
|
+
name: "John",
|
|
188
|
+
age: 50,
|
|
189
|
+
email: "xxx@example.com",
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
});
|
package/src/index.mjs
ADDED
package/esm/config_scheme.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.valueConfigScheme = exports.tupleConfigScheme = exports.selectionConfigScheme = exports.objConfigScheme = exports.boundedSeriesScheme = exports.arrayConfigScheme = void 0;
|
|
7
|
-
var _zod = require("zod");
|
|
8
|
-
var valueConfigScheme = exports.valueConfigScheme = _zod.z.object({
|
|
9
|
-
type: _zod.z.string().regex(/^value$/, {
|
|
10
|
-
message: "invalid type string"
|
|
11
|
-
}),
|
|
12
|
-
generateFn: _zod.z["function"]()
|
|
13
|
-
});
|
|
14
|
-
var selectionConfigScheme = exports.selectionConfigScheme = _zod.z.object({
|
|
15
|
-
type: _zod.z.string().regex(/^select$/, {
|
|
16
|
-
message: "invalid type string"
|
|
17
|
-
}),
|
|
18
|
-
items: _zod.z.any().array().nonempty({
|
|
19
|
-
message: "items can not be empty"
|
|
20
|
-
})
|
|
21
|
-
});
|
|
22
|
-
var arrayConfigScheme = exports.arrayConfigScheme = _zod.z.object({
|
|
23
|
-
type: _zod.z.string().regex(/^arr$/, {
|
|
24
|
-
message: "invalid type string"
|
|
25
|
-
}),
|
|
26
|
-
item: _zod.z.object({}),
|
|
27
|
-
len: _zod.z.number().nonnegative()
|
|
28
|
-
});
|
|
29
|
-
var tupleConfigScheme = exports.tupleConfigScheme = _zod.z.object({
|
|
30
|
-
type: _zod.z.string().regex(/^tuple$/, {
|
|
31
|
-
message: "invalid type string"
|
|
32
|
-
}),
|
|
33
|
-
configItems: _zod.z.any().array()
|
|
34
|
-
});
|
|
35
|
-
var objConfigScheme = exports.objConfigScheme = _zod.z.object({
|
|
36
|
-
type: _zod.z.string().regex(/^obj$/, {
|
|
37
|
-
message: "invalid type string"
|
|
38
|
-
}),
|
|
39
|
-
content: _zod.z.object({})
|
|
40
|
-
});
|
|
41
|
-
var boundedSeriesScheme = exports.boundedSeriesScheme = _zod.z.object({
|
|
42
|
-
type: _zod.z.string().regex(/^bounded_series$/, {
|
|
43
|
-
message: "invalid type string"
|
|
44
|
-
}),
|
|
45
|
-
upperLimit: _zod.z.number().nonnegative(),
|
|
46
|
-
lowerLimit: _zod.z.number().nonnegative(),
|
|
47
|
-
createInitValue: _zod.z["function"]().args().returns(_zod.z.number()),
|
|
48
|
-
count: _zod.z.number().nonnegative()
|
|
49
|
-
}).refine(function (_ref) {
|
|
50
|
-
var upperLimit = _ref.upperLimit,
|
|
51
|
-
lowerLimit = _ref.lowerLimit;
|
|
52
|
-
return upperLimit >= lowerLimit;
|
|
53
|
-
}, {
|
|
54
|
-
message: "lowerLimit can not greater then upperLimit"
|
|
55
|
-
}).refine(function (_ref2) {
|
|
56
|
-
var createInitValue = _ref2.createInitValue;
|
|
57
|
-
return typeof createInitValue() === "number";
|
|
58
|
-
}, {
|
|
59
|
-
message: "createInitValue is not return number",
|
|
60
|
-
path: ["createInitValue"]
|
|
61
|
-
});
|
package/esm/create_config.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createValueConfig = exports.createTupleConfig = exports.createSelectionConfig = exports.createObjectConfig = exports.createBoundedSeriesConfig = exports.createArrayConfig = void 0;
|
|
7
|
-
var _faker = require("@faker-js/faker");
|
|
8
|
-
var _config_scheme = require("./config_scheme.js");
|
|
9
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
10
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
|
-
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
13
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
14
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
15
|
-
/**
|
|
16
|
-
* value
|
|
17
|
-
* @param {function} generateFn - The function used to generate the value.
|
|
18
|
-
* @return {ValueConfig} The configuration object with the type "value" and the provided generate function.
|
|
19
|
-
*/
|
|
20
|
-
var createValueConfig = exports.createValueConfig = function createValueConfig(generateFn) {
|
|
21
|
-
var config = {
|
|
22
|
-
type: "value",
|
|
23
|
-
generateFn: generateFn
|
|
24
|
-
};
|
|
25
|
-
_config_scheme.valueConfigScheme.parse(config);
|
|
26
|
-
return config;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* selection
|
|
31
|
-
* @param {Array} items - The array of items to choose from.
|
|
32
|
-
* @return {SelectionConfig} The configuration object with the type "select" and the provided items.
|
|
33
|
-
*/
|
|
34
|
-
var createSelectionConfig = exports.createSelectionConfig = function createSelectionConfig(items) {
|
|
35
|
-
var config = {
|
|
36
|
-
type: "select",
|
|
37
|
-
items: items
|
|
38
|
-
};
|
|
39
|
-
_config_scheme.selectionConfigScheme.parse(config);
|
|
40
|
-
return config;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* object
|
|
45
|
-
* @param {object} content
|
|
46
|
-
* @return {ObjectConfig}
|
|
47
|
-
*/
|
|
48
|
-
var createObjectConfig = exports.createObjectConfig = function createObjectConfig(content) {
|
|
49
|
-
var config = {
|
|
50
|
-
type: "obj",
|
|
51
|
-
content: content
|
|
52
|
-
};
|
|
53
|
-
_config_scheme.objConfigScheme.parse(config);
|
|
54
|
-
return config;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* array
|
|
59
|
-
* @param {object} item
|
|
60
|
-
* @param {number} len
|
|
61
|
-
* @return {ArrayConfig}
|
|
62
|
-
*/
|
|
63
|
-
var createArrayConfig = exports.createArrayConfig = function createArrayConfig(item, len) {
|
|
64
|
-
var config = {
|
|
65
|
-
type: "arr",
|
|
66
|
-
item: item,
|
|
67
|
-
len: len
|
|
68
|
-
};
|
|
69
|
-
_config_scheme.arrayConfigScheme.parse(config);
|
|
70
|
-
return config;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* tuple
|
|
75
|
-
* @param {Array} configItems
|
|
76
|
-
* @return {TupleConfig}
|
|
77
|
-
*/
|
|
78
|
-
var createTupleConfig = exports.createTupleConfig = function createTupleConfig(configItems) {
|
|
79
|
-
var config = {
|
|
80
|
-
type: "tuple",
|
|
81
|
-
configItems: configItems
|
|
82
|
-
};
|
|
83
|
-
_config_scheme.tupleConfigScheme.parse(config);
|
|
84
|
-
return config;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* bounded series
|
|
89
|
-
* @param {{ upperLimit: number, lowerLimit: number, createInitValue: () => number, count: number }} config
|
|
90
|
-
* @return {BoundedSeriesConfig}
|
|
91
|
-
*/
|
|
92
|
-
var createBoundedSeriesConfig = exports.createBoundedSeriesConfig = function createBoundedSeriesConfig(config) {
|
|
93
|
-
var newConfig = _objectSpread({
|
|
94
|
-
type: "bounded_series"
|
|
95
|
-
}, config);
|
|
96
|
-
_config_scheme.boundedSeriesScheme.parse(newConfig);
|
|
97
|
-
return newConfig;
|
|
98
|
-
};
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createValueGenerator = exports.createTupleGenerator = exports.createSelectionGenerator = exports.createObjectGenerator = exports.createGeneratorByType = exports.createBoundedSeriesGenerator = exports.createArrayGenerator = void 0;
|
|
7
|
-
var _faker = require("@faker-js/faker");
|
|
8
|
-
var _config_scheme = require("./config_scheme.js");
|
|
9
|
-
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
10
|
-
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
11
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
12
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
13
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
14
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
15
|
-
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
16
|
-
/**
|
|
17
|
-
* value
|
|
18
|
-
* @param {ValueConfig} config
|
|
19
|
-
* @return {function}
|
|
20
|
-
*/
|
|
21
|
-
var createValueGenerator = exports.createValueGenerator = function createValueGenerator(config) {
|
|
22
|
-
_config_scheme.valueConfigScheme.parse(config);
|
|
23
|
-
return config.generateFn;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* selection
|
|
28
|
-
* @param {SelectionConfig} config
|
|
29
|
-
* @return {function} The configuration object with the type "select" and the provided items.
|
|
30
|
-
*/
|
|
31
|
-
var createSelectionGenerator = exports.createSelectionGenerator = function createSelectionGenerator(config) {
|
|
32
|
-
_config_scheme.selectionConfigScheme.parse(config);
|
|
33
|
-
var items = config.items;
|
|
34
|
-
return function () {
|
|
35
|
-
return items[_faker.faker.number["int"](items.length - 1)];
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* object
|
|
41
|
-
* @param {ObjectConfig} config
|
|
42
|
-
* @param {(() => ValueConfig)=} customTypeMatch
|
|
43
|
-
* @return {() => object}
|
|
44
|
-
*/
|
|
45
|
-
var createObjectGenerator = exports.createObjectGenerator = function createObjectGenerator(config, customTypeMatch) {
|
|
46
|
-
_config_scheme.objConfigScheme.parse(config);
|
|
47
|
-
var keyWithFns = Object.entries(config.content).map(function (_ref) {
|
|
48
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
49
|
-
key = _ref2[0],
|
|
50
|
-
subConfig = _ref2[1];
|
|
51
|
-
return [key, createGeneratorByType(subConfig, customTypeMatch)];
|
|
52
|
-
});
|
|
53
|
-
return function () {
|
|
54
|
-
var result = {};
|
|
55
|
-
var _iterator = _createForOfIteratorHelper(keyWithFns),
|
|
56
|
-
_step;
|
|
57
|
-
try {
|
|
58
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
59
|
-
var _step$value = _slicedToArray(_step.value, 2),
|
|
60
|
-
key = _step$value[0],
|
|
61
|
-
generateFn = _step$value[1];
|
|
62
|
-
result[key] = generateFn();
|
|
63
|
-
}
|
|
64
|
-
} catch (err) {
|
|
65
|
-
_iterator.e(err);
|
|
66
|
-
} finally {
|
|
67
|
-
_iterator.f();
|
|
68
|
-
}
|
|
69
|
-
return result;
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* array
|
|
75
|
-
* @param {ArrayConfig} config
|
|
76
|
-
* @param {(() => ValueConfig)=} customTypeMatch
|
|
77
|
-
* @return {() => Array}
|
|
78
|
-
*/
|
|
79
|
-
var createArrayGenerator = exports.createArrayGenerator = function createArrayGenerator(config, customTypeMatch) {
|
|
80
|
-
_config_scheme.arrayConfigScheme.parse(config);
|
|
81
|
-
var itemGeneratorFn = createGeneratorByType(config.item, customTypeMatch);
|
|
82
|
-
return function () {
|
|
83
|
-
var _config$len;
|
|
84
|
-
return Array.from({
|
|
85
|
-
length: (_config$len = config.len) !== null && _config$len !== void 0 ? _config$len : 0
|
|
86
|
-
}, itemGeneratorFn);
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* tuple
|
|
92
|
-
* @param {TupleConfig} config
|
|
93
|
-
* @param {(() => ValueConfig)=} customTypeMatch
|
|
94
|
-
* @return {() => Array}
|
|
95
|
-
*/
|
|
96
|
-
var createTupleGenerator = exports.createTupleGenerator = function createTupleGenerator(config, customTypeMatch) {
|
|
97
|
-
_config_scheme.tupleConfigScheme.parse(config);
|
|
98
|
-
var itemsFns = config.configItems.map(function (configItem) {
|
|
99
|
-
return createGeneratorByType(configItem, customTypeMatch);
|
|
100
|
-
});
|
|
101
|
-
return function () {
|
|
102
|
-
return itemsFns.map(function (generateFn) {
|
|
103
|
-
return generateFn();
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* bounded series
|
|
110
|
-
* @param {BoundedSeriesConfig} config
|
|
111
|
-
* @return {() => Array<number>}
|
|
112
|
-
*/
|
|
113
|
-
var createBoundedSeriesGenerator = exports.createBoundedSeriesGenerator = function createBoundedSeriesGenerator(config) {
|
|
114
|
-
_config_scheme.boundedSeriesScheme.parse(config);
|
|
115
|
-
var upperLimit = config.upperLimit,
|
|
116
|
-
lowerLimit = config.lowerLimit,
|
|
117
|
-
createInitValue = config.createInitValue,
|
|
118
|
-
count = config.count;
|
|
119
|
-
return function () {
|
|
120
|
-
var value = createInitValue();
|
|
121
|
-
var boundedSeries = [];
|
|
122
|
-
for (var i = 0; i < count; i++) {
|
|
123
|
-
value = _faker.faker.number["float"]({
|
|
124
|
-
max: upperLimit,
|
|
125
|
-
min: lowerLimit
|
|
126
|
-
}) * value;
|
|
127
|
-
boundedSeries.push(value);
|
|
128
|
-
}
|
|
129
|
-
return boundedSeries;
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
*
|
|
135
|
-
* @param {ValueConfig | SelectionConfig | ArrayConfig | ObjectConfig | TupleConfig | BoundedSeriesConfig} config
|
|
136
|
-
* @param {(() => ValueConfig)=} customTypeMatch
|
|
137
|
-
* @return {function}
|
|
138
|
-
*/
|
|
139
|
-
var createGeneratorByType = exports.createGeneratorByType = function createGeneratorByType(config, customTypeMatch) {
|
|
140
|
-
switch (config.type) {
|
|
141
|
-
case "obj":
|
|
142
|
-
return createObjectGenerator(config, customTypeMatch);
|
|
143
|
-
case "arr":
|
|
144
|
-
return createArrayGenerator(config, customTypeMatch);
|
|
145
|
-
case "select":
|
|
146
|
-
return createSelectionGenerator(config);
|
|
147
|
-
case "tuple":
|
|
148
|
-
return createTupleGenerator(config, customTypeMatch);
|
|
149
|
-
case "value":
|
|
150
|
-
return createValueGenerator(config);
|
|
151
|
-
case "bounded_series":
|
|
152
|
-
return createBoundedSeriesGenerator(config);
|
|
153
|
-
default:
|
|
154
|
-
{
|
|
155
|
-
if (customTypeMatch) {
|
|
156
|
-
return createValueGenerator(customTypeMatch(config));
|
|
157
|
-
}
|
|
158
|
-
throw Error("config type \"".concat(config.type, "\" is not supported"));
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
};
|
package/esm/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _create_config = require("./create_config");
|
|
7
|
-
Object.keys(_create_config).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _create_config[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function get() {
|
|
13
|
-
return _create_config[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _create_generator_fn = require("./create_generator_fn");
|
|
18
|
-
Object.keys(_create_generator_fn).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _create_generator_fn[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function get() {
|
|
24
|
-
return _create_generator_fn[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
package/src/index.js
DELETED
|
File without changes
|
|
File without changes
|