yuppi 1.2.8 → 1.2.10
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 -2
- package/dist/main.d.mts +24 -11
- package/dist/main.d.ts +24 -11
- package/dist/main.js +23 -26
- package/dist/main.mjs +23 -26
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -203,9 +203,9 @@ Validate the properties with your Yuppi schema.
|
|
|
203
203
|
> }
|
|
204
204
|
> */
|
|
205
205
|
> } catch (error) {
|
|
206
|
-
> const
|
|
206
|
+
> const errors = (error as ValidationError).errors;
|
|
207
207
|
>
|
|
208
|
-
> console.log(
|
|
208
|
+
> console.log(errors[0]); // "Field email must match the required pattern ^[a-zA-Z0-9._-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$"
|
|
209
209
|
> }
|
|
210
210
|
> ```
|
|
211
211
|
|
package/dist/main.d.mts
CHANGED
|
@@ -6,12 +6,7 @@ type AnyObject = AnyObject$1;
|
|
|
6
6
|
|
|
7
7
|
type JSONSchema = TObject<Record<string, TAnySchema>>;
|
|
8
8
|
|
|
9
|
-
type
|
|
10
|
-
default?: unknown;
|
|
11
|
-
nullable: boolean;
|
|
12
|
-
required: boolean;
|
|
13
|
-
};
|
|
14
|
-
type String = Base & {
|
|
9
|
+
type String = {
|
|
15
10
|
type: 'string';
|
|
16
11
|
enum?: string[];
|
|
17
12
|
pattern?: string;
|
|
@@ -19,8 +14,11 @@ type String = Base & {
|
|
|
19
14
|
max?: number;
|
|
20
15
|
lowercase?: boolean;
|
|
21
16
|
uppercase?: boolean;
|
|
17
|
+
default?: string | null;
|
|
18
|
+
nullable: boolean;
|
|
19
|
+
required: boolean;
|
|
22
20
|
};
|
|
23
|
-
type Number =
|
|
21
|
+
type Number = {
|
|
24
22
|
type: 'number';
|
|
25
23
|
enum?: number[];
|
|
26
24
|
min?: number;
|
|
@@ -28,24 +26,39 @@ type Number = Base & {
|
|
|
28
26
|
integer?: boolean;
|
|
29
27
|
positive?: boolean;
|
|
30
28
|
negative?: boolean;
|
|
29
|
+
default?: number | null;
|
|
30
|
+
nullable: boolean;
|
|
31
|
+
required: boolean;
|
|
31
32
|
};
|
|
32
|
-
type Boolean =
|
|
33
|
+
type Boolean = {
|
|
33
34
|
type: 'boolean';
|
|
35
|
+
default?: boolean | null;
|
|
36
|
+
nullable: boolean;
|
|
37
|
+
required: boolean;
|
|
34
38
|
};
|
|
35
|
-
type Date =
|
|
39
|
+
type Date = {
|
|
36
40
|
type: 'date';
|
|
37
41
|
min?: string;
|
|
38
42
|
max?: string;
|
|
43
|
+
default?: string | null;
|
|
44
|
+
nullable: boolean;
|
|
45
|
+
required: boolean;
|
|
39
46
|
};
|
|
40
|
-
type Object$1 =
|
|
47
|
+
type Object$1 = {
|
|
41
48
|
type: 'object';
|
|
42
49
|
properties: Schema;
|
|
50
|
+
default?: Record<string, unknown> | null;
|
|
51
|
+
nullable: boolean;
|
|
52
|
+
required: boolean;
|
|
43
53
|
};
|
|
44
|
-
type Array =
|
|
54
|
+
type Array = {
|
|
45
55
|
type: 'array';
|
|
46
56
|
min?: number;
|
|
47
57
|
max?: number;
|
|
48
58
|
items: Types;
|
|
59
|
+
default?: unknown[] | null;
|
|
60
|
+
nullable: boolean;
|
|
61
|
+
required: boolean;
|
|
49
62
|
};
|
|
50
63
|
type Types = String | Number | Boolean | Date | Object$1 | Array;
|
|
51
64
|
type Schema = Record<string, Types>;
|
package/dist/main.d.ts
CHANGED
|
@@ -6,12 +6,7 @@ type AnyObject = AnyObject$1;
|
|
|
6
6
|
|
|
7
7
|
type JSONSchema = TObject<Record<string, TAnySchema>>;
|
|
8
8
|
|
|
9
|
-
type
|
|
10
|
-
default?: unknown;
|
|
11
|
-
nullable: boolean;
|
|
12
|
-
required: boolean;
|
|
13
|
-
};
|
|
14
|
-
type String = Base & {
|
|
9
|
+
type String = {
|
|
15
10
|
type: 'string';
|
|
16
11
|
enum?: string[];
|
|
17
12
|
pattern?: string;
|
|
@@ -19,8 +14,11 @@ type String = Base & {
|
|
|
19
14
|
max?: number;
|
|
20
15
|
lowercase?: boolean;
|
|
21
16
|
uppercase?: boolean;
|
|
17
|
+
default?: string | null;
|
|
18
|
+
nullable: boolean;
|
|
19
|
+
required: boolean;
|
|
22
20
|
};
|
|
23
|
-
type Number =
|
|
21
|
+
type Number = {
|
|
24
22
|
type: 'number';
|
|
25
23
|
enum?: number[];
|
|
26
24
|
min?: number;
|
|
@@ -28,24 +26,39 @@ type Number = Base & {
|
|
|
28
26
|
integer?: boolean;
|
|
29
27
|
positive?: boolean;
|
|
30
28
|
negative?: boolean;
|
|
29
|
+
default?: number | null;
|
|
30
|
+
nullable: boolean;
|
|
31
|
+
required: boolean;
|
|
31
32
|
};
|
|
32
|
-
type Boolean =
|
|
33
|
+
type Boolean = {
|
|
33
34
|
type: 'boolean';
|
|
35
|
+
default?: boolean | null;
|
|
36
|
+
nullable: boolean;
|
|
37
|
+
required: boolean;
|
|
34
38
|
};
|
|
35
|
-
type Date =
|
|
39
|
+
type Date = {
|
|
36
40
|
type: 'date';
|
|
37
41
|
min?: string;
|
|
38
42
|
max?: string;
|
|
43
|
+
default?: string | null;
|
|
44
|
+
nullable: boolean;
|
|
45
|
+
required: boolean;
|
|
39
46
|
};
|
|
40
|
-
type Object$1 =
|
|
47
|
+
type Object$1 = {
|
|
41
48
|
type: 'object';
|
|
42
49
|
properties: Schema;
|
|
50
|
+
default?: Record<string, unknown> | null;
|
|
51
|
+
nullable: boolean;
|
|
52
|
+
required: boolean;
|
|
43
53
|
};
|
|
44
|
-
type Array =
|
|
54
|
+
type Array = {
|
|
45
55
|
type: 'array';
|
|
46
56
|
min?: number;
|
|
47
57
|
max?: number;
|
|
48
58
|
items: Types;
|
|
59
|
+
default?: unknown[] | null;
|
|
60
|
+
nullable: boolean;
|
|
61
|
+
required: boolean;
|
|
49
62
|
};
|
|
50
63
|
type Types = String | Number | Boolean | Date | Object$1 | Array;
|
|
51
64
|
type Schema = Record<string, Types>;
|
package/dist/main.js
CHANGED
|
@@ -51,7 +51,7 @@ var convertToYup = (schema, error_messages) => {
|
|
|
51
51
|
if (config.required)
|
|
52
52
|
schema2 = schema2.test(
|
|
53
53
|
"required",
|
|
54
|
-
({ path }) => (error_messages?.base?.required ?? "").
|
|
54
|
+
({ path }) => (error_messages?.base?.required ?? "").replaceAll("{path}", path),
|
|
55
55
|
(property) => {
|
|
56
56
|
if (property === void 0) return false;
|
|
57
57
|
if (typeof property === "string" && property.trim() === "") return false;
|
|
@@ -59,78 +59,74 @@ var convertToYup = (schema, error_messages) => {
|
|
|
59
59
|
return true;
|
|
60
60
|
}
|
|
61
61
|
);
|
|
62
|
-
if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path }) => (error_messages?.base?.nullable ?? "").
|
|
62
|
+
if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path }) => (error_messages?.base?.nullable ?? "").replaceAll("{path}", path));
|
|
63
63
|
if (config.default) schema2 = schema2.default(config.default);
|
|
64
64
|
return schema2;
|
|
65
65
|
};
|
|
66
66
|
const build = (key, config) => {
|
|
67
67
|
let schema2;
|
|
68
68
|
if (config.type === "string") {
|
|
69
|
-
schema2 = Yup.string().typeError(({ path }) => (error_messages?.string?.type ?? "").
|
|
69
|
+
schema2 = Yup.string().typeError(({ path }) => (error_messages?.string?.type ?? "").replaceAll("{path}", path));
|
|
70
70
|
schema2 = base(schema2, key, config);
|
|
71
71
|
schema2 = schema2.transform((property) => typeof property === "string" ? property.trim() : property);
|
|
72
72
|
if (config.enum)
|
|
73
73
|
schema2 = schema2.oneOf(
|
|
74
74
|
config.enum.map((item) => item.trim()),
|
|
75
|
-
({ path }) => (error_messages?.string?.enum ?? "").
|
|
76
|
-
);
|
|
77
|
-
if (config.pattern)
|
|
78
|
-
schema2 = schema2.matches(
|
|
79
|
-
new RegExp(config.pattern ?? Any),
|
|
80
|
-
({ path }) => (error_messages?.string?.pattern ?? "").split("{path}").join(path).split("{pattern}").join(new RegExp(config.pattern ?? Any).source)
|
|
75
|
+
({ path }) => (error_messages?.string?.enum ?? "").replaceAll("{path}", path)
|
|
81
76
|
);
|
|
77
|
+
if (config.pattern) schema2 = schema2.matches(new RegExp(config.pattern ?? Any), ({ path }) => (error_messages?.string?.pattern ?? "").replaceAll("{path}", path).replaceAll("{pattern}", new RegExp(config.pattern ?? Any).source));
|
|
82
78
|
if (config.min)
|
|
83
79
|
schema2 = schema2.min(
|
|
84
80
|
config.min,
|
|
85
|
-
({ path, min }) => (error_messages?.string?.min ?? "").
|
|
81
|
+
({ path, min }) => (error_messages?.string?.min ?? "").replaceAll("{path}", path).replaceAll("{min}", min.toString()).replaceAll("{plural_suffix}", min > 1 ? "s" : "")
|
|
86
82
|
);
|
|
87
83
|
if (config.max)
|
|
88
84
|
schema2 = schema2.max(
|
|
89
85
|
config.max,
|
|
90
|
-
({ path, max }) => (error_messages?.string?.max ?? "").
|
|
86
|
+
({ path, max }) => (error_messages?.string?.max ?? "").replaceAll("{path}", path).replaceAll("{max}", max.toString()).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
|
|
91
87
|
);
|
|
92
88
|
if (config.lowercase) schema2 = schema2.transform((property) => typeof property === "string" ? property.toLowerCase() : property);
|
|
93
89
|
if (config.uppercase) schema2 = schema2.transform((property) => typeof property === "string" ? property.toUpperCase() : property);
|
|
94
90
|
return schema2;
|
|
95
91
|
} else if (config.type === "number") {
|
|
96
|
-
schema2 = Yup.number().typeError(({ path }) => (error_messages?.number?.type ?? "").
|
|
92
|
+
schema2 = Yup.number().typeError(({ path }) => (error_messages?.number?.type ?? "").replaceAll("{path}", path));
|
|
97
93
|
schema2 = base(schema2, key, config);
|
|
98
|
-
if (config.enum) schema2 = schema2.oneOf(config.enum, ({ path }) => (error_messages?.number?.enum ?? "").
|
|
99
|
-
if (config.min) schema2 = schema2.min(config.min, ({ path, min }) => (error_messages?.number?.min ?? "").
|
|
100
|
-
if (config.max) schema2 = schema2.max(config.max, ({ path, max }) => (error_messages?.number?.max ?? "").
|
|
101
|
-
if (config.integer) schema2 = schema2.integer(({ path }) => (error_messages?.number?.integer ?? "").
|
|
102
|
-
if (config.positive) schema2 = schema2.positive(({ path }) => (error_messages?.number?.positive ?? "").
|
|
103
|
-
if (config.negative) schema2 = schema2.negative(({ path }) => (error_messages?.number?.negative ?? "").
|
|
94
|
+
if (config.enum) schema2 = schema2.oneOf(config.enum, ({ path }) => (error_messages?.number?.enum ?? "").replaceAll("{path}", path));
|
|
95
|
+
if (config.min) schema2 = schema2.min(config.min, ({ path, min }) => (error_messages?.number?.min ?? "").replaceAll("{path}", path).replaceAll("{min}", min.toString()));
|
|
96
|
+
if (config.max) schema2 = schema2.max(config.max, ({ path, max }) => (error_messages?.number?.max ?? "").replaceAll("{path}", path).replaceAll("{max}", max.toString()));
|
|
97
|
+
if (config.integer) schema2 = schema2.integer(({ path }) => (error_messages?.number?.integer ?? "").replaceAll("{path}", path));
|
|
98
|
+
if (config.positive) schema2 = schema2.positive(({ path }) => (error_messages?.number?.positive ?? "").replaceAll("{path}", path));
|
|
99
|
+
if (config.negative) schema2 = schema2.negative(({ path }) => (error_messages?.number?.negative ?? "").replaceAll("{path}", path));
|
|
104
100
|
return schema2;
|
|
105
101
|
} else if (config.type === "boolean") {
|
|
106
|
-
schema2 = Yup.boolean().typeError(({ path }) => (error_messages?.boolean?.type ?? "").
|
|
102
|
+
schema2 = Yup.boolean().typeError(({ path }) => (error_messages?.boolean?.type ?? "").replaceAll("{path}", path));
|
|
107
103
|
schema2 = base(schema2, key, config);
|
|
108
104
|
return schema2;
|
|
109
105
|
} else if (config.type === "date") {
|
|
110
|
-
schema2 = Yup.date().typeError(({ path }) => (error_messages?.date?.type ?? "").
|
|
106
|
+
schema2 = Yup.date().typeError(({ path }) => (error_messages?.date?.type ?? "").replaceAll("{path}", path));
|
|
111
107
|
schema2 = base(schema2, key, config);
|
|
112
|
-
if (config.min) schema2 = schema2.min(config.min, ({ path, min }) => (error_messages?.date?.min ?? "").
|
|
113
|
-
if (config.max) schema2 = schema2.max(config.max, ({ path, max }) => (error_messages?.date?.max ?? "").
|
|
108
|
+
if (config.min) schema2 = schema2.min(config.min, ({ path, min }) => (error_messages?.date?.min ?? "").replaceAll("{path}", path).replaceAll("{min}", new Date(min).toISOString()));
|
|
109
|
+
if (config.max) schema2 = schema2.max(config.max, ({ path, max }) => (error_messages?.date?.max ?? "").replaceAll("{path}", path).replaceAll("{max}", new Date(max).toISOString()));
|
|
114
110
|
return schema2;
|
|
115
111
|
} else if (config.type === "object") {
|
|
116
|
-
schema2 = Yup.object().typeError(({ path }) => (error_messages?.object?.type ?? "").
|
|
112
|
+
schema2 = Yup.object().typeError(({ path }) => (error_messages?.object?.type ?? "").replaceAll("{path}", path));
|
|
117
113
|
schema2 = base(schema2, key, config);
|
|
118
114
|
const nested_properties = {};
|
|
119
115
|
for (const [nested_key, nested_config] of Object.entries(config.properties)) nested_properties[nested_key] = build(nested_key, nested_config);
|
|
120
116
|
schema2 = schema2.shape(nested_properties);
|
|
121
117
|
return schema2;
|
|
122
118
|
} else if (config.type === "array") {
|
|
123
|
-
schema2 = Yup.array().typeError(({ path }) => (error_messages?.array?.type ?? "").
|
|
119
|
+
schema2 = Yup.array().typeError(({ path }) => (error_messages?.array?.type ?? "").replaceAll("{path}", path));
|
|
124
120
|
schema2 = base(schema2, key, config);
|
|
125
121
|
if (config.min)
|
|
126
122
|
schema2 = schema2.min(
|
|
127
123
|
config.min,
|
|
128
|
-
({ path, min }) => (error_messages?.array?.min ?? "").
|
|
124
|
+
({ path, min }) => (error_messages?.array?.min ?? "").replaceAll("{path}", path).replaceAll("{min}", min.toString()).replaceAll("{plural_suffix}", min > 1 ? "s" : "")
|
|
129
125
|
);
|
|
130
126
|
if (config.max)
|
|
131
127
|
schema2 = schema2.max(
|
|
132
128
|
config.max,
|
|
133
|
-
({ path, max }) => (error_messages?.array?.max ?? "").
|
|
129
|
+
({ path, max }) => (error_messages?.array?.max ?? "").replaceAll("{path}", path).replaceAll("{max}", max.toString()).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
|
|
134
130
|
);
|
|
135
131
|
schema2 = schema2.of(build(key, config.items));
|
|
136
132
|
return schema2;
|
|
@@ -232,6 +228,7 @@ var YuppiOptionsDefault = {
|
|
|
232
228
|
|
|
233
229
|
// src/Yuppi.class.ts
|
|
234
230
|
var Yuppi = class {
|
|
231
|
+
options;
|
|
235
232
|
constructor(options = YuppiOptionsDefault) {
|
|
236
233
|
this.options = import_lodash.default.merge({}, YuppiOptionsDefault, options);
|
|
237
234
|
}
|
package/dist/main.mjs
CHANGED
|
@@ -20,7 +20,7 @@ var convertToYup = (schema, error_messages) => {
|
|
|
20
20
|
if (config.required)
|
|
21
21
|
schema2 = schema2.test(
|
|
22
22
|
"required",
|
|
23
|
-
({ path }) => (error_messages?.base?.required ?? "").
|
|
23
|
+
({ path }) => (error_messages?.base?.required ?? "").replaceAll("{path}", path),
|
|
24
24
|
(property) => {
|
|
25
25
|
if (property === void 0) return false;
|
|
26
26
|
if (typeof property === "string" && property.trim() === "") return false;
|
|
@@ -28,78 +28,74 @@ var convertToYup = (schema, error_messages) => {
|
|
|
28
28
|
return true;
|
|
29
29
|
}
|
|
30
30
|
);
|
|
31
|
-
if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path }) => (error_messages?.base?.nullable ?? "").
|
|
31
|
+
if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path }) => (error_messages?.base?.nullable ?? "").replaceAll("{path}", path));
|
|
32
32
|
if (config.default) schema2 = schema2.default(config.default);
|
|
33
33
|
return schema2;
|
|
34
34
|
};
|
|
35
35
|
const build = (key, config) => {
|
|
36
36
|
let schema2;
|
|
37
37
|
if (config.type === "string") {
|
|
38
|
-
schema2 = Yup.string().typeError(({ path }) => (error_messages?.string?.type ?? "").
|
|
38
|
+
schema2 = Yup.string().typeError(({ path }) => (error_messages?.string?.type ?? "").replaceAll("{path}", path));
|
|
39
39
|
schema2 = base(schema2, key, config);
|
|
40
40
|
schema2 = schema2.transform((property) => typeof property === "string" ? property.trim() : property);
|
|
41
41
|
if (config.enum)
|
|
42
42
|
schema2 = schema2.oneOf(
|
|
43
43
|
config.enum.map((item) => item.trim()),
|
|
44
|
-
({ path }) => (error_messages?.string?.enum ?? "").
|
|
45
|
-
);
|
|
46
|
-
if (config.pattern)
|
|
47
|
-
schema2 = schema2.matches(
|
|
48
|
-
new RegExp(config.pattern ?? Any),
|
|
49
|
-
({ path }) => (error_messages?.string?.pattern ?? "").split("{path}").join(path).split("{pattern}").join(new RegExp(config.pattern ?? Any).source)
|
|
44
|
+
({ path }) => (error_messages?.string?.enum ?? "").replaceAll("{path}", path)
|
|
50
45
|
);
|
|
46
|
+
if (config.pattern) schema2 = schema2.matches(new RegExp(config.pattern ?? Any), ({ path }) => (error_messages?.string?.pattern ?? "").replaceAll("{path}", path).replaceAll("{pattern}", new RegExp(config.pattern ?? Any).source));
|
|
51
47
|
if (config.min)
|
|
52
48
|
schema2 = schema2.min(
|
|
53
49
|
config.min,
|
|
54
|
-
({ path, min }) => (error_messages?.string?.min ?? "").
|
|
50
|
+
({ path, min }) => (error_messages?.string?.min ?? "").replaceAll("{path}", path).replaceAll("{min}", min.toString()).replaceAll("{plural_suffix}", min > 1 ? "s" : "")
|
|
55
51
|
);
|
|
56
52
|
if (config.max)
|
|
57
53
|
schema2 = schema2.max(
|
|
58
54
|
config.max,
|
|
59
|
-
({ path, max }) => (error_messages?.string?.max ?? "").
|
|
55
|
+
({ path, max }) => (error_messages?.string?.max ?? "").replaceAll("{path}", path).replaceAll("{max}", max.toString()).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
|
|
60
56
|
);
|
|
61
57
|
if (config.lowercase) schema2 = schema2.transform((property) => typeof property === "string" ? property.toLowerCase() : property);
|
|
62
58
|
if (config.uppercase) schema2 = schema2.transform((property) => typeof property === "string" ? property.toUpperCase() : property);
|
|
63
59
|
return schema2;
|
|
64
60
|
} else if (config.type === "number") {
|
|
65
|
-
schema2 = Yup.number().typeError(({ path }) => (error_messages?.number?.type ?? "").
|
|
61
|
+
schema2 = Yup.number().typeError(({ path }) => (error_messages?.number?.type ?? "").replaceAll("{path}", path));
|
|
66
62
|
schema2 = base(schema2, key, config);
|
|
67
|
-
if (config.enum) schema2 = schema2.oneOf(config.enum, ({ path }) => (error_messages?.number?.enum ?? "").
|
|
68
|
-
if (config.min) schema2 = schema2.min(config.min, ({ path, min }) => (error_messages?.number?.min ?? "").
|
|
69
|
-
if (config.max) schema2 = schema2.max(config.max, ({ path, max }) => (error_messages?.number?.max ?? "").
|
|
70
|
-
if (config.integer) schema2 = schema2.integer(({ path }) => (error_messages?.number?.integer ?? "").
|
|
71
|
-
if (config.positive) schema2 = schema2.positive(({ path }) => (error_messages?.number?.positive ?? "").
|
|
72
|
-
if (config.negative) schema2 = schema2.negative(({ path }) => (error_messages?.number?.negative ?? "").
|
|
63
|
+
if (config.enum) schema2 = schema2.oneOf(config.enum, ({ path }) => (error_messages?.number?.enum ?? "").replaceAll("{path}", path));
|
|
64
|
+
if (config.min) schema2 = schema2.min(config.min, ({ path, min }) => (error_messages?.number?.min ?? "").replaceAll("{path}", path).replaceAll("{min}", min.toString()));
|
|
65
|
+
if (config.max) schema2 = schema2.max(config.max, ({ path, max }) => (error_messages?.number?.max ?? "").replaceAll("{path}", path).replaceAll("{max}", max.toString()));
|
|
66
|
+
if (config.integer) schema2 = schema2.integer(({ path }) => (error_messages?.number?.integer ?? "").replaceAll("{path}", path));
|
|
67
|
+
if (config.positive) schema2 = schema2.positive(({ path }) => (error_messages?.number?.positive ?? "").replaceAll("{path}", path));
|
|
68
|
+
if (config.negative) schema2 = schema2.negative(({ path }) => (error_messages?.number?.negative ?? "").replaceAll("{path}", path));
|
|
73
69
|
return schema2;
|
|
74
70
|
} else if (config.type === "boolean") {
|
|
75
|
-
schema2 = Yup.boolean().typeError(({ path }) => (error_messages?.boolean?.type ?? "").
|
|
71
|
+
schema2 = Yup.boolean().typeError(({ path }) => (error_messages?.boolean?.type ?? "").replaceAll("{path}", path));
|
|
76
72
|
schema2 = base(schema2, key, config);
|
|
77
73
|
return schema2;
|
|
78
74
|
} else if (config.type === "date") {
|
|
79
|
-
schema2 = Yup.date().typeError(({ path }) => (error_messages?.date?.type ?? "").
|
|
75
|
+
schema2 = Yup.date().typeError(({ path }) => (error_messages?.date?.type ?? "").replaceAll("{path}", path));
|
|
80
76
|
schema2 = base(schema2, key, config);
|
|
81
|
-
if (config.min) schema2 = schema2.min(config.min, ({ path, min }) => (error_messages?.date?.min ?? "").
|
|
82
|
-
if (config.max) schema2 = schema2.max(config.max, ({ path, max }) => (error_messages?.date?.max ?? "").
|
|
77
|
+
if (config.min) schema2 = schema2.min(config.min, ({ path, min }) => (error_messages?.date?.min ?? "").replaceAll("{path}", path).replaceAll("{min}", new Date(min).toISOString()));
|
|
78
|
+
if (config.max) schema2 = schema2.max(config.max, ({ path, max }) => (error_messages?.date?.max ?? "").replaceAll("{path}", path).replaceAll("{max}", new Date(max).toISOString()));
|
|
83
79
|
return schema2;
|
|
84
80
|
} else if (config.type === "object") {
|
|
85
|
-
schema2 = Yup.object().typeError(({ path }) => (error_messages?.object?.type ?? "").
|
|
81
|
+
schema2 = Yup.object().typeError(({ path }) => (error_messages?.object?.type ?? "").replaceAll("{path}", path));
|
|
86
82
|
schema2 = base(schema2, key, config);
|
|
87
83
|
const nested_properties = {};
|
|
88
84
|
for (const [nested_key, nested_config] of Object.entries(config.properties)) nested_properties[nested_key] = build(nested_key, nested_config);
|
|
89
85
|
schema2 = schema2.shape(nested_properties);
|
|
90
86
|
return schema2;
|
|
91
87
|
} else if (config.type === "array") {
|
|
92
|
-
schema2 = Yup.array().typeError(({ path }) => (error_messages?.array?.type ?? "").
|
|
88
|
+
schema2 = Yup.array().typeError(({ path }) => (error_messages?.array?.type ?? "").replaceAll("{path}", path));
|
|
93
89
|
schema2 = base(schema2, key, config);
|
|
94
90
|
if (config.min)
|
|
95
91
|
schema2 = schema2.min(
|
|
96
92
|
config.min,
|
|
97
|
-
({ path, min }) => (error_messages?.array?.min ?? "").
|
|
93
|
+
({ path, min }) => (error_messages?.array?.min ?? "").replaceAll("{path}", path).replaceAll("{min}", min.toString()).replaceAll("{plural_suffix}", min > 1 ? "s" : "")
|
|
98
94
|
);
|
|
99
95
|
if (config.max)
|
|
100
96
|
schema2 = schema2.max(
|
|
101
97
|
config.max,
|
|
102
|
-
({ path, max }) => (error_messages?.array?.max ?? "").
|
|
98
|
+
({ path, max }) => (error_messages?.array?.max ?? "").replaceAll("{path}", path).replaceAll("{max}", max.toString()).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
|
|
103
99
|
);
|
|
104
100
|
schema2 = schema2.of(build(key, config.items));
|
|
105
101
|
return schema2;
|
|
@@ -201,6 +197,7 @@ var YuppiOptionsDefault = {
|
|
|
201
197
|
|
|
202
198
|
// src/Yuppi.class.ts
|
|
203
199
|
var Yuppi = class {
|
|
200
|
+
options;
|
|
204
201
|
constructor(options = YuppiOptionsDefault) {
|
|
205
202
|
this.options = _.merge({}, YuppiOptionsDefault, options);
|
|
206
203
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yuppi",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.10",
|
|
4
4
|
"description": "Schemas that can be converted to Yup and JSON Schema.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/keift/yuppi",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"yup": "^1.7.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"neatlint": "^1.1.
|
|
24
|
+
"neatlint": "^1.1.16",
|
|
25
25
|
"prettier": "^3.6.2",
|
|
26
26
|
"tsup": "^8.5.0"
|
|
27
27
|
},
|