yuppi 1.1.2 → 1.2.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.
Files changed (49) hide show
  1. package/README.md +19 -10
  2. package/dist/Patterns.barrel-D-k3IHDq.d.mts +20 -0
  3. package/dist/Patterns.barrel-JdN3lL2Q.d.ts +20 -0
  4. package/dist/Yuppi.class.js +10 -5
  5. package/dist/Yuppi.class.mjs +10 -5
  6. package/dist/barrels/Patterns.barrel.d.mts +4 -2
  7. package/dist/barrels/Patterns.barrel.d.ts +4 -2
  8. package/dist/barrels/Patterns.barrel.js +21 -6
  9. package/dist/barrels/Patterns.barrel.mjs +17 -5
  10. package/dist/main.d.mts +5 -2
  11. package/dist/main.d.ts +5 -2
  12. package/dist/main.js +24 -10
  13. package/dist/main.mjs +24 -10
  14. package/dist/patterns/Any.pattern.d.mts +3 -0
  15. package/dist/patterns/Any.pattern.d.ts +3 -0
  16. package/dist/patterns/{URL.pattern.js → Any.pattern.js} +7 -7
  17. package/dist/patterns/Any.pattern.mjs +5 -0
  18. package/dist/patterns/Domain.pattern.d.mts +3 -0
  19. package/dist/patterns/Domain.pattern.d.ts +3 -0
  20. package/dist/patterns/Domain.pattern.js +30 -0
  21. package/dist/patterns/Domain.pattern.mjs +5 -0
  22. package/dist/patterns/Email.pattern.d.mts +1 -3
  23. package/dist/patterns/Email.pattern.d.ts +1 -3
  24. package/dist/patterns/Email.pattern.js +1 -1
  25. package/dist/patterns/Email.pattern.mjs +1 -1
  26. package/dist/patterns/HTTP.pattern.d.mts +3 -0
  27. package/dist/patterns/HTTP.pattern.d.ts +3 -0
  28. package/dist/patterns/HTTP.pattern.js +30 -0
  29. package/dist/patterns/HTTP.pattern.mjs +5 -0
  30. package/dist/patterns/PhoneNumber.pattern.d.mts +1 -3
  31. package/dist/patterns/PhoneNumber.pattern.d.ts +1 -3
  32. package/dist/patterns/PhoneNumber.pattern.js +1 -1
  33. package/dist/patterns/PhoneNumber.pattern.mjs +1 -1
  34. package/dist/patterns/URI.pattern.d.mts +3 -0
  35. package/dist/patterns/URI.pattern.d.ts +3 -0
  36. package/dist/patterns/URI.pattern.js +30 -0
  37. package/dist/patterns/URI.pattern.mjs +5 -0
  38. package/dist/patterns/Username.pattern.d.mts +1 -3
  39. package/dist/patterns/Username.pattern.d.ts +1 -3
  40. package/dist/utils/ConvertToJSONSchema.util.js +7 -2
  41. package/dist/utils/ConvertToJSONSchema.util.mjs +7 -2
  42. package/dist/utils/ConvertToYup.util.js +8 -3
  43. package/dist/utils/ConvertToYup.util.mjs +8 -3
  44. package/package.json +5 -5
  45. package/dist/Patterns.barrel-KU6hZBXs.d.mts +0 -14
  46. package/dist/Patterns.barrel-UKU2yPZ6.d.ts +0 -14
  47. package/dist/patterns/URL.pattern.d.mts +0 -5
  48. package/dist/patterns/URL.pattern.d.ts +0 -5
  49. package/dist/patterns/URL.pattern.mjs +0 -5
package/README.md CHANGED
@@ -9,9 +9,12 @@
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
+ [Domain]: ./src/patterns/Domain.pattern.ts
12
14
  [Email]: ./src/patterns/Email.pattern.ts
15
+ [HTTP]: ./src/patterns/HTTP.pattern.ts
13
16
  [PhoneNumber]: ./src/patterns/PhoneNumber.pattern.ts
14
- [URL]: ./src/patterns/URL.pattern.ts
17
+ [URI]: ./src/patterns/URI.pattern.ts
15
18
  [Username]: ./src/patterns/Username.pattern.ts
16
19
  [AnyObject]: https://github.com/jquense/yup/blob/master/src/util/objectTypes.ts#L7
17
20
  [JSONSchema]: https://github.com/sinclairzx81/typebox/blob/master/src/type/object/object.ts#L78
@@ -101,9 +104,12 @@ Yuppi
101
104
  │ └── convertToJSONSchema(schema)
102
105
 
103
106
  ├── Patterns
107
+ │ ├── Any
108
+ │ ├── Domain
104
109
  │ ├── Email
110
+ │ ├── HTTP
105
111
  │ ├── PhoneNumber
106
- │ ├── URL
112
+ │ ├── URI
107
113
  │ └── Username
108
114
 
109
115
  └── type Types
@@ -207,7 +213,7 @@ Validate the properties with your Yuppi schema.
207
213
  > }
208
214
  > */
209
215
  > } catch((error: YuppiTypes.ValidationError)) {
210
- > console.log(error.message); // "Field email must match the required pattern ^[a-zA-Z0-9._%-]+@([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$"
216
+ > console.log(error.message); // "Field email must match the required pattern ^[a-zA-Z0-9._-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$"
211
217
  > }
