struct-fakerator 3.0.1 → 3.1.0
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/README.md +2 -4
- package/dist/config_scheme.cjs +24 -40
- package/dist/config_scheme.js +24 -40
- package/dist/create_config.cjs +8 -7
- package/dist/create_config.js +8 -7
- package/dist/create_generator_fn.cjs +9 -8
- package/dist/create_generator_fn.js +9 -8
- package/dist/types/config_scheme.d.ts +35 -29
- package/dist/types/create_generator_fn.d.ts +2 -2
- package/dist/types/type.d.ts +1 -10
- package/dist/types/utils/airline.d.ts +4 -4
- package/dist/types/utils/color.d.ts +7 -7
- package/dist/types/utils/commerce.d.ts +2 -2
- package/dist/types/utils/common.d.ts +2 -1
- package/dist/types/utils/datatype.d.ts +1 -1
- package/dist/types/utils/datetime.d.ts +8 -8
- package/dist/types/utils/finance.d.ts +7 -7
- package/dist/types/utils/git.d.ts +3 -3
- package/dist/types/utils/image.d.ts +4 -4
- package/dist/types/utils/internet.d.ts +11 -11
- package/dist/types/utils/location.d.ts +11 -11
- package/dist/types/utils/lorem.d.ts +8 -8
- package/dist/types/utils/number.d.ts +7 -7
- package/dist/types/utils/person.d.ts +8 -6
- package/dist/types/utils/phone.d.ts +1 -1
- package/dist/types/utils/string.d.ts +14 -11
- package/dist/types/utils/system.d.ts +5 -5
- package/dist/types/utils/utils.d.ts +1 -1
- package/dist/types/utils/word.d.ts +9 -9
- package/dist/utils/common.cjs +2 -2
- package/dist/utils/common.js +1 -1
- package/dist/utils/utils.cjs +2 -2
- package/dist/utils/utils.js +1 -1
- package/package.json +54 -52
package/README.md
CHANGED
|
@@ -267,10 +267,8 @@ flowchart TB
|
|
|
267
267
|
但並不是所有人情況都能自己手動建立函數,有可能是開放給別人使用的服務,沒辦法在使用方建立函數,這時 `createGeneratorByType` 第二個可以讓製作服務的人帶入自己的擴充,這樣這個函數就能接受更多種型態。
|
|
268
268
|
|
|
269
269
|
```typescript
|
|
270
|
-
const createIntValueConfig = (option) =>
|
|
271
|
-
|
|
272
|
-
const createEmailValueConfig = (option) =>
|
|
273
|
-
createValueConfig(() => faker.internet.email(option));
|
|
270
|
+
const createIntValueConfig = (option) => createValueConfig(() => faker.number.int(option));
|
|
271
|
+
const createEmailValueConfig = (option) => createValueConfig(() => faker.internet.email(option));
|
|
274
272
|
|
|
275
273
|
const customTypeMatch = (config) => {
|
|
276
274
|
if (config.type === "int") {
|
package/dist/config_scheme.cjs
CHANGED
|
@@ -31,51 +31,35 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
31
31
|
boundedSeriesScheme: ()=>boundedSeriesScheme,
|
|
32
32
|
objConfigScheme: ()=>objConfigScheme
|
|
33
33
|
});
|
|
34
|
-
const
|
|
35
|
-
const valueConfigScheme =
|
|
36
|
-
type:
|
|
37
|
-
|
|
38
|
-
}),
|
|
39
|
-
generateFn: external_zod_namespaceObject.z.any()
|
|
34
|
+
const external_valibot_namespaceObject = require("valibot");
|
|
35
|
+
const valueConfigScheme = external_valibot_namespaceObject.object({
|
|
36
|
+
type: external_valibot_namespaceObject.pipe(external_valibot_namespaceObject.string(), external_valibot_namespaceObject.regex(/^value$/, "invalid type string")),
|
|
37
|
+
generateFn: external_valibot_namespaceObject.any()
|
|
40
38
|
});
|
|
41
|
-
const selectionConfigScheme =
|
|
42
|
-
type:
|
|
43
|
-
|
|
44
|
-
}),
|
|
45
|
-
items: external_zod_namespaceObject.z.any().array().nonempty({
|
|
46
|
-
message: "items can not be empty"
|
|
47
|
-
})
|
|
39
|
+
const selectionConfigScheme = external_valibot_namespaceObject.object({
|
|
40
|
+
type: external_valibot_namespaceObject.pipe(external_valibot_namespaceObject.string(), external_valibot_namespaceObject.regex(/^select$/, "invalid type string")),
|
|
41
|
+
items: external_valibot_namespaceObject.pipe(external_valibot_namespaceObject.array(external_valibot_namespaceObject.any()), external_valibot_namespaceObject.nonEmpty("items can not be empty"))
|
|
48
42
|
});
|
|
49
|
-
const arrayConfigScheme =
|
|
50
|
-
type:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
item: external_zod_namespaceObject.z.object({}),
|
|
54
|
-
len: external_zod_namespaceObject.z.number().nonnegative()
|
|
43
|
+
const arrayConfigScheme = external_valibot_namespaceObject.object({
|
|
44
|
+
type: external_valibot_namespaceObject.pipe(external_valibot_namespaceObject.string(), external_valibot_namespaceObject.regex(/^arr$/, "invalid type string")),
|
|
45
|
+
item: external_valibot_namespaceObject.object({}),
|
|
46
|
+
len: external_valibot_namespaceObject.pipe(external_valibot_namespaceObject.number(), external_valibot_namespaceObject.integer(), external_valibot_namespaceObject.minValue(0))
|
|
55
47
|
});
|
|
56
|
-
const tupleConfigScheme =
|
|
57
|
-
type:
|
|
58
|
-
|
|
59
|
-
}),
|
|
60
|
-
configItems: external_zod_namespaceObject.z.any().array()
|
|
48
|
+
const tupleConfigScheme = external_valibot_namespaceObject.object({
|
|
49
|
+
type: external_valibot_namespaceObject.pipe(external_valibot_namespaceObject.string(), external_valibot_namespaceObject.regex(/^tuple$/, "invalid type string")),
|
|
50
|
+
configItems: external_valibot_namespaceObject.array(external_valibot_namespaceObject.any())
|
|
61
51
|
});
|
|
62
|
-
const objConfigScheme =
|
|
63
|
-
type:
|
|
64
|
-
|
|
65
|
-
}),
|
|
66
|
-
content: external_zod_namespaceObject.z.object({})
|
|
67
|
-
});
|
|
68
|
-
const boundedSeriesScheme = external_zod_namespaceObject.z.object({
|
|
69
|
-
type: external_zod_namespaceObject.z.string().regex(/^bounded_series$/, {
|
|
70
|
-
message: "invalid type string"
|
|
71
|
-
}),
|
|
72
|
-
upperLimit: external_zod_namespaceObject.z.number().nonnegative(),
|
|
73
|
-
lowerLimit: external_zod_namespaceObject.z.number().nonnegative(),
|
|
74
|
-
createInitValue: external_zod_namespaceObject.z.any(),
|
|
75
|
-
count: external_zod_namespaceObject.z.number().nonnegative()
|
|
76
|
-
}).refine(({ upperLimit, lowerLimit })=>upperLimit >= lowerLimit, {
|
|
77
|
-
message: "lowerLimit can not greater then upperLimit"
|
|
52
|
+
const objConfigScheme = external_valibot_namespaceObject.object({
|
|
53
|
+
type: external_valibot_namespaceObject.pipe(external_valibot_namespaceObject.string(), external_valibot_namespaceObject.regex(/^obj$/, "invalid type string")),
|
|
54
|
+
content: external_valibot_namespaceObject.object({})
|
|
78
55
|
});
|
|
56
|
+
const boundedSeriesScheme = external_valibot_namespaceObject.pipe(external_valibot_namespaceObject.object({
|
|
57
|
+
type: external_valibot_namespaceObject.pipe(external_valibot_namespaceObject.string(), external_valibot_namespaceObject.regex(/^bounded_series$/, "invalid type string")),
|
|
58
|
+
upperLimit: external_valibot_namespaceObject.pipe(external_valibot_namespaceObject.number(), external_valibot_namespaceObject.minValue(0)),
|
|
59
|
+
lowerLimit: external_valibot_namespaceObject.pipe(external_valibot_namespaceObject.number(), external_valibot_namespaceObject.minValue(0)),
|
|
60
|
+
createInitValue: external_valibot_namespaceObject.any(),
|
|
61
|
+
count: external_valibot_namespaceObject.pipe(external_valibot_namespaceObject.number(), external_valibot_namespaceObject.integer(), external_valibot_namespaceObject.minValue(0))
|
|
62
|
+
}), external_valibot_namespaceObject.check(({ upperLimit, lowerLimit })=>upperLimit >= lowerLimit, "lowerLimit can not greater then upperLimit"));
|
|
79
63
|
exports.arrayConfigScheme = __webpack_exports__.arrayConfigScheme;
|
|
80
64
|
exports.boundedSeriesScheme = __webpack_exports__.boundedSeriesScheme;
|
|
81
65
|
exports.objConfigScheme = __webpack_exports__.objConfigScheme;
|
package/dist/config_scheme.js
CHANGED
|
@@ -1,46 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const valueConfigScheme =
|
|
3
|
-
type:
|
|
4
|
-
|
|
5
|
-
}),
|
|
6
|
-
generateFn: z.any()
|
|
1
|
+
import { any, array, check, integer, minValue, nonEmpty, number, object, pipe, regex, string } from "valibot";
|
|
2
|
+
const valueConfigScheme = object({
|
|
3
|
+
type: pipe(string(), regex(/^value$/, "invalid type string")),
|
|
4
|
+
generateFn: any()
|
|
7
5
|
});
|
|
8
|
-
const selectionConfigScheme =
|
|
9
|
-
type:
|
|
10
|
-
|
|
11
|
-
}),
|
|
12
|
-
items: z.any().array().nonempty({
|
|
13
|
-
message: "items can not be empty"
|
|
14
|
-
})
|
|
6
|
+
const selectionConfigScheme = object({
|
|
7
|
+
type: pipe(string(), regex(/^select$/, "invalid type string")),
|
|
8
|
+
items: pipe(array(any()), nonEmpty("items can not be empty"))
|
|
15
9
|
});
|
|
16
|
-
const arrayConfigScheme =
|
|
17
|
-
type:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
item: z.object({}),
|
|
21
|
-
len: z.number().nonnegative()
|
|
10
|
+
const arrayConfigScheme = object({
|
|
11
|
+
type: pipe(string(), regex(/^arr$/, "invalid type string")),
|
|
12
|
+
item: object({}),
|
|
13
|
+
len: pipe(number(), integer(), minValue(0))
|
|
22
14
|
});
|
|
23
|
-
const tupleConfigScheme =
|
|
24
|
-
type:
|
|
25
|
-
|
|
26
|
-
}),
|
|
27
|
-
configItems: z.any().array()
|
|
15
|
+
const tupleConfigScheme = object({
|
|
16
|
+
type: pipe(string(), regex(/^tuple$/, "invalid type string")),
|
|
17
|
+
configItems: array(any())
|
|
28
18
|
});
|
|
29
|
-
const objConfigScheme =
|
|
30
|
-
type:
|
|
31
|
-
|
|
32
|
-
}),
|
|
33
|
-
content: z.object({})
|
|
34
|
-
});
|
|
35
|
-
const boundedSeriesScheme = z.object({
|
|
36
|
-
type: z.string().regex(/^bounded_series$/, {
|
|
37
|
-
message: "invalid type string"
|
|
38
|
-
}),
|
|
39
|
-
upperLimit: z.number().nonnegative(),
|
|
40
|
-
lowerLimit: z.number().nonnegative(),
|
|
41
|
-
createInitValue: z.any(),
|
|
42
|
-
count: z.number().nonnegative()
|
|
43
|
-
}).refine(({ upperLimit, lowerLimit })=>upperLimit >= lowerLimit, {
|
|
44
|
-
message: "lowerLimit can not greater then upperLimit"
|
|
19
|
+
const objConfigScheme = object({
|
|
20
|
+
type: pipe(string(), regex(/^obj$/, "invalid type string")),
|
|
21
|
+
content: object({})
|
|
45
22
|
});
|
|
23
|
+
const boundedSeriesScheme = pipe(object({
|
|
24
|
+
type: pipe(string(), regex(/^bounded_series$/, "invalid type string")),
|
|
25
|
+
upperLimit: pipe(number(), minValue(0)),
|
|
26
|
+
lowerLimit: pipe(number(), minValue(0)),
|
|
27
|
+
createInitValue: any(),
|
|
28
|
+
count: pipe(number(), integer(), minValue(0))
|
|
29
|
+
}), check(({ upperLimit, lowerLimit })=>upperLimit >= lowerLimit, "lowerLimit can not greater then upperLimit"));
|
|
46
30
|
export { arrayConfigScheme, boundedSeriesScheme, objConfigScheme, selectionConfigScheme, tupleConfigScheme, valueConfigScheme };
|
package/dist/create_config.cjs
CHANGED
|
@@ -31,13 +31,14 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
31
31
|
createBoundedSeriesConfig: ()=>createBoundedSeriesConfig,
|
|
32
32
|
createTupleConfig: ()=>createTupleConfig
|
|
33
33
|
});
|
|
34
|
+
const external_valibot_namespaceObject = require("valibot");
|
|
34
35
|
const external_config_scheme_cjs_namespaceObject = require("./config_scheme.cjs");
|
|
35
36
|
const createValueConfig = (generateFn)=>{
|
|
36
37
|
const config = {
|
|
37
38
|
type: "value",
|
|
38
39
|
generateFn
|
|
39
40
|
};
|
|
40
|
-
external_config_scheme_cjs_namespaceObject.valueConfigScheme
|
|
41
|
+
external_valibot_namespaceObject.assert(external_config_scheme_cjs_namespaceObject.valueConfigScheme, config);
|
|
41
42
|
return config;
|
|
42
43
|
};
|
|
43
44
|
const createSelectionConfig = (items)=>{
|
|
@@ -45,7 +46,7 @@ const createSelectionConfig = (items)=>{
|
|
|
45
46
|
type: "select",
|
|
46
47
|
items
|
|
47
48
|
};
|
|
48
|
-
external_config_scheme_cjs_namespaceObject.selectionConfigScheme
|
|
49
|
+
external_valibot_namespaceObject.assert(external_config_scheme_cjs_namespaceObject.selectionConfigScheme, config);
|
|
49
50
|
return config;
|
|
50
51
|
};
|
|
51
52
|
function createObjectConfig(content, transformer) {
|
|
@@ -55,14 +56,14 @@ function createObjectConfig(content, transformer) {
|
|
|
55
56
|
content,
|
|
56
57
|
transformer
|
|
57
58
|
};
|
|
58
|
-
external_config_scheme_cjs_namespaceObject.objConfigScheme
|
|
59
|
+
external_valibot_namespaceObject.assert(external_config_scheme_cjs_namespaceObject.objConfigScheme, config);
|
|
59
60
|
return config;
|
|
60
61
|
}
|
|
61
62
|
const config = {
|
|
62
63
|
type: "obj",
|
|
63
64
|
content
|
|
64
65
|
};
|
|
65
|
-
external_config_scheme_cjs_namespaceObject.objConfigScheme
|
|
66
|
+
external_valibot_namespaceObject.assert(external_config_scheme_cjs_namespaceObject.objConfigScheme, config);
|
|
66
67
|
return config;
|
|
67
68
|
}
|
|
68
69
|
const createArrayConfig = (item, len, next)=>{
|
|
@@ -72,7 +73,7 @@ const createArrayConfig = (item, len, next)=>{
|
|
|
72
73
|
len,
|
|
73
74
|
next
|
|
74
75
|
};
|
|
75
|
-
external_config_scheme_cjs_namespaceObject.arrayConfigScheme
|
|
76
|
+
external_valibot_namespaceObject.assert(external_config_scheme_cjs_namespaceObject.arrayConfigScheme, config);
|
|
76
77
|
return config;
|
|
77
78
|
};
|
|
78
79
|
const createTupleConfig = (configItems)=>{
|
|
@@ -80,7 +81,7 @@ const createTupleConfig = (configItems)=>{
|
|
|
80
81
|
type: "tuple",
|
|
81
82
|
configItems
|
|
82
83
|
};
|
|
83
|
-
external_config_scheme_cjs_namespaceObject.tupleConfigScheme
|
|
84
|
+
external_valibot_namespaceObject.assert(external_config_scheme_cjs_namespaceObject.tupleConfigScheme, config);
|
|
84
85
|
return config;
|
|
85
86
|
};
|
|
86
87
|
const createBoundedSeriesConfig = (config)=>{
|
|
@@ -88,7 +89,7 @@ const createBoundedSeriesConfig = (config)=>{
|
|
|
88
89
|
type: "bounded_series",
|
|
89
90
|
...config
|
|
90
91
|
};
|
|
91
|
-
external_config_scheme_cjs_namespaceObject.boundedSeriesScheme
|
|
92
|
+
external_valibot_namespaceObject.assert(external_config_scheme_cjs_namespaceObject.boundedSeriesScheme, newConfig);
|
|
92
93
|
return newConfig;
|
|
93
94
|
};
|
|
94
95
|
exports.createArrayConfig = __webpack_exports__.createArrayConfig;
|
package/dist/create_config.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { assert } from "valibot";
|
|
1
2
|
import { arrayConfigScheme, boundedSeriesScheme, objConfigScheme, selectionConfigScheme, tupleConfigScheme, valueConfigScheme } from "./config_scheme.js";
|
|
2
3
|
const createValueConfig = (generateFn)=>{
|
|
3
4
|
const config = {
|
|
4
5
|
type: "value",
|
|
5
6
|
generateFn
|
|
6
7
|
};
|
|
7
|
-
valueConfigScheme
|
|
8
|
+
assert(valueConfigScheme, config);
|
|
8
9
|
return config;
|
|
9
10
|
};
|
|
10
11
|
const createSelectionConfig = (items)=>{
|
|
@@ -12,7 +13,7 @@ const createSelectionConfig = (items)=>{
|
|
|
12
13
|
type: "select",
|
|
13
14
|
items
|
|
14
15
|
};
|
|
15
|
-
selectionConfigScheme
|
|
16
|
+
assert(selectionConfigScheme, config);
|
|
16
17
|
return config;
|
|
17
18
|
};
|
|
18
19
|
function createObjectConfig(content, transformer) {
|
|
@@ -22,14 +23,14 @@ function createObjectConfig(content, transformer) {
|
|
|
22
23
|
content,
|
|
23
24
|
transformer
|
|
24
25
|
};
|
|
25
|
-
objConfigScheme
|
|
26
|
+
assert(objConfigScheme, config);
|
|
26
27
|
return config;
|
|
27
28
|
}
|
|
28
29
|
const config = {
|
|
29
30
|
type: "obj",
|
|
30
31
|
content
|
|
31
32
|
};
|
|
32
|
-
objConfigScheme
|
|
33
|
+
assert(objConfigScheme, config);
|
|
33
34
|
return config;
|
|
34
35
|
}
|
|
35
36
|
const createArrayConfig = (item, len, next)=>{
|
|
@@ -39,7 +40,7 @@ const createArrayConfig = (item, len, next)=>{
|
|
|
39
40
|
len,
|
|
40
41
|
next
|
|
41
42
|
};
|
|
42
|
-
arrayConfigScheme
|
|
43
|
+
assert(arrayConfigScheme, config);
|
|
43
44
|
return config;
|
|
44
45
|
};
|
|
45
46
|
const createTupleConfig = (configItems)=>{
|
|
@@ -47,7 +48,7 @@ const createTupleConfig = (configItems)=>{
|
|
|
47
48
|
type: "tuple",
|
|
48
49
|
configItems
|
|
49
50
|
};
|
|
50
|
-
tupleConfigScheme
|
|
51
|
+
assert(tupleConfigScheme, config);
|
|
51
52
|
return config;
|
|
52
53
|
};
|
|
53
54
|
const createBoundedSeriesConfig = (config)=>{
|
|
@@ -55,7 +56,7 @@ const createBoundedSeriesConfig = (config)=>{
|
|
|
55
56
|
type: "bounded_series",
|
|
56
57
|
...config
|
|
57
58
|
};
|
|
58
|
-
boundedSeriesScheme
|
|
59
|
+
assert(boundedSeriesScheme, newConfig);
|
|
59
60
|
return newConfig;
|
|
60
61
|
};
|
|
61
62
|
export { createArrayConfig, createBoundedSeriesConfig, createObjectConfig, createSelectionConfig, createTupleConfig, createValueConfig };
|
|
@@ -33,10 +33,11 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
33
33
|
createTupleGenerator: ()=>createTupleGenerator
|
|
34
34
|
});
|
|
35
35
|
const faker_namespaceObject = require("@faker-js/faker");
|
|
36
|
+
const external_valibot_namespaceObject = require("valibot");
|
|
36
37
|
const external_config_scheme_cjs_namespaceObject = require("./config_scheme.cjs");
|
|
37
38
|
const _createValueGenerator = (config, path)=>{
|
|
38
39
|
try {
|
|
39
|
-
external_config_scheme_cjs_namespaceObject.valueConfigScheme
|
|
40
|
+
external_valibot_namespaceObject.assert(external_config_scheme_cjs_namespaceObject.valueConfigScheme, config);
|
|
40
41
|
} catch (err) {
|
|
41
42
|
throw new Error(`config path: ${path}.value\n${err}`);
|
|
42
43
|
}
|
|
@@ -45,7 +46,7 @@ const _createValueGenerator = (config, path)=>{
|
|
|
45
46
|
const createValueGenerator = (config)=>_createValueGenerator(config, "*");
|
|
46
47
|
const _createSelectionGenerator = (config, path)=>{
|
|
47
48
|
try {
|
|
48
|
-
external_config_scheme_cjs_namespaceObject.selectionConfigScheme
|
|
49
|
+
external_valibot_namespaceObject.assert(external_config_scheme_cjs_namespaceObject.selectionConfigScheme, config);
|
|
49
50
|
} catch (err) {
|
|
50
51
|
throw new Error(`config path: ${path}.select\n${err}`);
|
|
51
52
|
}
|
|
@@ -55,7 +56,7 @@ const _createSelectionGenerator = (config, path)=>{
|
|
|
55
56
|
const createSelectionGenerator = (config)=>_createSelectionGenerator(config, "*");
|
|
56
57
|
const _createObjectGenerator = (config, path, customTypeMatch)=>{
|
|
57
58
|
try {
|
|
58
|
-
external_config_scheme_cjs_namespaceObject.objConfigScheme
|
|
59
|
+
external_valibot_namespaceObject.assert(external_config_scheme_cjs_namespaceObject.objConfigScheme, config);
|
|
59
60
|
} catch (err) {
|
|
60
61
|
throw new Error(`config path: ${path}.obj\n ${err}`);
|
|
61
62
|
}
|
|
@@ -73,7 +74,7 @@ const _createObjectGenerator = (config, path, customTypeMatch)=>{
|
|
|
73
74
|
const createObjectGenerator = (config, customTypeMatch)=>_createObjectGenerator(config, "*", customTypeMatch);
|
|
74
75
|
const _createArrayGenerator = (config, path, customTypeMatch)=>{
|
|
75
76
|
try {
|
|
76
|
-
external_config_scheme_cjs_namespaceObject.arrayConfigScheme
|
|
77
|
+
external_valibot_namespaceObject.assert(external_config_scheme_cjs_namespaceObject.arrayConfigScheme, config);
|
|
77
78
|
} catch (err) {
|
|
78
79
|
throw new Error(`config path: ${path}.arr\n ${err}`);
|
|
79
80
|
}
|
|
@@ -83,7 +84,7 @@ const _createArrayGenerator = (config, path, customTypeMatch)=>{
|
|
|
83
84
|
return ()=>{
|
|
84
85
|
let prev = itemGeneratorFn();
|
|
85
86
|
const result = [];
|
|
86
|
-
for(let i = 0; i < config.len; i
|
|
87
|
+
for(let i = 0; i < config.len; i += 1){
|
|
87
88
|
const nextValue = next(prev, itemGeneratorFn());
|
|
88
89
|
result.push(nextValue);
|
|
89
90
|
prev = nextValue;
|
|
@@ -98,7 +99,7 @@ const _createArrayGenerator = (config, path, customTypeMatch)=>{
|
|
|
98
99
|
const createArrayGenerator = (config, customTypeMatch)=>_createArrayGenerator(config, "*", customTypeMatch);
|
|
99
100
|
const _createTupleGenerator = (config, path, customTypeMatch)=>{
|
|
100
101
|
try {
|
|
101
|
-
external_config_scheme_cjs_namespaceObject.tupleConfigScheme
|
|
102
|
+
external_valibot_namespaceObject.assert(external_config_scheme_cjs_namespaceObject.tupleConfigScheme, config);
|
|
102
103
|
} catch (err) {
|
|
103
104
|
throw new Error(`config path: ${path}.tuple\n ${err}`);
|
|
104
105
|
}
|
|
@@ -108,7 +109,7 @@ const _createTupleGenerator = (config, path, customTypeMatch)=>{
|
|
|
108
109
|
const createTupleGenerator = (config, customTypeMatch)=>_createTupleGenerator(config, "*", customTypeMatch);
|
|
109
110
|
const _createBoundedSeriesGenerator = (config, path)=>{
|
|
110
111
|
try {
|
|
111
|
-
external_config_scheme_cjs_namespaceObject.boundedSeriesScheme
|
|
112
|
+
external_valibot_namespaceObject.assert(external_config_scheme_cjs_namespaceObject.boundedSeriesScheme, config);
|
|
112
113
|
} catch (err) {
|
|
113
114
|
throw new Error(`config path: ${path}.boundedSeries\n ${err}`);
|
|
114
115
|
}
|
|
@@ -116,7 +117,7 @@ const _createBoundedSeriesGenerator = (config, path)=>{
|
|
|
116
117
|
return ()=>{
|
|
117
118
|
let value = createInitValue();
|
|
118
119
|
const boundedSeries = [];
|
|
119
|
-
for(let i = 0; i < count; i
|
|
120
|
+
for(let i = 0; i < count; i += 1){
|
|
120
121
|
value = faker_namespaceObject.faker.number.float({
|
|
121
122
|
max: upperLimit,
|
|
122
123
|
min: lowerLimit
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { faker } from "@faker-js/faker";
|
|
2
|
+
import { assert } from "valibot";
|
|
2
3
|
import { arrayConfigScheme, boundedSeriesScheme, objConfigScheme, selectionConfigScheme, tupleConfigScheme, valueConfigScheme } from "./config_scheme.js";
|
|
3
4
|
const _createValueGenerator = (config, path)=>{
|
|
4
5
|
try {
|
|
5
|
-
valueConfigScheme
|
|
6
|
+
assert(valueConfigScheme, config);
|
|
6
7
|
} catch (err) {
|
|
7
8
|
throw new Error(`config path: ${path}.value\n${err}`);
|
|
8
9
|
}
|
|
@@ -11,7 +12,7 @@ const _createValueGenerator = (config, path)=>{
|
|
|
11
12
|
const createValueGenerator = (config)=>_createValueGenerator(config, "*");
|
|
12
13
|
const _createSelectionGenerator = (config, path)=>{
|
|
13
14
|
try {
|
|
14
|
-
selectionConfigScheme
|
|
15
|
+
assert(selectionConfigScheme, config);
|
|
15
16
|
} catch (err) {
|
|
16
17
|
throw new Error(`config path: ${path}.select\n${err}`);
|
|
17
18
|
}
|
|
@@ -21,7 +22,7 @@ const _createSelectionGenerator = (config, path)=>{
|
|
|
21
22
|
const createSelectionGenerator = (config)=>_createSelectionGenerator(config, "*");
|
|
22
23
|
const _createObjectGenerator = (config, path, customTypeMatch)=>{
|
|
23
24
|
try {
|
|
24
|
-
objConfigScheme
|
|
25
|
+
assert(objConfigScheme, config);
|
|
25
26
|
} catch (err) {
|
|
26
27
|
throw new Error(`config path: ${path}.obj\n ${err}`);
|
|
27
28
|
}
|
|
@@ -39,7 +40,7 @@ const _createObjectGenerator = (config, path, customTypeMatch)=>{
|
|
|
39
40
|
const createObjectGenerator = (config, customTypeMatch)=>_createObjectGenerator(config, "*", customTypeMatch);
|
|
40
41
|
const _createArrayGenerator = (config, path, customTypeMatch)=>{
|
|
41
42
|
try {
|
|
42
|
-
arrayConfigScheme
|
|
43
|
+
assert(arrayConfigScheme, config);
|
|
43
44
|
} catch (err) {
|
|
44
45
|
throw new Error(`config path: ${path}.arr\n ${err}`);
|
|
45
46
|
}
|
|
@@ -49,7 +50,7 @@ const _createArrayGenerator = (config, path, customTypeMatch)=>{
|
|
|
49
50
|
return ()=>{
|
|
50
51
|
let prev = itemGeneratorFn();
|
|
51
52
|
const result = [];
|
|
52
|
-
for(let i = 0; i < config.len; i
|
|
53
|
+
for(let i = 0; i < config.len; i += 1){
|
|
53
54
|
const nextValue = next(prev, itemGeneratorFn());
|
|
54
55
|
result.push(nextValue);
|
|
55
56
|
prev = nextValue;
|
|
@@ -64,7 +65,7 @@ const _createArrayGenerator = (config, path, customTypeMatch)=>{
|
|
|
64
65
|
const createArrayGenerator = (config, customTypeMatch)=>_createArrayGenerator(config, "*", customTypeMatch);
|
|
65
66
|
const _createTupleGenerator = (config, path, customTypeMatch)=>{
|
|
66
67
|
try {
|
|
67
|
-
tupleConfigScheme
|
|
68
|
+
assert(tupleConfigScheme, config);
|
|
68
69
|
} catch (err) {
|
|
69
70
|
throw new Error(`config path: ${path}.tuple\n ${err}`);
|
|
70
71
|
}
|
|
@@ -74,7 +75,7 @@ const _createTupleGenerator = (config, path, customTypeMatch)=>{
|
|
|
74
75
|
const createTupleGenerator = (config, customTypeMatch)=>_createTupleGenerator(config, "*", customTypeMatch);
|
|
75
76
|
const _createBoundedSeriesGenerator = (config, path)=>{
|
|
76
77
|
try {
|
|
77
|
-
boundedSeriesScheme
|
|
78
|
+
assert(boundedSeriesScheme, config);
|
|
78
79
|
} catch (err) {
|
|
79
80
|
throw new Error(`config path: ${path}.boundedSeries\n ${err}`);
|
|
80
81
|
}
|
|
@@ -82,7 +83,7 @@ const _createBoundedSeriesGenerator = (config, path)=>{
|
|
|
82
83
|
return ()=>{
|
|
83
84
|
let value = createInitValue();
|
|
84
85
|
const boundedSeries = [];
|
|
85
|
-
for(let i = 0; i < count; i
|
|
86
|
+
for(let i = 0; i < count; i += 1){
|
|
86
87
|
value = faker.number.float({
|
|
87
88
|
max: upperLimit,
|
|
88
89
|
min: lowerLimit
|
|
@@ -1,29 +1,35 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare const valueConfigScheme:
|
|
3
|
-
type:
|
|
4
|
-
generateFn:
|
|
5
|
-
},
|
|
6
|
-
export declare const selectionConfigScheme:
|
|
7
|
-
type:
|
|
8
|
-
items:
|
|
9
|
-
},
|
|
10
|
-
export declare const arrayConfigScheme:
|
|
11
|
-
type:
|
|
12
|
-
item:
|
|
13
|
-
len:
|
|
14
|
-
},
|
|
15
|
-
export declare const tupleConfigScheme:
|
|
16
|
-
type:
|
|
17
|
-
configItems:
|
|
18
|
-
},
|
|
19
|
-
export declare const objConfigScheme:
|
|
20
|
-
type:
|
|
21
|
-
content:
|
|
22
|
-
},
|
|
23
|
-
export declare const boundedSeriesScheme:
|
|
24
|
-
type:
|
|
25
|
-
upperLimit:
|
|
26
|
-
lowerLimit:
|
|
27
|
-
createInitValue:
|
|
28
|
-
count:
|
|
29
|
-
},
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
export declare const valueConfigScheme: v.ObjectSchema<{
|
|
3
|
+
readonly type: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "invalid type string">]>;
|
|
4
|
+
readonly generateFn: v.AnySchema;
|
|
5
|
+
}, undefined>;
|
|
6
|
+
export declare const selectionConfigScheme: v.ObjectSchema<{
|
|
7
|
+
readonly type: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "invalid type string">]>;
|
|
8
|
+
readonly items: v.SchemaWithPipe<readonly [v.ArraySchema<v.AnySchema, undefined>, v.NonEmptyAction<any[], "items can not be empty">]>;
|
|
9
|
+
}, undefined>;
|
|
10
|
+
export declare const arrayConfigScheme: v.ObjectSchema<{
|
|
11
|
+
readonly type: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "invalid type string">]>;
|
|
12
|
+
readonly item: v.ObjectSchema<{}, undefined>;
|
|
13
|
+
readonly len: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
14
|
+
}, undefined>;
|
|
15
|
+
export declare const tupleConfigScheme: v.ObjectSchema<{
|
|
16
|
+
readonly type: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "invalid type string">]>;
|
|
17
|
+
readonly configItems: v.ArraySchema<v.AnySchema, undefined>;
|
|
18
|
+
}, undefined>;
|
|
19
|
+
export declare const objConfigScheme: v.ObjectSchema<{
|
|
20
|
+
readonly type: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "invalid type string">]>;
|
|
21
|
+
readonly content: v.ObjectSchema<{}, undefined>;
|
|
22
|
+
}, undefined>;
|
|
23
|
+
export declare const boundedSeriesScheme: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
24
|
+
readonly type: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "invalid type string">]>;
|
|
25
|
+
readonly upperLimit: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
26
|
+
readonly lowerLimit: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
27
|
+
readonly createInitValue: v.AnySchema;
|
|
28
|
+
readonly count: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
29
|
+
}, undefined>, v.CheckAction<{
|
|
30
|
+
type: string;
|
|
31
|
+
upperLimit: number;
|
|
32
|
+
lowerLimit: number;
|
|
33
|
+
createInitValue: any;
|
|
34
|
+
count: number;
|
|
35
|
+
}, "lowerLimit can not greater then upperLimit">]>;
|
|
@@ -4,7 +4,7 @@ export declare const createValueGenerator: <R = unknown>(config: ValueConfig<unk
|
|
|
4
4
|
export declare const createSelectionGenerator: <T extends SelectionConfig<unknown>>(config: T) => (() => Result<T>);
|
|
5
5
|
export declare const createObjectGenerator: <T extends ObjectConfig<unknown>>(config: T, customTypeMatch?: (config: unknown, path?: string) => ValueConfig<unknown>) => (() => Result<T>);
|
|
6
6
|
export declare const createArrayGenerator: <T extends ArrayConfig<unknown>>(config: T, customTypeMatch?: (config: unknown, path?: string) => ValueConfig<unknown>) => (() => Result<T>);
|
|
7
|
-
export declare const createTupleGenerator: <T extends TupleConfig<unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown> | TupleConfig<unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown> | TupleConfig<unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown> | TupleConfig<unknown, unknown, unknown, unknown, unknown, unknown> | TupleConfig<unknown, unknown, unknown, unknown, unknown> | TupleConfig<unknown, unknown, unknown, unknown> | TupleConfig<unknown, unknown, unknown> | TupleConfig<unknown, unknown> | TupleConfig<unknown>>(config: T, customTypeMatch?: (config: unknown, path
|
|
7
|
+
export declare const createTupleGenerator: <T extends TupleConfig<unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown> | TupleConfig<unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown> | TupleConfig<unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown> | TupleConfig<unknown, unknown, unknown, unknown, unknown, unknown> | TupleConfig<unknown, unknown, unknown, unknown, unknown> | TupleConfig<unknown, unknown, unknown, unknown> | TupleConfig<unknown, unknown, unknown> | TupleConfig<unknown, unknown> | TupleConfig<unknown>>(config: T, customTypeMatch?: (config: unknown, path?: string) => ValueConfig<unknown>) => (() => Result<T>);
|
|
8
8
|
export declare const createBoundedSeriesGenerator: <T extends BoundedSeriesConfig>(config: T) => (() => Result<T>);
|
|
9
|
-
export declare const createGeneratorByType: <T extends AllConfig<unknown>>(config: T, customTypeMatch?: (config: unknown, path
|
|
9
|
+
export declare const createGeneratorByType: <T extends AllConfig<unknown>>(config: T, customTypeMatch?: (config: unknown, path?: string) => ValueConfig<unknown>) => (() => Result<T>);
|
|
10
10
|
export {};
|
package/dist/types/type.d.ts
CHANGED
|
@@ -37,16 +37,7 @@ export type TupleConfig<A, B = undefined, C = undefined, D = undefined, E = unde
|
|
|
37
37
|
};
|
|
38
38
|
export type Result<T> = T extends ValueConfig<infer U> ? U : T extends SelectionConfig<infer S> ? S : T extends BoundedSeriesConfig ? number[] : T extends ArrayConfig<infer W> ? Array<Result<W>> : T extends ObjectConfigWithFn<infer _, infer R> ? R : T extends ObjectConfig<infer O> ? {
|
|
39
39
|
[K in keyof O]: Result<O[K]>;
|
|
40
|
-
} : T extends TupleConfig<infer A, infer B, infer C, infer D, infer E, infer F, infer G, infer H, infer I, infer J> ? J extends undefined ? I extends undefined ? H extends undefined ? G extends undefined ? F extends undefined ? E extends undefined ? D extends undefined ? C extends undefined ? B extends undefined ? [Result<A>] : [Result<A>, Result<B>] : [
|
|
41
|
-
Result<A>,
|
|
42
|
-
Result<B>,
|
|
43
|
-
Result<C>
|
|
44
|
-
] : [
|
|
45
|
-
Result<A>,
|
|
46
|
-
Result<B>,
|
|
47
|
-
Result<C>,
|
|
48
|
-
Result<D>
|
|
49
|
-
] : [
|
|
40
|
+
} : T extends TupleConfig<infer A, infer B, infer C, infer D, infer E, infer F, infer G, infer H, infer I, infer J> ? J extends undefined ? I extends undefined ? H extends undefined ? G extends undefined ? F extends undefined ? E extends undefined ? D extends undefined ? C extends undefined ? B extends undefined ? [Result<A>] : [Result<A>, Result<B>] : [Result<A>, Result<B>, Result<C>] : [Result<A>, Result<B>, Result<C>, Result<D>] : [
|
|
50
41
|
Result<A>,
|
|
51
42
|
Result<B>,
|
|
52
43
|
Result<C>,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { faker } from "@faker-js/faker";
|
|
2
|
-
import type { ValueConfig } from "
|
|
2
|
+
import type { ValueConfig } from "..";
|
|
3
3
|
/** Airline [aircraftType](https://fakerjs.dev/api/airline.html#aircraftType) */
|
|
4
4
|
export declare const aircraftType: () => ValueConfig<"narrowbody" | "regional" | "widebody">;
|
|
5
5
|
type Airline = ReturnType<typeof faker.airline.airline>;
|
|
@@ -18,14 +18,14 @@ export declare const flightNumber: (options?: {
|
|
|
18
18
|
max: number;
|
|
19
19
|
};
|
|
20
20
|
addLeadingZeros?: boolean;
|
|
21
|
-
}) => ValueConfig<string>;
|
|
21
|
+
} | undefined) => ValueConfig<string>;
|
|
22
22
|
/** Airline [recordLocator](https://fakerjs.dev/api/airline.html#recordLocator) */
|
|
23
23
|
export declare const recordLocator: (options?: {
|
|
24
24
|
allowNumerics?: boolean;
|
|
25
25
|
allowVisuallySimilarCharacters?: boolean;
|
|
26
|
-
}) => ValueConfig<string>;
|
|
26
|
+
} | undefined) => ValueConfig<string>;
|
|
27
27
|
/** Airline [seat](https://fakerjs.dev/api/airline.html#seat) */
|
|
28
28
|
export declare const seat: (options?: {
|
|
29
29
|
aircraftType?: import("@faker-js/faker").AircraftType;
|
|
30
|
-
}) => ValueConfig<string>;
|
|
30
|
+
} | undefined) => ValueConfig<string>;
|
|
31
31
|
export {};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/** Color [cmyk](https://fakerjs.dev/api/color.html#cmyk) */
|
|
2
2
|
export declare const cmyk: (options?: {
|
|
3
3
|
format?: import("@faker-js/faker").ColorFormat;
|
|
4
|
-
}) => import("..").ValueConfig<string | number[]>;
|
|
4
|
+
} | undefined) => import("..").ValueConfig<string | number[]>;
|
|
5
5
|
/** Color [colorByCSSColorSpace](https://fakerjs.dev/api/color.html#colorByCSSColorSpace) */
|
|
6
6
|
export declare const colorByCSSColorSpace: (options?: {
|
|
7
7
|
format?: import("@faker-js/faker").ColorFormat;
|
|
8
8
|
space?: import("@faker-js/faker").CssSpaceType;
|
|
9
|
-
}) => import("..").ValueConfig<string | number[]>;
|
|
9
|
+
} | undefined) => import("..").ValueConfig<string | number[]>;
|
|
10
10
|
/** Color [cssSupportedFunction](https://fakerjs.dev/api/color.html#cssSupportedFunction) */
|
|
11
11
|
export declare const cssSupportedFunction: () => import("..").ValueConfig<"rgb" | "rgba" | "hsl" | "hsla" | "hwb" | "cmyk" | "lab" | "lch" | "color">;
|
|
12
12
|
/** Color [cssSupportedSpace](https://fakerjs.dev/api/color.html#cssSupportedSpace) */
|
|
@@ -15,27 +15,27 @@ export declare const cssSupportedSpace: () => import("..").ValueConfig<"sRGB" |
|
|
|
15
15
|
export declare const hsl: (options?: {
|
|
16
16
|
format?: import("@faker-js/faker").ColorFormat;
|
|
17
17
|
includeAlpha?: boolean;
|
|
18
|
-
}) => import("..").ValueConfig<string | number[]>;
|
|
18
|
+
} | undefined) => import("..").ValueConfig<string | number[]>;
|
|
19
19
|
/** Color [human](https://fakerjs.dev/api/color.html#human) */
|
|
20
20
|
export declare const human: () => import("..").ValueConfig<string>;
|
|
21
21
|
/** Color [hwb](https://fakerjs.dev/api/color.html#hwb) */
|
|
22
22
|
export declare const hwb: (options?: {
|
|
23
23
|
format?: import("@faker-js/faker").ColorFormat;
|
|
24
|
-
}) => import("..").ValueConfig<string | number[]>;
|
|
24
|
+
} | undefined) => import("..").ValueConfig<string | number[]>;
|
|
25
25
|
/** Color [lab](https://fakerjs.dev/api/color.html#lab) */
|
|
26
26
|
export declare const lab: (options?: {
|
|
27
27
|
format?: import("@faker-js/faker").ColorFormat;
|
|
28
|
-
}) => import("..").ValueConfig<string | number[]>;
|
|
28
|
+
} | undefined) => import("..").ValueConfig<string | number[]>;
|
|
29
29
|
/** Color [lch](https://fakerjs.dev/api/color.html#lch) */
|
|
30
30
|
export declare const lch: (options?: {
|
|
31
31
|
format?: import("@faker-js/faker").ColorFormat;
|
|
32
|
-
}) => import("..").ValueConfig<string | number[]>;
|
|
32
|
+
} | undefined) => import("..").ValueConfig<string | number[]>;
|
|
33
33
|
/** Color [rgb](https://fakerjs.dev/api/color.html#rgb) */
|
|
34
34
|
export declare const rgb: (options?: {
|
|
35
35
|
prefix?: string;
|
|
36
36
|
casing?: import("@faker-js/faker").Casing;
|
|
37
37
|
format?: "hex" | import("@faker-js/faker").ColorFormat;
|
|
38
38
|
includeAlpha?: boolean;
|
|
39
|
-
}) => import("..").ValueConfig<string | number[]>;
|
|
39
|
+
} | undefined) => import("..").ValueConfig<string | number[]>;
|
|
40
40
|
/** Color [space](https://fakerjs.dev/api/color.html#space) */
|
|
41
41
|
export declare const space: () => import("..").ValueConfig<string>;
|
|
@@ -4,14 +4,14 @@ export declare const department: () => import("..").ValueConfig<string>;
|
|
|
4
4
|
export declare const isbn: (options?: 10 | 13 | {
|
|
5
5
|
variant?: 10 | 13;
|
|
6
6
|
separator?: string;
|
|
7
|
-
}) => import("..").ValueConfig<string>;
|
|
7
|
+
} | undefined) => import("..").ValueConfig<string>;
|
|
8
8
|
/** Commerce [price](https://fakerjs.dev/api/commerce.html#price) */
|
|
9
9
|
export declare const price: (options?: {
|
|
10
10
|
min?: number;
|
|
11
11
|
max?: number;
|
|
12
12
|
dec?: number;
|
|
13
13
|
symbol?: string;
|
|
14
|
-
}) => import("..").ValueConfig<string>;
|
|
14
|
+
} | undefined) => import("..").ValueConfig<string>;
|
|
15
15
|
/** Commerce [product](https://fakerjs.dev/api/commerce.html#product) */
|
|
16
16
|
export declare const product: () => import("..").ValueConfig<string>;
|
|
17
17
|
/** Commerce [productAdjective](https://fakerjs.dev/api/commerce.html#productAdjective) */
|