yuppi 1.2.9 → 1.2.11

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
@@ -9,7 +9,6 @@
9
9
  [Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
10
10
  [Void]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Undefined
11
11
  [YuppiOptionsDefault]: ./src/defaults/YuppiOptions.default.ts
12
- [Any]: ./src/patterns/Any.pattern.ts
13
12
  [Domain]: ./src/patterns/Domain.pattern.ts
14
13
  [Email]: ./src/patterns/Email.pattern.ts
15
14
  [HTTP]: ./src/patterns/HTTP.pattern.ts
@@ -203,9 +202,9 @@ Validate the properties with your Yuppi schema.
203
202
  > }
204
203
  > */
205
204
  > } catch (error) {
206
- > const message = (error as ValidationError).message;
205
+ > const errors = (error as ValidationError).errors;
207
206
  >
208
- > console.log(message); // "Field email must match the required pattern ^[a-zA-Z0-9._-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$"
207
+ > console.log(errors[0]); // "Field email must match the required pattern ^[a-zA-Z0-9._-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$"
209
208
  > }
210
209
  > ```
211
210
 
@@ -305,7 +304,6 @@ Convert your Yuppi schema into [JSON Schema](https://json-schema.org).
305
304
  > type: "string",
306
305
  > minLength: 1,
307
306
  > maxLength: 32,
308
- > pattern: "[\\s\\S]*"
309
307
  > },
310
308
  > username: {
311
309
  > type: "string",
@@ -331,7 +329,6 @@ Convert your Yuppi schema into [JSON Schema](https://json-schema.org).
331
329
 
332
330
  | Pattern | Description | Examples |
333
331
  | ------------- | ------------------------------ | -------------------------------------------------------------------------------- |
334
- | [Any] | Everything will pass. | `"Yuppi!"` ✅<br/>`" "` ✅ |
335
332
  | [Domain] | Domains. | `"google.com"` ✅<br/>`"www.google.com"` ✅<br/>`"https://google.com"` ❌ |
336
333
  | [Email] | Emails. | `"fir4tozden@gmail.com"` ✅<br/>`"fir4tozden+2@gmail.com"` ❌ |
337
334
  | [HTTP] | HTTP only links. | `"https://google.com"` ✅<br/>`"http://google.com"` ✅<br/>`"google.com"` ❌ |
package/dist/main.d.mts CHANGED
@@ -122,8 +122,6 @@ declare class Yuppi {
122
122
  convertToJSONSchema(schema: Schema): JSONSchema;
123
123
  }
124
124
 
125
- declare const Any = "[\\s\\S]*";
126
-
127
125
  declare const Domain = "^([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
128
126
 
129
127
  declare const Email = "^[a-zA-Z0-9._-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
@@ -136,7 +134,6 @@ declare const URI = "^([a-zA-Z][a-zA-Z0-9+\\-.]*:\\/\\/)([a-zA-Z0-9._%+-]+(:[a-z
136
134
 
137
135
  declare const Username = "^(?=.*[a-zA-Z])[a-zA-Z0-9][a-zA-Z0-9_]*$";
138
136
 
139
- declare const Patterns_barrel_Any: typeof Any;
140
137
  declare const Patterns_barrel_Domain: typeof Domain;
141
138
  declare const Patterns_barrel_Email: typeof Email;
142
139
  declare const Patterns_barrel_HTTP: typeof HTTP;
@@ -144,7 +141,7 @@ declare const Patterns_barrel_PhoneNumber: typeof PhoneNumber;
144
141
  declare const Patterns_barrel_URI: typeof URI;
145
142
  declare const Patterns_barrel_Username: typeof Username;
146
143
  declare namespace Patterns_barrel {
147
- export { Patterns_barrel_Any as Any, Patterns_barrel_Domain as Domain, Patterns_barrel_Email as Email, Patterns_barrel_HTTP as HTTP, Patterns_barrel_PhoneNumber as PhoneNumber, Patterns_barrel_URI as URI, Patterns_barrel_Username as Username };
144
+ export { Patterns_barrel_Domain as Domain, Patterns_barrel_Email as Email, Patterns_barrel_HTTP as HTTP, Patterns_barrel_PhoneNumber as PhoneNumber, Patterns_barrel_URI as URI, Patterns_barrel_Username as Username };
148
145
  }
149
146
 
150
147
  type ValidationError = ValidationError$1;
package/dist/main.d.ts CHANGED
@@ -122,8 +122,6 @@ declare class Yuppi {
122
122
  convertToJSONSchema(schema: Schema): JSONSchema;
123
123
  }
124
124
 
125
- declare const Any = "[\\s\\S]*";
126
-
127
125
  declare const Domain = "^([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
128
126
 
129
127
  declare const Email = "^[a-zA-Z0-9._-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
@@ -136,7 +134,6 @@ declare const URI = "^([a-zA-Z][a-zA-Z0-9+\\-.]*:\\/\\/)([a-zA-Z0-9._%+-]+(:[a-z
136
134
 
137
135
  declare const Username = "^(?=.*[a-zA-Z])[a-zA-Z0-9][a-zA-Z0-9_]*$";
138
136
 
139
- declare const Patterns_barrel_Any: typeof Any;
140
137
  declare const Patterns_barrel_Domain: typeof Domain;
141
138
  declare const Patterns_barrel_Email: typeof Email;
142
139
  declare const Patterns_barrel_HTTP: typeof HTTP;
@@ -144,7 +141,7 @@ declare const Patterns_barrel_PhoneNumber: typeof PhoneNumber;
144
141
  declare const Patterns_barrel_URI: typeof URI;
145
142
  declare const Patterns_barrel_Username: typeof Username;
146
143
  declare namespace Patterns_barrel {
147
- export { Patterns_barrel_Any as Any, Patterns_barrel_Domain as Domain, Patterns_barrel_Email as Email, Patterns_barrel_HTTP as HTTP, Patterns_barrel_PhoneNumber as PhoneNumber, Patterns_barrel_URI as URI, Patterns_barrel_Username as Username };
144
+ export { Patterns_barrel_Domain as Domain, Patterns_barrel_Email as Email, Patterns_barrel_HTTP as HTTP, Patterns_barrel_PhoneNumber as PhoneNumber, Patterns_barrel_URI as URI, Patterns_barrel_Username as Username };
148
145
  }
149
146
 
150
147
  type ValidationError = ValidationError$1;
package/dist/main.js CHANGED
@@ -40,18 +40,13 @@ var import_lodash = __toESM(require("lodash"));
40
40
 
41
41
  // src/utils/ConvertToYup.util.ts
42
42
  var Yup = __toESM(require("yup"));
43
-
44
- // src/patterns/Any.pattern.ts
45
- var Any = "[\\s\\S]*";
46
-
47
- // src/utils/ConvertToYup.util.ts
48
43
  var convertToYup = (schema, error_messages) => {
49
44
  const base = (schema2, key, config) => {
50
45
  schema2 = schema2.nullable();
51
46
  if (config.required)
52
47
  schema2 = schema2.test(
53
48
  "required",
54
- ({ path }) => (error_messages?.base?.required ?? "").split("{path}").join(path),
49
+ ({ path }) => (error_messages?.base?.required ?? "").replaceAll("{path}", path),
55
50
  (property) => {
56
51
  if (property === void 0) return false;
57
52
  if (typeof property === "string" && property.trim() === "") return false;
@@ -59,78 +54,74 @@ var convertToYup = (schema, error_messages) => {
59
54
  return true;
60
55
  }
61
56
  );
62
- if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path }) => (error_messages?.base?.nullable ?? "").split("{path}").join(path));
57
+ if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path }) => (error_messages?.base?.nullable ?? "").replaceAll("{path}", path));
63
58
  if (config.default) schema2 = schema2.default(config.default);
64
59
  return schema2;
65
60
  };
66
61
  const build = (key, config) => {
67
62
  let schema2;
68
63
  if (config.type === "string") {
69
- schema2 = Yup.string().typeError(({ path }) => (error_messages?.string?.type ?? "").split("{path}").join(path));
64
+ schema2 = Yup.string().typeError(({ path }) => (error_messages?.string?.type ?? "").replaceAll("{path}", path));
70
65
  schema2 = base(schema2, key, config);
71
66
  schema2 = schema2.transform((property) => typeof property === "string" ? property.trim() : property);
72
67
  if (config.enum)
73
68
  schema2 = schema2.oneOf(
74
69
  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)
70
+ ({ path }) => (error_messages?.string?.enum ?? "").replaceAll("{path}", path)
81
71
  );
72
+ if (config.pattern) schema2 = schema2.matches(new RegExp(config.pattern), ({ path }) => (error_messages?.string?.pattern ?? "").replaceAll("{path}", path).replaceAll("{pattern}", config.pattern ? new RegExp(config.pattern).source : ""));
82
73
  if (config.min)
83
74
  schema2 = schema2.min(
84
75
  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" : "")
76
+ ({ path, min }) => (error_messages?.string?.min ?? "").replaceAll("{path}", path).replaceAll("{min}", min.toString()).replaceAll("{plural_suffix}", min > 1 ? "s" : "")
86
77
  );
87
78
  if (config.max)
88
79
  schema2 = schema2.max(
89
80
  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" : "")
81
+ ({ path, max }) => (error_messages?.string?.max ?? "").replaceAll("{path}", path).replaceAll("{max}", max.toString()).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
91
82
  );
92
83
  if (config.lowercase) schema2 = schema2.transform((property) => typeof property === "string" ? property.toLowerCase() : property);
93
84
  if (config.uppercase) schema2 = schema2.transform((property) => typeof property === "string" ? property.toUpperCase() : property);
94
85
  return schema2;
95
86
  } else if (config.type === "number") {
96
- schema2 = Yup.number().typeError(({ path }) => (error_messages?.number?.type ?? "").split("{path}").join(path));
87
+ schema2 = Yup.number().typeError(({ path }) => (error_messages?.number?.type ?? "").replaceAll("{path}", path));
97
88
  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));
89
+ if (config.enum) schema2 = schema2.oneOf(config.enum, ({ path }) => (error_messages?.number?.enum ?? "").replaceAll("{path}", path));
90
+ if (config.min) schema2 = schema2.min(config.min, ({ path, min }) => (error_messages?.number?.min ?? "").replaceAll("{path}", path).replaceAll("{min}", min.toString()));
91
+ if (config.max) schema2 = schema2.max(config.max, ({ path, max }) => (error_messages?.number?.max ?? "").replaceAll("{path}", path).replaceAll("{max}", max.toString()));
92
+ if (config.integer) schema2 = schema2.integer(({ path }) => (error_messages?.number?.integer ?? "").replaceAll("{path}", path));
93
+ if (config.positive) schema2 = schema2.positive(({ path }) => (error_messages?.number?.positive ?? "").replaceAll("{path}", path));
94
+ if (config.negative) schema2 = schema2.negative(({ path }) => (error_messages?.number?.negative ?? "").replaceAll("{path}", path));
104
95
  return schema2;
105
96
  } else if (config.type === "boolean") {
106
- schema2 = Yup.boolean().typeError(({ path }) => (error_messages?.boolean?.type ?? "").split("{path}").join(path));
97
+ schema2 = Yup.boolean().typeError(({ path }) => (error_messages?.boolean?.type ?? "").replaceAll("{path}", path));
107
98
  schema2 = base(schema2, key, config);
108
99
  return schema2;
109
100
  } else if (config.type === "date") {
110
- schema2 = Yup.date().typeError(({ path }) => (error_messages?.date?.type ?? "").split("{path}").join(path));
101
+ schema2 = Yup.date().typeError(({ path }) => (error_messages?.date?.type ?? "").replaceAll("{path}", path));
111
102
  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()));
103
+ if (config.min) schema2 = schema2.min(config.min, ({ path, min }) => (error_messages?.date?.min ?? "").replaceAll("{path}", path).replaceAll("{min}", new Date(min).toISOString()));
104
+ if (config.max) schema2 = schema2.max(config.max, ({ path, max }) => (error_messages?.date?.max ?? "").replaceAll("{path}", path).replaceAll("{max}", new Date(max).toISOString()));
114
105
  return schema2;
115
106
  } else if (config.type === "object") {
116
- schema2 = Yup.object().typeError(({ path }) => (error_messages?.object?.type ?? "").split("{path}").join(path));
107
+ schema2 = Yup.object().typeError(({ path }) => (error_messages?.object?.type ?? "").replaceAll("{path}", path));
117
108
  schema2 = base(schema2, key, config);
118
109
  const nested_properties = {};
119
110
  for (const [nested_key, nested_config] of Object.entries(config.properties)) nested_properties[nested_key] = build(nested_key, nested_config);
120
111
  schema2 = schema2.shape(nested_properties);
121
112
  return schema2;
122
113
  } else if (config.type === "array") {
123
- schema2 = Yup.array().typeError(({ path }) => (error_messages?.array?.type ?? "").split("{path}").join(path));
114
+ schema2 = Yup.array().typeError(({ path }) => (error_messages?.array?.type ?? "").replaceAll("{path}", path));
124
115
  schema2 = base(schema2, key, config);
125
116
  if (config.min)
126
117
  schema2 = schema2.min(
127
118
  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" : "")
119
+ ({ path, min }) => (error_messages?.array?.min ?? "").replaceAll("{path}", path).replaceAll("{min}", min.toString()).replaceAll("{plural_suffix}", min > 1 ? "s" : "")
129
120
  );
130
121
  if (config.max)
131
122
  schema2 = schema2.max(
132
123
  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" : "")
124
+ ({ path, max }) => (error_messages?.array?.max ?? "").replaceAll("{path}", path).replaceAll("{max}", max.toString()).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
134
125
  );
135
126
  schema2 = schema2.of(build(key, config.items));
136
127
  return schema2;
@@ -152,7 +143,7 @@ var convertToJSONSchema = (schema) => {
152
143
  const build = (key, config) => {
153
144
  let schema2;
154
145
  if (config.type === "string") {
155
- schema2 = import_typebox.Type.String({ enum: config.enum, minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
146
+ schema2 = import_typebox.Type.String({ enum: config.enum, minLength: config.min, maxLength: config.max, pattern: config.pattern ? new RegExp(config.pattern).source : void 0, default: config.default });
156
147
  schema2 = base(schema2, key, config);
157
148
  return schema2;
158
149
  } else if (config.type === "number") {
@@ -232,6 +223,7 @@ var YuppiOptionsDefault = {
232
223
 
233
224
  // src/Yuppi.class.ts
234
225
  var Yuppi = class {
226
+ options;
235
227
  constructor(options = YuppiOptionsDefault) {
236
228
  this.options = import_lodash.default.merge({}, YuppiOptionsDefault, options);
237
229
  }
@@ -250,7 +242,6 @@ var Yuppi = class {
250
242
  // src/barrels/Patterns.barrel.ts
251
243
  var Patterns_barrel_exports = {};
252
244
  __export(Patterns_barrel_exports, {
253
- Any: () => Any,
254
245
  Domain: () => Domain,
255
246
  Email: () => Email,
256
247
  HTTP: () => HTTP,
package/dist/main.mjs CHANGED
@@ -9,18 +9,13 @@ import _ from "lodash";
9
9
 
10
10
  // src/utils/ConvertToYup.util.ts
11
11
  import * as Yup from "yup";
12
-
13
- // src/patterns/Any.pattern.ts
14
- var Any = "[\\s\\S]*";
15
-
16
- // src/utils/ConvertToYup.util.ts
17
12
  var convertToYup = (schema, error_messages) => {
18
13
  const base = (schema2, key, config) => {
19
14
  schema2 = schema2.nullable();
20
15
  if (config.required)
21
16
  schema2 = schema2.test(
22
17
  "required",
23
- ({ path }) => (error_messages?.base?.required ?? "").split("{path}").join(path),
18
+ ({ path }) => (error_messages?.base?.required ?? "").replaceAll("{path}", path),
24
19
  (property) => {
25
20
  if (property === void 0) return false;
26
21
  if (typeof property === "string" && property.trim() === "") return false;
@@ -28,78 +23,74 @@ var convertToYup = (schema, error_messages) => {
28
23
  return true;
29
24
  }
30
25
  );
31
- if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path }) => (error_messages?.base?.nullable ?? "").split("{path}").join(path));
26
+ if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path }) => (error_messages?.base?.nullable ?? "").replaceAll("{path}", path));
32
27
  if (config.default) schema2 = schema2.default(config.default);
33
28
  return schema2;
34
29
  };
35
30
  const build = (key, config) => {
36
31
  let schema2;
37
32
  if (config.type === "string") {
38
- schema2 = Yup.string().typeError(({ path }) => (error_messages?.string?.type ?? "").split("{path}").join(path));
33
+ schema2 = Yup.string().typeError(({ path }) => (error_messages?.string?.type ?? "").replaceAll("{path}", path));
39
34
  schema2 = base(schema2, key, config);
40
35
  schema2 = schema2.transform((property) => typeof property === "string" ? property.trim() : property);
41
36
  if (config.enum)
42
37
  schema2 = schema2.oneOf(
43
38
  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)
39
+ ({ path }) => (error_messages?.string?.enum ?? "").replaceAll("{path}", path)
50
40
  );
41
+ if (config.pattern) schema2 = schema2.matches(new RegExp(config.pattern), ({ path }) => (error_messages?.string?.pattern ?? "").replaceAll("{path}", path).replaceAll("{pattern}", config.pattern ? new RegExp(config.pattern).source : ""));
51
42
  if (config.min)
52
43
  schema2 = schema2.min(
53
44
  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" : "")
45
+ ({ path, min }) => (error_messages?.string?.min ?? "").replaceAll("{path}", path).replaceAll("{min}", min.toString()).replaceAll("{plural_suffix}", min > 1 ? "s" : "")
55
46
  );
56
47
  if (config.max)
57
48
  schema2 = schema2.max(
58
49
  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" : "")
50
+ ({ path, max }) => (error_messages?.string?.max ?? "").replaceAll("{path}", path).replaceAll("{max}", max.toString()).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
60
51
  );
61
52
  if (config.lowercase) schema2 = schema2.transform((property) => typeof property === "string" ? property.toLowerCase() : property);
62
53
  if (config.uppercase) schema2 = schema2.transform((property) => typeof property === "string" ? property.toUpperCase() : property);
63
54
  return schema2;
64
55
  } else if (config.type === "number") {
65
- schema2 = Yup.number().typeError(({ path }) => (error_messages?.number?.type ?? "").split("{path}").join(path));
56
+ schema2 = Yup.number().typeError(({ path }) => (error_messages?.number?.type ?? "").replaceAll("{path}", path));
66
57
  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));
58
+ if (config.enum) schema2 = schema2.oneOf(config.enum, ({ path }) => (error_messages?.number?.enum ?? "").replaceAll("{path}", path));
59
+ if (config.min) schema2 = schema2.min(config.min, ({ path, min }) => (error_messages?.number?.min ?? "").replaceAll("{path}", path).replaceAll("{min}", min.toString()));
60
+ if (config.max) schema2 = schema2.max(config.max, ({ path, max }) => (error_messages?.number?.max ?? "").replaceAll("{path}", path).replaceAll("{max}", max.toString()));
61
+ if (config.integer) schema2 = schema2.integer(({ path }) => (error_messages?.number?.integer ?? "").replaceAll("{path}", path));
62
+ if (config.positive) schema2 = schema2.positive(({ path }) => (error_messages?.number?.positive ?? "").replaceAll("{path}", path));
63
+ if (config.negative) schema2 = schema2.negative(({ path }) => (error_messages?.number?.negative ?? "").replaceAll("{path}", path));
73
64
  return schema2;
74
65
  } else if (config.type === "boolean") {
75
- schema2 = Yup.boolean().typeError(({ path }) => (error_messages?.boolean?.type ?? "").split("{path}").join(path));
66
+ schema2 = Yup.boolean().typeError(({ path }) => (error_messages?.boolean?.type ?? "").replaceAll("{path}", path));
76
67
  schema2 = base(schema2, key, config);
77
68
  return schema2;
78
69
  } else if (config.type === "date") {
79
- schema2 = Yup.date().typeError(({ path }) => (error_messages?.date?.type ?? "").split("{path}").join(path));
70
+ schema2 = Yup.date().typeError(({ path }) => (error_messages?.date?.type ?? "").replaceAll("{path}", path));
80
71
  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()));
72
+ if (config.min) schema2 = schema2.min(config.min, ({ path, min }) => (error_messages?.date?.min ?? "").replaceAll("{path}", path).replaceAll("{min}", new Date(min).toISOString()));
73
+ if (config.max) schema2 = schema2.max(config.max, ({ path, max }) => (error_messages?.date?.max ?? "").replaceAll("{path}", path).replaceAll("{max}", new Date(max).toISOString()));
83
74
  return schema2;
84
75
  } else if (config.type === "object") {
85
- schema2 = Yup.object().typeError(({ path }) => (error_messages?.object?.type ?? "").split("{path}").join(path));
76
+ schema2 = Yup.object().typeError(({ path }) => (error_messages?.object?.type ?? "").replaceAll("{path}", path));
86
77
  schema2 = base(schema2, key, config);
87
78
  const nested_properties = {};
88
79
  for (const [nested_key, nested_config] of Object.entries(config.properties)) nested_properties[nested_key] = build(nested_key, nested_config);
89
80
  schema2 = schema2.shape(nested_properties);
90
81
  return schema2;
91
82
  } else if (config.type === "array") {
92
- schema2 = Yup.array().typeError(({ path }) => (error_messages?.array?.type ?? "").split("{path}").join(path));
83
+ schema2 = Yup.array().typeError(({ path }) => (error_messages?.array?.type ?? "").replaceAll("{path}", path));
93
84
  schema2 = base(schema2, key, config);
94
85
  if (config.min)
95
86
  schema2 = schema2.min(
96
87
  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" : "")
88
+ ({ path, min }) => (error_messages?.array?.min ?? "").replaceAll("{path}", path).replaceAll("{min}", min.toString()).replaceAll("{plural_suffix}", min > 1 ? "s" : "")
98
89
  );
99
90
  if (config.max)
100
91
  schema2 = schema2.max(
101
92
  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" : "")
93
+ ({ path, max }) => (error_messages?.array?.max ?? "").replaceAll("{path}", path).replaceAll("{max}", max.toString()).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
103
94
  );
104
95
  schema2 = schema2.of(build(key, config.items));
105
96
  return schema2;
@@ -121,7 +112,7 @@ var convertToJSONSchema = (schema) => {
121
112
  const build = (key, config) => {
122
113
  let schema2;
123
114
  if (config.type === "string") {
124
- schema2 = Type.String({ enum: config.enum, minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
115
+ schema2 = Type.String({ enum: config.enum, minLength: config.min, maxLength: config.max, pattern: config.pattern ? new RegExp(config.pattern).source : void 0, default: config.default });
125
116
  schema2 = base(schema2, key, config);
126
117
  return schema2;
127
118
  } else if (config.type === "number") {
@@ -201,6 +192,7 @@ var YuppiOptionsDefault = {
201
192
 
202
193
  // src/Yuppi.class.ts
203
194
  var Yuppi = class {
195
+ options;
204
196
  constructor(options = YuppiOptionsDefault) {
205
197
  this.options = _.merge({}, YuppiOptionsDefault, options);
206
198
  }
@@ -219,7 +211,6 @@ var Yuppi = class {
219
211
  // src/barrels/Patterns.barrel.ts
220
212
  var Patterns_barrel_exports = {};
221
213
  __export(Patterns_barrel_exports, {
222
- Any: () => Any,
223
214
  Domain: () => Domain,
224
215
  Email: () => Email,
225
216
  HTTP: () => HTTP,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuppi",
3
- "version": "1.2.9",
3
+ "version": "1.2.11",
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
  },