212
218
  > ```
213
219
 
@@ -317,7 +323,7 @@ Convert your Yuppi schema into [JSON Schema](https://json-schema.org).
317
323
  > },
318
324
  > email: {
319
325
  > type: "string",
320
- > pattern: "^[a-zA-Z0-9._%-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$",
326
+ > pattern: "^[a-zA-Z0-9._-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$",
321
327
  > }
322
328
  > },
323
329
  > required: [
@@ -331,12 +337,15 @@ Convert your Yuppi schema into [JSON Schema](https://json-schema.org).
331
337
 
332
338
  ### Patterns
333
339
 
334
- | Pattern |
335
- | ------------- |
336
- | [Email] |
337
- | [PhoneNumber] |
338
- | [URL] |
339
- | [Username] |
340
+ | Pattern | Description | Examples |
341
+ | ------------- | ------------------------------ | --------------------------------------------------------------------------------------------------- |
342
+ | [Any] | Everything will pass. | `"Yuppi!"` ✅<br/>`" "` ✅ |
343
+ | [Domain] | Domains. | `"google.com"` ✅<br/>`"www.google.com"` ✅<br/>`"https://google.com"` ❌ |
344
+ | [Email] | Emails. | `"fir4tozden@gmail.com"` ✅<br/>`"fir4tozden@mail.google.com"` ✅<br/>`"fir4tozden+2@gmail.com"` ❌ |
345
+ | [HTTP] | HTTP only links. | `"https://google.com"` ✅<br/>`"http://google.com"` ✅<br/>`"google.com"` ❌ |
346
+ | [PhoneNumber] | Country code and phone number. | `"0090-555555555"` ✅<br/>`"90-5555555555"` ❌ |
347
+ | [URI] | Protocol free links. | `"mongodb://cluster0.0000000.mongodb.net"` ✅<br/>`"https://google.com"` ✅<br/>`"google.com"` ❌ |
348
+ | [Username] | Usernames like Twitter. | `"fir4tozden"` ✅<br/>`"Fir4tozden"` ✅<br/>`"fir4t ozden"` ❌ |
340
349
 
341
350
  ### Types
342
351
 
@@ -0,0 +1,20 @@
1
+ import { Any } from './patterns/Any.pattern.mjs';
2
+ import { Domain } from './patterns/Domain.pattern.mjs';
3
+ import { Email } from './patterns/Email.pattern.mjs';
4
+ import { HTTP } from './patterns/HTTP.pattern.mjs';
5
+ import { PhoneNumber } from './patterns/PhoneNumber.pattern.mjs';
6
+ import { URI } from './patterns/URI.pattern.mjs';
7
+ import { Username } from './patterns/Username.pattern.mjs';
8
+
9
+ declare const Patterns_barrel_Any: typeof Any;
10
+ declare const Patterns_barrel_Domain: typeof Domain;
11
+ declare const Patterns_barrel_Email: typeof Email;
12
+ declare const Patterns_barrel_HTTP: typeof HTTP;
13
+ declare const Patterns_barrel_PhoneNumber: typeof PhoneNumber;
14
+ declare const Patterns_barrel_URI: typeof URI;
15
+ declare const Patterns_barrel_Username: typeof Username;
16
+ declare namespace Patterns_barrel {
17
+ 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 };
18
+ }
19
+
20
+ export { Patterns_barrel as P };
@@ -0,0 +1,20 @@
1
+ import { Any } from './patterns/Any.pattern.js';
2
+ import { Domain } from './patterns/Domain.pattern.js';
3
+ import { Email } from './patterns/Email.pattern.js';
4
+ import { HTTP } from './patterns/HTTP.pattern.js';
5
+ import { PhoneNumber } from './patterns/PhoneNumber.pattern.js';
6
+ import { URI } from './patterns/URI.pattern.js';
7
+ import { Username } from './patterns/Username.pattern.js';
8
+
9
+ declare const Patterns_barrel_Any: typeof Any;
10
+ declare const Patterns_barrel_Domain: typeof Domain;
11
+ declare const Patterns_barrel_Email: typeof Email;
12
+ declare const Patterns_barrel_HTTP: typeof HTTP;
13
+ declare const Patterns_barrel_PhoneNumber: typeof PhoneNumber;
14
+ declare const Patterns_barrel_URI: typeof URI;
15
+ declare const Patterns_barrel_Username: typeof Username;
16
+ declare namespace Patterns_barrel {
17
+ 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 };
18
+ }
19
+
20
+ export { Patterns_barrel as P };
@@ -37,6 +37,11 @@ var import_lodash = __toESM(require("lodash"));
37
37
 
38
38
  // src/utils/ConvertToYup.util.ts
39
39
  var Yup = __toESM(require("yup"));
40
+
41
+ // src/patterns/Any.pattern.ts
42
+ var Any = "[\\s\\S]*";
43
+
44
+ // src/utils/ConvertToYup.util.ts
40
45
  var convertToYup = (schema, error_messages) => {
41
46
  const base = (schema2, key, config) => {
42
47
  schema2 = schema2.nullable();
@@ -51,12 +56,12 @@ var convertToYup = (schema, error_messages) => {
51
56
  return true;
52
57
  }
53
58
  );
54
- if (!config.nullable) schema2 = schema2.nonNullable(({ path }) => (error_messages?.base?.nullable ?? "").split("{path}").join(path));
59
+ if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path }) => (error_messages?.base?.nullable ?? "").split("{path}").join(path));
55
60
  if (config.default !== void 0) schema2 = schema2.default(config.default);
56
61
  if (config.pattern !== void 0 && schema2.matches !== void 0)
57
62
  schema2 = schema2.matches(
58
- new RegExp(config.pattern ?? "[\\s\\S]*"),
59
- ({ path }) => (error_messages?.base?.pattern ?? "").split("{path}").join(path).split("{pattern}").join(new RegExp(config.pattern ?? "[\\s\\S]*").source)
63
+ new RegExp(config.pattern ?? Any),
64
+ ({ path }) => (error_messages?.base?.pattern ?? "").split("{path}").join(path).split("{pattern}").join(new RegExp(config.pattern ?? Any).source)
60
65
  );
61
66
  return schema2;
62
67
  };
@@ -132,7 +137,7 @@ var import_typebox = require("@sinclair/typebox");
132
137
  var convertToJSONSchema = (schema) => {
133
138
  const build = (key, config) => {
134
139
  if (config.type === "string") {
135
- let schema2 = import_typebox.Type.String({ minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? "[\\s\\S]*").source, default: config.default });
140
+ let schema2 = import_typebox.Type.String({ minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
136
141
  if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
137
142
  return config.required ? schema2 : import_typebox.Type.Optional(schema2);
138
143
  } else if (config.type === "number") {
@@ -144,7 +149,7 @@ var convertToJSONSchema = (schema) => {
144
149
  if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
145
150
  return config.required ? schema2 : import_typebox.Type.Optional(schema2);
146
151
  } else if (config.type === "date") {
147
- let schema2 = import_typebox.Type.String({ format: "date-time", minimum: config.min, maximum: config.max, pattern: new RegExp(config.pattern ?? "[\\s\\S]*").source, default: config.default });
152
+ let schema2 = import_typebox.Type.String({ format: "date-time", minimum: config.min, maximum: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
148
153
  if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
149
154
  return config.required ? schema2 : import_typebox.Type.Optional(schema2);
150
155
  } else if (config.type === "object") {
@@ -3,6 +3,11 @@ import _ from "lodash";
3
3
 
4
4
  // src/utils/ConvertToYup.util.ts
5
5
  import * as Yup from "yup";
6
+
7
+ // src/patterns/Any.pattern.ts
8
+ var Any = "[\\s\\S]*";
9
+
10
+ // src/utils/ConvertToYup.util.ts
6
11
  var convertToYup = (schema, error_messages) => {
7
12
  const base = (schema2, key, config) => {
8
13
  schema2 = schema2.nullable();
@@ -17,12 +22,12 @@ var convertToYup = (schema, error_messages) => {
17
22
  return true;
18
23
  }
19
24
  );
20
- if (!config.nullable) schema2 = schema2.nonNullable(({ path }) => (error_messages?.base?.nullable ?? "").split("{path}").join(path));
25
+ if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path }) => (error_messages?.base?.nullable ?? "").split("{path}").join(path));
21
26
  if (config.default !== void 0) schema2 = schema2.default(config.default);
22
27
  if (config.pattern !== void 0 && schema2.matches !== void 0)
23
28
  schema2 = schema2.matches(
24
- new RegExp(config.pattern ?? "[\\s\\S]*"),
25
- ({ path }) => (error_messages?.base?.pattern ?? "").split("{path}").join(path).split("{pattern}").join(new RegExp(config.pattern ?? "[\\s\\S]*").source)
29
+ new RegExp(config.pattern ?? Any),
30
+ ({ path }) => (error_messages?.base?.pattern ?? "").split("{path}").join(path).split("{pattern}").join(new RegExp(config.pattern ?? Any).source)
26
31
  );
27
32
  return schema2;
28
33
  };
@@ -98,7 +103,7 @@ import { Type } from "@sinclair/typebox";
98
103
  var convertToJSONSchema = (schema) => {
99
104
  const build = (key, config) => {
100
105
  if (config.type === "string") {
101
- let schema2 = Type.String({ minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? "[\\s\\S]*").source, default: config.default });
106
+ let schema2 = Type.String({ minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
102
107
  if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
103
108
  return config.required ? schema2 : Type.Optional(schema2);
104
109
  } else if (config.type === "number") {
@@ -110,7 +115,7 @@ var convertToJSONSchema = (schema) => {
110
115
  if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
111
116
  return config.required ? schema2 : Type.Optional(schema2);
112
117
  } else if (config.type === "date") {
113
- let schema2 = Type.String({ format: "date-time", minimum: config.min, maximum: config.max, pattern: new RegExp(config.pattern ?? "[\\s\\S]*").source, default: config.default });
118
+ let schema2 = Type.String({ format: "date-time", minimum: config.min, maximum: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
114
119
  if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
115
120
  return config.required ? schema2 : Type.Optional(schema2);
116
121
  } else if (config.type === "object") {
@@ -1,5 +1,7 @@
1
+ export { Any } from '../patterns/Any.pattern.mjs';
2
+ export { Domain } from '../patterns/Domain.pattern.mjs';
1
3
  export { Email } from '../patterns/Email.pattern.mjs';
4
+ export { HTTP } from '../patterns/HTTP.pattern.mjs';
2
5
  export { PhoneNumber } from '../patterns/PhoneNumber.pattern.mjs';
3
- export { URL } from '../patterns/URL.pattern.mjs';
6
+ export { URI } from '../patterns/URI.pattern.mjs';
4
7
  export { Username } from '../patterns/Username.pattern.mjs';
5
- import '../types/Schema.type.mjs';
@@ -1,5 +1,7 @@
1
+ export { Any } from '../patterns/Any.pattern.js';
2
+ export { Domain } from '../patterns/Domain.pattern.js';
1
3
  export { Email } from '../patterns/Email.pattern.js';
4
+ export { HTTP } from '../patterns/HTTP.pattern.js';
2
5
  export { PhoneNumber } from '../patterns/PhoneNumber.pattern.js';
3
- export { URL } from '../patterns/URL.pattern.js';
6
+ export { URI } from '../patterns/URI.pattern.js';
4
7
  export { Username } from '../patterns/Username.pattern.js';
5
- import '../types/Schema.type.js';
@@ -20,28 +20,43 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/barrels/Patterns.barrel.ts
21
21
  var Patterns_barrel_exports = {};
22
22
  __export(Patterns_barrel_exports, {
23
+ Any: () => Any,
24
+ Domain: () => Domain,
23
25
  Email: () => Email,
26
+ HTTP: () => HTTP,
24
27
  PhoneNumber: () => PhoneNumber,
25
- URL: () => URL,
28
+ URI: () => URI,
26
29
  Username: () => Username
27
30
  });
28
31
  module.exports = __toCommonJS(Patterns_barrel_exports);
29
32
 
33
+ // src/patterns/Any.pattern.ts
34
+ var Any = "[\\s\\S]*";
35
+
36
+ // src/patterns/Domain.pattern.ts
37
+ var Domain = "^([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
38
+
30
39
  // src/patterns/Email.pattern.ts
31
- var Email = "^[a-zA-Z0-9._%-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
40
+ var Email = "^[a-zA-Z0-9._-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
41
+
42
+ // src/patterns/HTTP.pattern.ts
43
+ var HTTP = "^(https?:\\/\\/)([a-zA-Z0-9._%+-]+(:[a-zA-Z0-9._%+-]+)?@)?([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(:\\d+)?(\\/[a-zA-Z0-9._-~%!$&'()*+,;=:@/]*)?(\\?[a-zA-Z0-9._~%!$&'()*+,;=:@/?-]*)?$";
32
44
 
33
45
  // src/patterns/PhoneNumber.pattern.ts
34
- var PhoneNumber = "^\\d{4}\\d{7,12}$";
46
+ var PhoneNumber = "^\\d{4}-\\d{7,12}$";
35
47
 
36
- // src/patterns/URL.pattern.ts
37
- var URL = "^(https?:\\/\\/)?([\\w-]+\\.)+[\\w-]{2,}(\\/[\\w-./?%&=]*)?$";
48
+ // src/patterns/URI.pattern.ts
49
+ var URI = "^([a-zA-Z][a-zA-Z0-9+\\-.]*:\\/\\/)([a-zA-Z0-9._%+-]+(:[a-zA-Z0-9._%+-]+)?@)?([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(:\\d+)?(\\/[a-zA-Z0-9._-~%!$&'()*+,;=:@/]*)?(\\?[a-zA-Z0-9._~%!$&'()*+,;=:@/?-]*)?$";
38
50
 
39
51
  // src/patterns/Username.pattern.ts
40
52
  var Username = "^(?=.*[a-zA-Z])[a-zA-Z0-9][a-zA-Z0-9_]*$";
41
53
  // Annotate the CommonJS export names for ESM import in node:
42
54
  0 && (module.exports = {
55
+ Any,
56
+ Domain,
43
57
  Email,
58
+ HTTP,
44
59
  PhoneNumber,
45
- URL,
60
+ URI,
46
61
  Username
47
62
  });
@@ -1,17 +1,29 @@
1
+ // src/patterns/Any.pattern.ts
2
+ var Any = "[\\s\\S]*";
3
+
4
+ // src/patterns/Domain.pattern.ts
5
+ var Domain = "^([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
6
+
1
7
  // src/patterns/Email.pattern.ts
2
- var Email = "^[a-zA-Z0-9._%-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
8
+ var Email = "^[a-zA-Z0-9._-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
9
+
10
+ // src/patterns/HTTP.pattern.ts
11
+ var HTTP = "^(https?:\\/\\/)([a-zA-Z0-9._%+-]+(:[a-zA-Z0-9._%+-]+)?@)?([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(:\\d+)?(\\/[a-zA-Z0-9._-~%!$&'()*+,;=:@/]*)?(\\?[a-zA-Z0-9._~%!$&'()*+,;=:@/?-]*)?$";
3
12
 
4
13
  // src/patterns/PhoneNumber.pattern.ts
5
- var PhoneNumber = "^\\d{4}\\d{7,12}$";
14
+ var PhoneNumber = "^\\d{4}-\\d{7,12}$";
6
15
 
7
- // src/patterns/URL.pattern.ts
8
- var URL = "^(https?:\\/\\/)?([\\w-]+\\.)+[\\w-]{2,}(\\/[\\w-./?%&=]*)?$";
16
+ // src/patterns/URI.pattern.ts
17
+ var URI = "^([a-zA-Z][a-zA-Z0-9+\\-.]*:\\/\\/)([a-zA-Z0-9._%+-]+(:[a-zA-Z0-9._%+-]+)?@)?([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(:\\d+)?(\\/[a-zA-Z0-9._-~%!$&'()*+,;=:@/]*)?(\\?[a-zA-Z0-9._~%!$&'()*+,;=:@/?-]*)?$";
9
18
 
10
19
  // src/patterns/Username.pattern.ts
11
20
  var Username = "^(?=.*[a-zA-Z])[a-zA-Z0-9][a-zA-Z0-9_]*$";
12
21
  export {
22
+ Any,
23
+ Domain,
13
24
  Email,
25
+ HTTP,
14
26
  PhoneNumber,
15
- URL,
27
+ URI,
16
28
  Username
17
29
  };
package/dist/main.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Yuppi } from './Yuppi.class.mjs';
2
- export { P as Patterns } from './Patterns.barrel-KU6hZBXs.mjs';
2
+ export { P as Patterns } from './Patterns.barrel-D-k3IHDq.mjs';
3
3
  export { T as Types } from './Types.barrel--XGUUjIp.mjs';
4
4
  import './types/AnyObject.type.mjs';
5
5
  import 'yup';
@@ -8,8 +8,11 @@ import '@sinclair/typebox';
8
8
  import './types/Schema.type.mjs';
9
9
  import './types/YuppiOptions.type.mjs';
10
10
  import './types/ValidateOptions.type.mjs';
11
+ import './patterns/Any.pattern.mjs';
12
+ import './patterns/Domain.pattern.mjs';
11
13
  import './patterns/Email.pattern.mjs';
14
+ import './patterns/HTTP.pattern.mjs';
12
15
  import './patterns/PhoneNumber.pattern.mjs';
13
- import './patterns/URL.pattern.mjs';
16
+ import './patterns/URI.pattern.mjs';
14
17
  import './patterns/Username.pattern.mjs';
15
18
  import './types/ValidationError.type.mjs';
package/dist/main.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Yuppi } from './Yuppi.class.js';
2
- export { P as Patterns } from './Patterns.barrel-UKU2yPZ6.js';
2
+ export { P as Patterns } from './Patterns.barrel-JdN3lL2Q.js';
3
3
  export { T as Types } from './Types.barrel-wzQq8e9v.js';
4
4
  import './types/AnyObject.type.js';
5
5
  import 'yup';
@@ -8,8 +8,11 @@ import '@sinclair/typebox';
8
8
  import './types/Schema.type.js';
9
9
  import './types/YuppiOptions.type.js';
10
10
  import './types/ValidateOptions.type.js';
11
+ import './patterns/Any.pattern.js';
12
+ import './patterns/Domain.pattern.js';
11
13
  import './patterns/Email.pattern.js';
14
+ import './patterns/HTTP.pattern.js';
12
15
  import './patterns/PhoneNumber.pattern.js';
13
- import './patterns/URL.pattern.js';
16
+ import './patterns/URI.pattern.js';
14
17
  import './patterns/Username.pattern.js';
15
18
  import './types/ValidationError.type.js';
package/dist/main.js CHANGED
@@ -40,6 +40,11 @@ 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
43
48
  var convertToYup = (schema, error_messages) => {
44
49
  const base = (schema2, key, config) => {
45
50
  schema2 = schema2.nullable();
@@ -54,12 +59,12 @@ var convertToYup = (schema, error_messages) => {
54
59
  return true;
55
60
  }
56
61
  );
57
- if (!config.nullable) 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 ?? "").split("{path}").join(path));
58
63
  if (config.default !== void 0) schema2 = schema2.default(config.default);
59
64
  if (config.pattern !== void 0 && schema2.matches !== void 0)
60
65
  schema2 = schema2.matches(
61
- new RegExp(config.pattern ?? "[\\s\\S]*"),
62
- ({ path }) => (error_messages?.base?.pattern ?? "").split("{path}").join(path).split("{pattern}").join(new RegExp(config.pattern ?? "[\\s\\S]*").source)
66
+ new RegExp(config.pattern ?? Any),
67
+ ({ path }) => (error_messages?.base?.pattern ?? "").split("{path}").join(path).split("{pattern}").join(new RegExp(config.pattern ?? Any).source)
63
68
  );
64
69
  return schema2;
65
70
  };
@@ -135,7 +140,7 @@ var import_typebox = require("@sinclair/typebox");
135
140
  var convertToJSONSchema = (schema) => {
136
141
  const build = (key, config) => {
137
142
  if (config.type === "string") {
138
- let schema2 = import_typebox.Type.String({ minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? "[\\s\\S]*").source, default: config.default });
143
+ let schema2 = import_typebox.Type.String({ minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
139
144
  if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
140
145
  return config.required ? schema2 : import_typebox.Type.Optional(schema2);
141
146
  } else if (config.type === "number") {
@@ -147,7 +152,7 @@ var convertToJSONSchema = (schema) => {
147
152
  if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
148
153
  return config.required ? schema2 : import_typebox.Type.Optional(schema2);
149
154
  } else if (config.type === "date") {
150
- let schema2 = import_typebox.Type.String({ format: "date-time", minimum: config.min, maximum: config.max, pattern: new RegExp(config.pattern ?? "[\\s\\S]*").source, default: config.default });
155
+ let schema2 = import_typebox.Type.String({ format: "date-time", minimum: config.min, maximum: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
151
156
  if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
152
157
  return config.required ? schema2 : import_typebox.Type.Optional(schema2);
153
158
  } else if (config.type === "object") {
@@ -232,20 +237,29 @@ var Yuppi = class {
232
237
  // src/barrels/Patterns.barrel.ts
233
238
  var Patterns_barrel_exports = {};
234
239
  __export(Patterns_barrel_exports, {
240
+ Any: () => Any,
241
+ Domain: () => Domain,
235
242
  Email: () => Email,
243
+ HTTP: () => HTTP,
236
244
  PhoneNumber: () => PhoneNumber,
237
- URL: () => URL,
245
+ URI: () => URI,
238
246
  Username: () => Username
239
247
  });
240
248
 
249
+ // src/patterns/Domain.pattern.ts
250
+ var Domain = "^([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
251
+
241
252
  // src/patterns/Email.pattern.ts
242
- var Email = "^[a-zA-Z0-9._%-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
253
+ var Email = "^[a-zA-Z0-9._-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
254
+
255
+ // src/patterns/HTTP.pattern.ts
256
+ var HTTP = "^(https?:\\/\\/)([a-zA-Z0-9._%+-]+(:[a-zA-Z0-9._%+-]+)?@)?([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(:\\d+)?(\\/[a-zA-Z0-9._-~%!$&'()*+,;=:@/]*)?(\\?[a-zA-Z0-9._~%!$&'()*+,;=:@/?-]*)?$";
243
257
 
244
258
  // src/patterns/PhoneNumber.pattern.ts
245
- var PhoneNumber = "^\\d{4}\\d{7,12}$";
259
+ var PhoneNumber = "^\\d{4}-\\d{7,12}$";
246
260
 
247
- // src/patterns/URL.pattern.ts
248
- var URL = "^(https?:\\/\\/)?([\\w-]+\\.)+[\\w-]{2,}(\\/[\\w-./?%&=]*)?$";
261
+ // src/patterns/URI.pattern.ts
262
+ var URI = "^([a-zA-Z][a-zA-Z0-9+\\-.]*:\\/\\/)([a-zA-Z0-9._%+-]+(:[a-zA-Z0-9._%+-]+)?@)?([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(:\\d+)?(\\/[a-zA-Z0-9._-~%!$&'()*+,;=:@/]*)?(\\?[a-zA-Z0-9._~%!$&'()*+,;=:@/?-]*)?$";
249
263
 
250
264
  // src/patterns/Username.pattern.ts
251
265
  var Username = "^(?=.*[a-zA-Z])[a-zA-Z0-9][a-zA-Z0-9_]*$";
package/dist/main.mjs CHANGED
@@ -9,6 +9,11 @@ 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
12
17
  var convertToYup = (schema, error_messages) => {
13
18
  const base = (schema2, key, config) => {
14
19
  schema2 = schema2.nullable();
@@ -23,12 +28,12 @@ var convertToYup = (schema, error_messages) => {
23
28
  return true;
24
29
  }
25
30
  );
26
- if (!config.nullable) 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 ?? "").split("{path}").join(path));
27
32
  if (config.default !== void 0) schema2 = schema2.default(config.default);
28
33
  if (config.pattern !== void 0 && schema2.matches !== void 0)
29
34
  schema2 = schema2.matches(
30
- new RegExp(config.pattern ?? "[\\s\\S]*"),
31
- ({ path }) => (error_messages?.base?.pattern ?? "").split("{path}").join(path).split("{pattern}").join(new RegExp(config.pattern ?? "[\\s\\S]*").source)
35
+ new RegExp(config.pattern ?? Any),
36
+ ({ path }) => (error_messages?.base?.pattern ?? "").split("{path}").join(path).split("{pattern}").join(new RegExp(config.pattern ?? Any).source)
32
37
  );
33
38
  return schema2;
34
39
  };
@@ -104,7 +109,7 @@ import { Type } from "@sinclair/typebox";
104
109
  var convertToJSONSchema = (schema) => {
105
110
  const build = (key, config) => {
106
111
  if (config.type === "string") {
107
- let schema2 = Type.String({ minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? "[\\s\\S]*").source, default: config.default });
112
+ let schema2 = Type.String({ minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
108
113
  if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
109
114
  return config.required ? schema2 : Type.Optional(schema2);
110
115
  } else if (config.type === "number") {
@@ -116,7 +121,7 @@ var convertToJSONSchema = (schema) => {
116
121
  if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
117
122
  return config.required ? schema2 : Type.Optional(schema2);
118
123
  } else if (config.type === "date") {
119
- let schema2 = Type.String({ format: "date-time", minimum: config.min, maximum: config.max, pattern: new RegExp(config.pattern ?? "[\\s\\S]*").source, default: config.default });
124
+ let schema2 = Type.String({ format: "date-time", minimum: config.min, maximum: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
120
125
  if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
121
126
  return config.required ? schema2 : Type.Optional(schema2);
122
127
  } else if (config.type === "object") {
@@ -201,20 +206,29 @@ var Yuppi = class {
201
206
  // src/barrels/Patterns.barrel.ts
202
207
  var Patterns_barrel_exports = {};
203
208
  __export(Patterns_barrel_exports, {
209
+ Any: () => Any,
210
+ Domain: () => Domain,
204
211
  Email: () => Email,
212
+ HTTP: () => HTTP,
205
213
  PhoneNumber: () => PhoneNumber,
206
- URL: () => URL,
214
+ URI: () => URI,
207
215
  Username: () => Username
208
216
  });
209
217
 
218
+ // src/patterns/Domain.pattern.ts
219
+ var Domain = "^([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
220
+
210
221
  // src/patterns/Email.pattern.ts
211
- var Email = "^[a-zA-Z0-9._%-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
222
+ var Email = "^[a-zA-Z0-9._-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
223
+
224
+ // src/patterns/HTTP.pattern.ts
225
+ var HTTP = "^(https?:\\/\\/)([a-zA-Z0-9._%+-]+(:[a-zA-Z0-9._%+-]+)?@)?([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(:\\d+)?(\\/[a-zA-Z0-9._-~%!$&'()*+,;=:@/]*)?(\\?[a-zA-Z0-9._~%!$&'()*+,;=:@/?-]*)?$";
212
226
 
213
227
  // src/patterns/PhoneNumber.pattern.ts
214
- var PhoneNumber = "^\\d{4}\\d{7,12}$";
228
+ var PhoneNumber = "^\\d{4}-\\d{7,12}$";
215
229
 
216
- // src/patterns/URL.pattern.ts
217
- var URL = "^(https?:\\/\\/)?([\\w-]+\\.)+[\\w-]{2,}(\\/[\\w-./?%&=]*)?$";
230
+ // src/patterns/URI.pattern.ts
231
+ var URI = "^([a-zA-Z][a-zA-Z0-9+\\-.]*:\\/\\/)([a-zA-Z0-9._%+-]+(:[a-zA-Z0-9._%+-]+)?@)?([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(:\\d+)?(\\/[a-zA-Z0-9._-~%!$&'()*+,;=:@/]*)?(\\?[a-zA-Z0-9._~%!$&'()*+,;=:@/?-]*)?$";
218
232
 
219
233
  // src/patterns/Username.pattern.ts
220
234
  var Username = "^(?=.*[a-zA-Z])[a-zA-Z0-9][a-zA-Z0-9_]*$";
@@ -0,0 +1,3 @@
1
+ declare const Any: string;
2
+
3
+ export { Any };
@@ -0,0 +1,3 @@
1
+ declare const Any: string;
2
+
3
+ export { Any };
@@ -17,14 +17,14 @@ var __copyProps = (to, from, except, desc) => {
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
- // src/patterns/URL.pattern.ts
21
- var URL_pattern_exports = {};
22
- __export(URL_pattern_exports, {
23
- URL: () => URL
20
+ // src/patterns/Any.pattern.ts
21
+ var Any_pattern_exports = {};
22
+ __export(Any_pattern_exports, {
23
+ Any: () => Any
24
24
  });
25
- module.exports = __toCommonJS(URL_pattern_exports);
26
- var URL = "^(https?:\\/\\/)?([\\w-]+\\.)+[\\w-]{2,}(\\/[\\w-./?%&=]*)?$";
25
+ module.exports = __toCommonJS(Any_pattern_exports);
26
+ var Any = "[\\s\\S]*";
27
27
  // Annotate the CommonJS export names for ESM import in node:
28
28
  0 && (module.exports = {
29
- URL
29
+ Any
30
30
  });
@@ -0,0 +1,5 @@
1
+ // src/patterns/Any.pattern.ts
2
+ var Any = "[\\s\\S]*";
3
+ export {
4
+ Any
5
+ };
@@ -0,0 +1,3 @@
1
+ declare const Domain: string;
2
+
3
+ export { Domain };
@@ -0,0 +1,3 @@
1
+ declare const Domain: string;
2
+
3
+ export { Domain };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/patterns/Domain.pattern.ts
21
+ var Domain_pattern_exports = {};
22
+ __export(Domain_pattern_exports, {
23
+ Domain: () => Domain
24
+ });
25
+ module.exports = __toCommonJS(Domain_pattern_exports);
26
+ var Domain = "^([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ Domain
30
+ });
@@ -0,0 +1,5 @@
1
+ // src/patterns/Domain.pattern.ts
2
+ var Domain = "^([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
3
+ export {
4
+ Domain
5
+ };
@@ -1,5 +1,3 @@
1
- import { Base } from '../types/Schema.type.mjs';
2
-
3
- declare const Email: Base["pattern"];
1
+ declare const Email: string;
4
2
 
5
3
  export { Email };
@@ -1,5 +1,3 @@
1
- import { Base } from '../types/Schema.type.js';
2
-
3
- declare const Email: Base["pattern"];
1
+ declare const Email: string;
4
2
 
5
3
  export { Email };
@@ -23,7 +23,7 @@ __export(Email_pattern_exports, {
23
23
  Email: () => Email
24
24
  });
25
25
  module.exports = __toCommonJS(Email_pattern_exports);
26
- var Email = "^[a-zA-Z0-9._%-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
26
+ var Email = "^[a-zA-Z0-9._-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
27
27
  // Annotate the CommonJS export names for ESM import in node:
28
28
  0 && (module.exports = {
29
29
  Email
@@ -1,5 +1,5 @@
1
1
  // src/patterns/Email.pattern.ts
2
- var Email = "^[a-zA-Z0-9._%-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
2
+ var Email = "^[a-zA-Z0-9._-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
3
3
  export {
4
4
  Email
5
5
  };
@@ -0,0 +1,3 @@
1
+ declare const HTTP: string;
2
+
3
+ export { HTTP };
@@ -0,0 +1,3 @@
1
+ declare const HTTP: string;
2
+
3
+ export { HTTP };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/patterns/HTTP.pattern.ts
21
+ var HTTP_pattern_exports = {};
22
+ __export(HTTP_pattern_exports, {
23
+ HTTP: () => HTTP
24
+ });
25
+ module.exports = __toCommonJS(HTTP_pattern_exports);
26
+ var HTTP = "^(https?:\\/\\/)([a-zA-Z0-9._%+-]+(:[a-zA-Z0-9._%+-]+)?@)?([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(:\\d+)?(\\/[a-zA-Z0-9._-~%!$&'()*+,;=:@/]*)?(\\?[a-zA-Z0-9._~%!$&'()*+,;=:@/?-]*)?$";
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ HTTP
30
+ });
@@ -0,0 +1,5 @@
1
+ // src/patterns/HTTP.pattern.ts
2
+ var HTTP = "^(https?:\\/\\/)([a-zA-Z0-9._%+-]+(:[a-zA-Z0-9._%+-]+)?@)?([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(:\\d+)?(\\/[a-zA-Z0-9._-~%!$&'()*+,;=:@/]*)?(\\?[a-zA-Z0-9._~%!$&'()*+,;=:@/?-]*)?$";
3
+ export {
4
+ HTTP
5
+ };
@@ -1,5 +1,3 @@
1
- import { Base } from '../types/Schema.type.mjs';
2
-
3
- declare const PhoneNumber: Base["pattern"];
1
+ declare const PhoneNumber: string;
4
2
 
5
3
  export { PhoneNumber };
@@ -1,5 +1,3 @@
1
- import { Base } from '../types/Schema.type.js';
2
-
3
- declare const PhoneNumber: Base["pattern"];
1
+ declare const PhoneNumber: string;
4
2
 
5
3
  export { PhoneNumber };
@@ -23,7 +23,7 @@ __export(PhoneNumber_pattern_exports, {
23
23
  PhoneNumber: () => PhoneNumber
24
24
  });
25
25
  module.exports = __toCommonJS(PhoneNumber_pattern_exports);
26
- var PhoneNumber = "^\\d{4}\\d{7,12}$";
26
+ var PhoneNumber = "^\\d{4}-\\d{7,12}$";
27
27
  // Annotate the CommonJS export names for ESM import in node:
28
28
  0 && (module.exports = {
29
29
  PhoneNumber
@@ -1,5 +1,5 @@
1
1
  // src/patterns/PhoneNumber.pattern.ts
2
- var PhoneNumber = "^\\d{4}\\d{7,12}$";
2
+ var PhoneNumber = "^\\d{4}-\\d{7,12}$";
3
3
  export {
4
4
  PhoneNumber
5
5
  };
@@ -0,0 +1,3 @@
1
+ declare const URI: string;
2
+
3
+ export { URI };
@@ -0,0 +1,3 @@
1
+ declare const URI: string;
2
+
3
+ export { URI };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/patterns/URI.pattern.ts
21
+ var URI_pattern_exports = {};
22
+ __export(URI_pattern_exports, {
23
+ URI: () => URI
24
+ });
25
+ module.exports = __toCommonJS(URI_pattern_exports);
26
+ var URI = "^([a-zA-Z][a-zA-Z0-9+\\-.]*:\\/\\/)([a-zA-Z0-9._%+-]+(:[a-zA-Z0-9._%+-]+)?@)?([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(:\\d+)?(\\/[a-zA-Z0-9._-~%!$&'()*+,;=:@/]*)?(\\?[a-zA-Z0-9._~%!$&'()*+,;=:@/?-]*)?$";
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ URI
30
+ });
@@ -0,0 +1,5 @@
1
+ // src/patterns/URI.pattern.ts
2
+ var URI = "^([a-zA-Z][a-zA-Z0-9+\\-.]*:\\/\\/)([a-zA-Z0-9._%+-]+(:[a-zA-Z0-9._%+-]+)?@)?([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(:\\d+)?(\\/[a-zA-Z0-9._-~%!$&'()*+,;=:@/]*)?(\\?[a-zA-Z0-9._~%!$&'()*+,;=:@/?-]*)?$";
3
+ export {
4
+ URI
5
+ };
@@ -1,5 +1,3 @@
1
- import { Base } from '../types/Schema.type.mjs';
2
-
3
- declare const Username: Base["pattern"];
1
+ declare const Username: string;
4
2
 
5
3
  export { Username };
@@ -1,5 +1,3 @@
1
- import { Base } from '../types/Schema.type.js';
2
-
3
- declare const Username: Base["pattern"];
1
+ declare const Username: string;
4
2
 
5
3
  export { Username };
@@ -24,10 +24,15 @@ __export(ConvertToJSONSchema_util_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(ConvertToJSONSchema_util_exports);
26
26
  var import_typebox = require("@sinclair/typebox");
27
+
28
+ // src/patterns/Any.pattern.ts
29
+ var Any = "[\\s\\S]*";
30
+
31
+ // src/utils/ConvertToJSONSchema.util.ts
27
32
  var convertToJSONSchema = (schema) => {
28
33
  const build = (key, config) => {
29
34
  if (config.type === "string") {
30
- let schema2 = import_typebox.Type.String({ minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? "[\\s\\S]*").source, default: config.default });
35
+ let schema2 = import_typebox.Type.String({ minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
31
36
  if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
32
37
  return config.required ? schema2 : import_typebox.Type.Optional(schema2);
33
38
  } else if (config.type === "number") {
@@ -39,7 +44,7 @@ var convertToJSONSchema = (schema) => {
39
44
  if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
40
45
  return config.required ? schema2 : import_typebox.Type.Optional(schema2);
41
46
  } else if (config.type === "date") {
42
- let schema2 = import_typebox.Type.String({ format: "date-time", minimum: config.min, maximum: config.max, pattern: new RegExp(config.pattern ?? "[\\s\\S]*").source, default: config.default });
47
+ let schema2 = import_typebox.Type.String({ format: "date-time", minimum: config.min, maximum: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
43
48
  if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
44
49
  return config.required ? schema2 : import_typebox.Type.Optional(schema2);
45
50
  } else if (config.type === "object") {
@@ -1,9 +1,14 @@
1
1
  // src/utils/ConvertToJSONSchema.util.ts
2
2
  import { Type } from "@sinclair/typebox";
3
+
4
+ // src/patterns/Any.pattern.ts
5
+ var Any = "[\\s\\S]*";
6
+
7
+ // src/utils/ConvertToJSONSchema.util.ts
3
8
  var convertToJSONSchema = (schema) => {
4
9
  const build = (key, config) => {
5
10
  if (config.type === "string") {
6
- let schema2 = Type.String({ minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? "[\\s\\S]*").source, default: config.default });
11
+ let schema2 = Type.String({ minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
7
12
  if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
8
13
  return config.required ? schema2 : Type.Optional(schema2);
9
14
  } else if (config.type === "number") {
@@ -15,7 +20,7 @@ var convertToJSONSchema = (schema) => {
15
20
  if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
16
21
  return config.required ? schema2 : Type.Optional(schema2);
17
22
  } else if (config.type === "date") {
18
- let schema2 = Type.String({ format: "date-time", minimum: config.min, maximum: config.max, pattern: new RegExp(config.pattern ?? "[\\s\\S]*").source, default: config.default });
23
+ let schema2 = Type.String({ format: "date-time", minimum: config.min, maximum: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
19
24
  if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
20
25
  return config.required ? schema2 : Type.Optional(schema2);
21
26
  } else if (config.type === "object") {
@@ -34,6 +34,11 @@ __export(ConvertToYup_util_exports, {
34
34
  });
35
35
  module.exports = __toCommonJS(ConvertToYup_util_exports);
36
36
  var Yup = __toESM(require("yup"));
37
+
38
+ // src/patterns/Any.pattern.ts
39
+ var Any = "[\\s\\S]*";
40
+
41
+ // src/utils/ConvertToYup.util.ts
37
42
  var convertToYup = (schema, error_messages) => {
38
43
  const base = (schema2, key, config) => {
39
44
  schema2 = schema2.nullable();
@@ -48,12 +53,12 @@ var convertToYup = (schema, error_messages) => {
48
53
  return true;
49
54
  }
50
55
  );
51
- if (!config.nullable) schema2 = schema2.nonNullable(({ path }) => (error_messages?.base?.nullable ?? "").split("{path}").join(path));
56
+ if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path }) => (error_messages?.base?.nullable ?? "").split("{path}").join(path));
52
57
  if (config.default !== void 0) schema2 = schema2.default(config.default);
53
58
  if (config.pattern !== void 0 && schema2.matches !== void 0)
54
59
  schema2 = schema2.matches(
55
- new RegExp(config.pattern ?? "[\\s\\S]*"),
56
- ({ path }) => (error_messages?.base?.pattern ?? "").split("{path}").join(path).split("{pattern}").join(new RegExp(config.pattern ?? "[\\s\\S]*").source)
60
+ new RegExp(config.pattern ?? Any),
61
+ ({ path }) => (error_messages?.base?.pattern ?? "").split("{path}").join(path).split("{pattern}").join(new RegExp(config.pattern ?? Any).source)
57
62
  );
58
63
  return schema2;
59
64
  };
@@ -1,5 +1,10 @@
1
1
  // src/utils/ConvertToYup.util.ts
2
2
  import * as Yup from "yup";
3
+
4
+ // src/patterns/Any.pattern.ts
5
+ var Any = "[\\s\\S]*";
6
+
7
+ // src/utils/ConvertToYup.util.ts
3
8
  var convertToYup = (schema, error_messages) => {
4
9
  const base = (schema2, key, config) => {
5
10
  schema2 = schema2.nullable();
@@ -14,12 +19,12 @@ var convertToYup = (schema, error_messages) => {
14
19
  return true;
15
20
  }
16
21
  );
17
- if (!config.nullable) schema2 = schema2.nonNullable(({ path }) => (error_messages?.base?.nullable ?? "").split("{path}").join(path));
22
+ if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path }) => (error_messages?.base?.nullable ?? "").split("{path}").join(path));
18
23
  if (config.default !== void 0) schema2 = schema2.default(config.default);
19
24
  if (config.pattern !== void 0 && schema2.matches !== void 0)
20
25
  schema2 = schema2.matches(
21
- new RegExp(config.pattern ?? "[\\s\\S]*"),
22
- ({ path }) => (error_messages?.base?.pattern ?? "").split("{path}").join(path).split("{pattern}").join(new RegExp(config.pattern ?? "[\\s\\S]*").source)
26
+ new RegExp(config.pattern ?? Any),
27
+ ({ path }) => (error_messages?.base?.pattern ?? "").split("{path}").join(path).split("{pattern}").join(new RegExp(config.pattern ?? Any).source)
23
28
  );
24
29
  return schema2;
25
30
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuppi",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
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",
@@ -15,17 +15,17 @@
15
15
  "lint": "eslint ./"
16
16
  },
17
17
  "dependencies": {
18
- "@sinclair/typebox": "^0.34.35",
19
- "@types/lodash": "^4.17.18",
18
+ "@sinclair/typebox": "^0.34.38",
19
+ "@types/lodash": "^4.17.20",
20
20
  "lodash": "^4.17.21",
21
21
  "yup": "^1.6.1"
22
22
  },
23
23
  "devDependencies": {
24
24
  "jiti": "^2.4.2",
25
- "prettier": "^3.5.3",
25
+ "prettier": "^3.6.2",
26
26
  "tsup": "^8.5.0",
27
27
  "typescript": "^5.8.3",
28
- "typescript-eslint": "^8.34.1"
28
+ "typescript-eslint": "^8.37.0"
29
29
  },
30
30
  "repository": {
31
31
  "type": "git",
@@ -1,14 +0,0 @@
1
- import { Email } from './patterns/Email.pattern.mjs';
2
- import { PhoneNumber } from './patterns/PhoneNumber.pattern.mjs';
3
- import { URL } from './patterns/URL.pattern.mjs';
4
- import { Username } from './patterns/Username.pattern.mjs';
5
-
6
- declare const Patterns_barrel_Email: typeof Email;
7
- declare const Patterns_barrel_PhoneNumber: typeof PhoneNumber;
8
- declare const Patterns_barrel_URL: typeof URL;
9
- declare const Patterns_barrel_Username: typeof Username;
10
- declare namespace Patterns_barrel {
11
- export { Patterns_barrel_Email as Email, Patterns_barrel_PhoneNumber as PhoneNumber, Patterns_barrel_URL as URL, Patterns_barrel_Username as Username };
12
- }
13
-
14
- export { Patterns_barrel as P };
@@ -1,14 +0,0 @@
1
- import { Email } from './patterns/Email.pattern.js';
2
- import { PhoneNumber } from './patterns/PhoneNumber.pattern.js';
3
- import { URL } from './patterns/URL.pattern.js';
4
- import { Username } from './patterns/Username.pattern.js';
5
-
6
- declare const Patterns_barrel_Email: typeof Email;
7
- declare const Patterns_barrel_PhoneNumber: typeof PhoneNumber;
8
- declare const Patterns_barrel_URL: typeof URL;
9
- declare const Patterns_barrel_Username: typeof Username;
10
- declare namespace Patterns_barrel {
11
- export { Patterns_barrel_Email as Email, Patterns_barrel_PhoneNumber as PhoneNumber, Patterns_barrel_URL as URL, Patterns_barrel_Username as Username };
12
- }
13
-
14
- export { Patterns_barrel as P };
@@ -1,5 +0,0 @@
1
- import { Base } from '../types/Schema.type.mjs';
2
-
3
- declare const URL: Base["pattern"];
4
-
5
- export { URL };
@@ -1,5 +0,0 @@
1
- import { Base } from '../types/Schema.type.js';
2
-
3
- declare const URL: Base["pattern"];
4
-
5
- export { URL };
@@ -1,5 +0,0 @@
1
- // src/patterns/URL.pattern.ts
2
- var URL = "^(https?:\\/\\/)?([\\w-]+\\.)+[\\w-]{2,}(\\/[\\w-./?%&=]*)?$";
3
- export {
4
- URL
5
- };