yuppi 1.2.9 → 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 CHANGED
@@ -203,9 +203,9 @@ Validate the properties with your Yuppi schema.
203
203
  > }
204
204
  > */
205
205
  > } catch (error) {
206
- > const message = (error as ValidationError).message;
206
+ > const errors = (error as ValidationError).errors;
207
207
  >
208
- > console.log(message); // "Field email must match the required pattern ^[a-zA-Z0-9._-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$"
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.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 ?? "").split("{path}").join(path),
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 ?? "").split("{path}").join(path));
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 ?? "").split("{path}").join(path));
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 ?? "").split("{path}").join(path)
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 ?? "").split("{path}").join(path).split("{min}").join(min.toString()).split("{plural_suffix}").join(min > 1 ? "s" : "")
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 ?? "").split("{path}").join(path).split("{max}").join(max.toString()).split("{plural_suffix}").join(max > 1 ? "s" : "")
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 ?? "").split("{path}").join(path));
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 ?? "").split("{path}").join(path));
99
- if (config.min) schema2 = schema2.min(config.min, ({ path, min }) => (error_messages?.number?.min ?? "").split("{path}").join(path).split("{min}").join(min.toString()));
100
- if (config.max) schema2 = schema2.max(config.max, ({ path, max }) => (error_messages?.number?.max ?? "").split("{path}").join(path).split("{max}").join(max.toString()));
101
- if (config.integer) schema2 = schema2.integer(({ path }) => (error_messages?.number?.integer ?? "").split("{path}").join(path));
102
- if (config.positive) schema2 = schema2.positive(({ path }) => (error_messages?.number?.positive ?? "").split("{path}").join(path));
103
- if (config.negative) schema2 = schema2.negative(({ path }) => (error_messages?.number?.negative ?? "").split("{path}").join(path));
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 ?? "").split("{path}").join(path));
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 ?? "").split("{path}").join(path));
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 ?? "").split("{path}").join(path).split("{min}").join(new Date(min).toISOString()));
113
- if (config.max) schema2 = schema2.max(config.max, ({ path, max }) => (error_messages?.date?.max ?? "").split("{path}").join(path).split("{max}").join(new Date(max).toISOString()));
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 ?? "").split("{path}").join(path));
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 ?? "").split("{path}").join(path));
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 ?? "").split("{path}").join(path).split("{min}").join(min.toString()).split("{plural_suffix}").join(min > 1 ? "s" : "")
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 ?? "").split("{path}").join(path).split("{max}").join(max.toString()).split("{plural_suffix}").join(max > 1 ? "s" : "")
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 ?? "").split("{path}").join(path),
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 ?? "").split("{path}").join(path));
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 ?? "").split("{path}").join(path));
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 ?? "").split("{path}").join(path)
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 ?? "").split("{path}").join(path).split("{min}").join(min.toString()).split("{plural_suffix}").join(min > 1 ? "s" : "")
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 ?? "").split("{path}").join(path).split("{max}").join(max.toString()).split("{plural_suffix}").join(max > 1 ? "s" : "")
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 ?? "").split("{path}").join(path));
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 ?? "").split("{path}").join(path));
68
- if (config.min) schema2 = schema2.min(config.min, ({ path, min }) => (error_messages?.number?.min ?? "").split("{path}").join(path).split("{min}").join(min.toString()));
69
- if (config.max) schema2 = schema2.max(config.max, ({ path, max }) => (error_messages?.number?.max ?? "").split("{path}").join(path).split("{max}").join(max.toString()));
70
- if (config.integer) schema2 = schema2.integer(({ path }) => (error_messages?.number?.integer ?? "").split("{path}").join(path));
71
- if (config.positive) schema2 = schema2.positive(({ path }) => (error_messages?.number?.positive ?? "").split("{path}").join(path));
72
- if (config.negative) schema2 = schema2.negative(({ path }) => (error_messages?.number?.negative ?? "").split("{path}").join(path));
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 ?? "").split("{path}").join(path));
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 ?? "").split("{path}").join(path));
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 ?? "").split("{path}").join(path).split("{min}").join(new Date(min).toISOString()));
82
- if (config.max) schema2 = schema2.max(config.max, ({ path, max }) => (error_messages?.date?.max ?? "").split("{path}").join(path).split("{max}").join(new Date(max).toISOString()));
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 ?? "").split("{path}").join(path));
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 ?? "").split("{path}").join(path));
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 ?? "").split("{path}").join(path).split("{min}").join(min.toString()).split("{plural_suffix}").join(min > 1 ? "s" : "")
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 ?? "").split("{path}").join(path).split("{max}").join(max.toString()).split("{plural_suffix}").join(max > 1 ? "s" : "")
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.9",
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.12",
24
+ "neatlint": "^1.1.16",
25
25
  "prettier": "^3.6.2",
26
26
  "tsup": "^8.5.0"
27
27
  },