unischema 1.0.1 → 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 (70) hide show
  1. package/README.md +780 -228
  2. package/dist/adapters/backend/index.d.mts +2 -1
  3. package/dist/adapters/backend/index.d.ts +2 -1
  4. package/dist/adapters/backend/index.js +17 -441
  5. package/dist/adapters/backend/index.mjs +9 -433
  6. package/dist/adapters/frontend/index.d.mts +2 -1
  7. package/dist/adapters/frontend/index.d.ts +2 -1
  8. package/dist/adapters/frontend/index.js +10 -421
  9. package/dist/adapters/frontend/index.mjs +8 -419
  10. package/dist/chunk-5A4ITJVD.mjs +124 -0
  11. package/dist/chunk-66RFUBVU.js +131 -0
  12. package/dist/chunk-75YSYC4K.mjs +85 -0
  13. package/dist/chunk-76BBWQDH.js +90 -0
  14. package/dist/chunk-7XES4A3M.mjs +237 -0
  15. package/dist/chunk-BVRXGZLS.js +17 -0
  16. package/dist/chunk-COMVAVFU.mjs +335 -0
  17. package/dist/chunk-DT2TQZU7.js +796 -0
  18. package/dist/chunk-FPCCH55A.js +103 -0
  19. package/dist/chunk-IUXRLMET.js +206 -0
  20. package/dist/chunk-JEW6U6CB.js +353 -0
  21. package/dist/chunk-KZCV5IW4.mjs +97 -0
  22. package/dist/chunk-KZZ7NVU3.mjs +41 -0
  23. package/dist/chunk-MFEBMQAU.mjs +779 -0
  24. package/dist/chunk-OIYG5D2I.js +50 -0
  25. package/dist/chunk-RW6HDA5H.mjs +194 -0
  26. package/dist/chunk-TTK77YBI.mjs +15 -0
  27. package/dist/chunk-TXT36BCE.js +248 -0
  28. package/dist/index-C17xs-fU.d.mts +140 -0
  29. package/dist/index-C17xs-fU.d.ts +140 -0
  30. package/dist/index.d.mts +26 -7
  31. package/dist/index.d.ts +26 -7
  32. package/dist/index.js +769 -499
  33. package/dist/index.mjs +695 -487
  34. package/dist/{schema-D9DGC9E_.d.ts → schema-DYE8Wz8X.d.mts} +264 -79
  35. package/dist/{schema-D9DGC9E_.d.mts → schema-Dtp-joeT.d.ts} +264 -79
  36. package/dist/validators/array.d.mts +15 -0
  37. package/dist/validators/array.d.ts +15 -0
  38. package/dist/validators/array.js +31 -0
  39. package/dist/validators/array.mjs +2 -0
  40. package/dist/validators/common.d.mts +13 -0
  41. package/dist/validators/common.d.ts +13 -0
  42. package/dist/validators/common.js +27 -0
  43. package/dist/validators/common.mjs +2 -0
  44. package/dist/validators/date.d.mts +23 -0
  45. package/dist/validators/date.d.ts +23 -0
  46. package/dist/validators/date.js +47 -0
  47. package/dist/validators/date.mjs +2 -0
  48. package/dist/validators/index.d.mts +46 -0
  49. package/dist/validators/index.d.ts +46 -0
  50. package/dist/validators/index.js +256 -0
  51. package/dist/validators/index.mjs +7 -0
  52. package/dist/validators/number.d.mts +25 -0
  53. package/dist/validators/number.d.ts +25 -0
  54. package/dist/validators/number.js +51 -0
  55. package/dist/validators/number.mjs +2 -0
  56. package/dist/validators/object.d.mts +11 -0
  57. package/dist/validators/object.d.ts +11 -0
  58. package/dist/validators/object.js +23 -0
  59. package/dist/validators/object.mjs +2 -0
  60. package/dist/validators/string.d.mts +37 -0
  61. package/dist/validators/string.d.ts +37 -0
  62. package/dist/validators/string.js +75 -0
  63. package/dist/validators/string.mjs +2 -0
  64. package/package.json +82 -5
  65. package/dist/adapters/backend/index.js.map +0 -1
  66. package/dist/adapters/backend/index.mjs.map +0 -1
  67. package/dist/adapters/frontend/index.js.map +0 -1
  68. package/dist/adapters/frontend/index.mjs.map +0 -1
  69. package/dist/index.js.map +0 -1
  70. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,103 @@
1
+ 'use strict';
2
+
3
+ var chunkOIYG5D2I_js = require('./chunk-OIYG5D2I.js');
4
+
5
+ // src/validators/common/notMatches.ts
6
+ var notMatchesValidator = (value, params, context) => {
7
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
8
+ const fieldName = params?.field;
9
+ const soft = params?.soft;
10
+ const message = params?.message;
11
+ if (!fieldName) return null;
12
+ const root = context.root;
13
+ const otherValue = root?.[fieldName];
14
+ if (value === otherValue) {
15
+ return chunkOIYG5D2I_js.createError(
16
+ context,
17
+ "INVALID_NOT_MATCHES",
18
+ message || `Must not match ${fieldName}`,
19
+ soft
20
+ );
21
+ }
22
+ return null;
23
+ };
24
+
25
+ // src/validators/common/greaterThan.ts
26
+ var greaterThanValidator = (value, params, context) => {
27
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
28
+ const fieldName = params?.field;
29
+ const soft = params?.soft;
30
+ const message = params?.message;
31
+ if (!chunkOIYG5D2I_js.isNumber(value) || !fieldName) return null;
32
+ const root = context.root;
33
+ const otherValue = root?.[fieldName];
34
+ if (chunkOIYG5D2I_js.isNumber(otherValue) && value <= otherValue) {
35
+ return chunkOIYG5D2I_js.createError(
36
+ context,
37
+ "INVALID_GREATER_THAN",
38
+ message || `Must be greater than ${fieldName}`,
39
+ soft
40
+ );
41
+ }
42
+ return null;
43
+ };
44
+
45
+ // src/validators/common/lessThan.ts
46
+ var lessThanValidator = (value, params, context) => {
47
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
48
+ const fieldName = params?.field;
49
+ const soft = params?.soft;
50
+ const message = params?.message;
51
+ if (!chunkOIYG5D2I_js.isNumber(value) || !fieldName) return null;
52
+ const root = context.root;
53
+ const otherValue = root?.[fieldName];
54
+ if (chunkOIYG5D2I_js.isNumber(otherValue) && value >= otherValue) {
55
+ return chunkOIYG5D2I_js.createError(
56
+ context,
57
+ "INVALID_LESS_THAN",
58
+ message || `Must be less than ${fieldName}`,
59
+ soft
60
+ );
61
+ }
62
+ return null;
63
+ };
64
+
65
+ // src/validators/common/when.ts
66
+ var whenValidator = (value, params, context) => {
67
+ const fieldName = params?.field;
68
+ const is = params?.is;
69
+ const then = params?.then;
70
+ if (!fieldName || !then) return null;
71
+ const root = context.root;
72
+ const otherValue = root?.[fieldName];
73
+ if (otherValue === is) {
74
+ return then(value, params, context);
75
+ }
76
+ return null;
77
+ };
78
+
79
+ // src/validators/common/dependsOn.ts
80
+ var dependsOnValidator = (value, params, context) => {
81
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
82
+ const fieldName = params?.field;
83
+ const soft = params?.soft;
84
+ const message = params?.message;
85
+ if (!fieldName) return null;
86
+ const root = context.root;
87
+ const otherValue = root?.[fieldName];
88
+ if (chunkOIYG5D2I_js.isEmpty(otherValue)) {
89
+ return chunkOIYG5D2I_js.createError(
90
+ context,
91
+ "INVALID_DEPENDS_ON",
92
+ message || `This field requires ${fieldName} to be set`,
93
+ soft
94
+ );
95
+ }
96
+ return null;
97
+ };
98
+
99
+ exports.dependsOnValidator = dependsOnValidator;
100
+ exports.greaterThanValidator = greaterThanValidator;
101
+ exports.lessThanValidator = lessThanValidator;
102
+ exports.notMatchesValidator = notMatchesValidator;
103
+ exports.whenValidator = whenValidator;
@@ -0,0 +1,206 @@
1
+ 'use strict';
2
+
3
+ var chunkOIYG5D2I_js = require('./chunk-OIYG5D2I.js');
4
+
5
+ // src/validators/number/port.ts
6
+ var portValidator = (value, params, context) => {
7
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
8
+ const soft = params?.soft;
9
+ const message = params?.message;
10
+ if (!chunkOIYG5D2I_js.isNumber(value)) return null;
11
+ if (!Number.isInteger(value) || value < 0 || value > 65535) {
12
+ return chunkOIYG5D2I_js.createError(
13
+ context,
14
+ "INVALID_PORT",
15
+ message || "Must be a valid port number (0-65535)",
16
+ soft
17
+ );
18
+ }
19
+ return null;
20
+ };
21
+
22
+ // src/validators/number/latitude.ts
23
+ var latitudeValidator = (value, params, context) => {
24
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
25
+ const soft = params?.soft;
26
+ const message = params?.message;
27
+ if (!chunkOIYG5D2I_js.isNumber(value)) return null;
28
+ if (value < -90 || value > 90) {
29
+ return chunkOIYG5D2I_js.createError(
30
+ context,
31
+ "INVALID_LATITUDE",
32
+ message || "Latitude must be between -90 and 90",
33
+ soft
34
+ );
35
+ }
36
+ return null;
37
+ };
38
+
39
+ // src/validators/number/longitude.ts
40
+ var longitudeValidator = (value, params, context) => {
41
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
42
+ const soft = params?.soft;
43
+ const message = params?.message;
44
+ if (!chunkOIYG5D2I_js.isNumber(value)) return null;
45
+ if (value < -180 || value > 180) {
46
+ return chunkOIYG5D2I_js.createError(
47
+ context,
48
+ "INVALID_LONGITUDE",
49
+ message || "Longitude must be between -180 and 180",
50
+ soft
51
+ );
52
+ }
53
+ return null;
54
+ };
55
+
56
+ // src/validators/number/percentage.ts
57
+ var percentageValidator = (value, params, context) => {
58
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
59
+ const soft = params?.soft;
60
+ const message = params?.message;
61
+ if (!chunkOIYG5D2I_js.isNumber(value)) return null;
62
+ if (value < 0 || value > 100) {
63
+ return chunkOIYG5D2I_js.createError(
64
+ context,
65
+ "INVALID_PERCENTAGE",
66
+ message || "Percentage must be between 0 and 100",
67
+ soft
68
+ );
69
+ }
70
+ return null;
71
+ };
72
+
73
+ // src/validators/number/between.ts
74
+ var betweenValidator = (value, params, context) => {
75
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
76
+ const min = params?.min;
77
+ const max = params?.max;
78
+ const soft = params?.soft;
79
+ const message = params?.message;
80
+ if (!chunkOIYG5D2I_js.isNumber(value)) return null;
81
+ if (value < min || value > max) {
82
+ return chunkOIYG5D2I_js.createError(
83
+ context,
84
+ "INVALID_BETWEEN",
85
+ message || `Must be between ${min} and ${max}`,
86
+ soft
87
+ );
88
+ }
89
+ return null;
90
+ };
91
+
92
+ // src/validators/number/divisibleBy.ts
93
+ var divisibleByValidator = (value, params, context) => {
94
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
95
+ const divisor = params?.divisor;
96
+ const soft = params?.soft;
97
+ const message = params?.message;
98
+ if (!chunkOIYG5D2I_js.isNumber(value)) return null;
99
+ if (value % divisor !== 0) {
100
+ return chunkOIYG5D2I_js.createError(
101
+ context,
102
+ "INVALID_DIVISIBLE_BY",
103
+ message || `Must be divisible by ${divisor}`,
104
+ soft
105
+ );
106
+ }
107
+ return null;
108
+ };
109
+
110
+ // src/validators/number/multipleOf.ts
111
+ var multipleOfValidator = (value, params, context) => {
112
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
113
+ const multiple = params?.multiple;
114
+ const soft = params?.soft;
115
+ const message = params?.message;
116
+ if (!chunkOIYG5D2I_js.isNumber(value)) return null;
117
+ if (value % multiple !== 0) {
118
+ return chunkOIYG5D2I_js.createError(
119
+ context,
120
+ "INVALID_MULTIPLE_OF",
121
+ message || `Must be a multiple of ${multiple}`,
122
+ soft
123
+ );
124
+ }
125
+ return null;
126
+ };
127
+
128
+ // src/validators/number/even.ts
129
+ var evenValidator = (value, params, context) => {
130
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
131
+ const soft = params?.soft;
132
+ const message = params?.message;
133
+ if (!chunkOIYG5D2I_js.isNumber(value)) return null;
134
+ if (value % 2 !== 0) {
135
+ return chunkOIYG5D2I_js.createError(
136
+ context,
137
+ "INVALID_EVEN",
138
+ message || "Must be an even number",
139
+ soft
140
+ );
141
+ }
142
+ return null;
143
+ };
144
+
145
+ // src/validators/number/odd.ts
146
+ var oddValidator = (value, params, context) => {
147
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
148
+ const soft = params?.soft;
149
+ const message = params?.message;
150
+ if (!chunkOIYG5D2I_js.isNumber(value)) return null;
151
+ if (value % 2 === 0) {
152
+ return chunkOIYG5D2I_js.createError(
153
+ context,
154
+ "INVALID_ODD",
155
+ message || "Must be an odd number",
156
+ soft
157
+ );
158
+ }
159
+ return null;
160
+ };
161
+
162
+ // src/validators/number/safe.ts
163
+ var safeValidator = (value, params, context) => {
164
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
165
+ const soft = params?.soft;
166
+ const message = params?.message;
167
+ if (!chunkOIYG5D2I_js.isNumber(value)) return null;
168
+ if (!Number.isSafeInteger(value)) {
169
+ return chunkOIYG5D2I_js.createError(
170
+ context,
171
+ "INVALID_SAFE_INTEGER",
172
+ message || "Must be a safe integer",
173
+ soft
174
+ );
175
+ }
176
+ return null;
177
+ };
178
+
179
+ // src/validators/number/finite.ts
180
+ var finiteValidator = (value, params, context) => {
181
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
182
+ const soft = params?.soft;
183
+ const message = params?.message;
184
+ if (!chunkOIYG5D2I_js.isNumber(value)) return null;
185
+ if (!Number.isFinite(value)) {
186
+ return chunkOIYG5D2I_js.createError(
187
+ context,
188
+ "INVALID_FINITE",
189
+ message || "Must be a finite number",
190
+ soft
191
+ );
192
+ }
193
+ return null;
194
+ };
195
+
196
+ exports.betweenValidator = betweenValidator;
197
+ exports.divisibleByValidator = divisibleByValidator;
198
+ exports.evenValidator = evenValidator;
199
+ exports.finiteValidator = finiteValidator;
200
+ exports.latitudeValidator = latitudeValidator;
201
+ exports.longitudeValidator = longitudeValidator;
202
+ exports.multipleOfValidator = multipleOfValidator;
203
+ exports.oddValidator = oddValidator;
204
+ exports.percentageValidator = percentageValidator;
205
+ exports.portValidator = portValidator;
206
+ exports.safeValidator = safeValidator;
@@ -0,0 +1,353 @@
1
+ 'use strict';
2
+
3
+ var chunkOIYG5D2I_js = require('./chunk-OIYG5D2I.js');
4
+
5
+ // src/validators/string/email.ts
6
+ var EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
7
+ var emailValidator = (value, params, context) => {
8
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
9
+ const soft = params?.soft;
10
+ const message = params?.message;
11
+ if (!chunkOIYG5D2I_js.isString(value)) {
12
+ return chunkOIYG5D2I_js.createError(context, "INVALID_EMAIL", "Email must be a string", soft);
13
+ }
14
+ if (!EMAIL_REGEX.test(value)) {
15
+ return chunkOIYG5D2I_js.createError(
16
+ context,
17
+ "INVALID_EMAIL",
18
+ message || "Invalid email address",
19
+ soft
20
+ );
21
+ }
22
+ return null;
23
+ };
24
+
25
+ // src/validators/string/url.ts
26
+ var urlValidator = (value, params, context) => {
27
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
28
+ const soft = params?.soft;
29
+ const message = params?.message;
30
+ if (!chunkOIYG5D2I_js.isString(value)) {
31
+ return chunkOIYG5D2I_js.createError(context, "INVALID_URL", "URL must be a string", soft);
32
+ }
33
+ try {
34
+ new URL(value);
35
+ return null;
36
+ } catch {
37
+ return chunkOIYG5D2I_js.createError(
38
+ context,
39
+ "INVALID_URL",
40
+ message || "Invalid URL format",
41
+ soft
42
+ );
43
+ }
44
+ };
45
+
46
+ // src/validators/string/ipAddress.ts
47
+ var IPV4_REGEX = /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
48
+ var ipAddressValidator = (value, params, context) => {
49
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
50
+ const soft = params?.soft;
51
+ const message = params?.message;
52
+ if (!chunkOIYG5D2I_js.isString(value)) {
53
+ return chunkOIYG5D2I_js.createError(context, "INVALID_IP", "IP address must be a string", soft);
54
+ }
55
+ if (!IPV4_REGEX.test(value)) {
56
+ return chunkOIYG5D2I_js.createError(
57
+ context,
58
+ "INVALID_IP",
59
+ message || "Invalid IP address format",
60
+ soft
61
+ );
62
+ }
63
+ return null;
64
+ };
65
+
66
+ // src/validators/string/ipv6.ts
67
+ var IPV6_REGEX = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|::)$/;
68
+ var ipv6Validator = (value, params, context) => {
69
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
70
+ const soft = params?.soft;
71
+ const message = params?.message;
72
+ if (!chunkOIYG5D2I_js.isString(value)) {
73
+ return chunkOIYG5D2I_js.createError(context, "INVALID_IPV6", "IPv6 address must be a string", soft);
74
+ }
75
+ if (!IPV6_REGEX.test(value)) {
76
+ return chunkOIYG5D2I_js.createError(
77
+ context,
78
+ "INVALID_IPV6",
79
+ message || "Invalid IPv6 address format",
80
+ soft
81
+ );
82
+ }
83
+ return null;
84
+ };
85
+
86
+ // src/validators/string/alpha.ts
87
+ var ALPHA_REGEX = /^[a-zA-Z]+$/;
88
+ var alphaValidator = (value, params, context) => {
89
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
90
+ const soft = params?.soft;
91
+ const message = params?.message;
92
+ if (!chunkOIYG5D2I_js.isString(value)) {
93
+ return chunkOIYG5D2I_js.createError(context, "INVALID_ALPHA", "Value must be a string", soft);
94
+ }
95
+ if (!ALPHA_REGEX.test(value)) {
96
+ return chunkOIYG5D2I_js.createError(
97
+ context,
98
+ "INVALID_ALPHA",
99
+ message || "Must contain only letters",
100
+ soft
101
+ );
102
+ }
103
+ return null;
104
+ };
105
+
106
+ // src/validators/string/alphanumeric.ts
107
+ var ALPHANUMERIC_REGEX = /^[a-zA-Z0-9]+$/;
108
+ var alphanumericValidator = (value, params, context) => {
109
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
110
+ const soft = params?.soft;
111
+ const message = params?.message;
112
+ if (!chunkOIYG5D2I_js.isString(value)) {
113
+ return chunkOIYG5D2I_js.createError(context, "INVALID_ALPHANUMERIC", "Value must be a string", soft);
114
+ }
115
+ if (!ALPHANUMERIC_REGEX.test(value)) {
116
+ return chunkOIYG5D2I_js.createError(
117
+ context,
118
+ "INVALID_ALPHANUMERIC",
119
+ message || "Must contain only letters and numbers",
120
+ soft
121
+ );
122
+ }
123
+ return null;
124
+ };
125
+
126
+ // src/validators/string/numeric.ts
127
+ var NUMERIC_REGEX = /^[0-9]+$/;
128
+ var numericValidator = (value, params, context) => {
129
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
130
+ const soft = params?.soft;
131
+ const message = params?.message;
132
+ if (!chunkOIYG5D2I_js.isString(value)) {
133
+ return chunkOIYG5D2I_js.createError(context, "INVALID_NUMERIC", "Value must be a string", soft);
134
+ }
135
+ if (!NUMERIC_REGEX.test(value)) {
136
+ return chunkOIYG5D2I_js.createError(
137
+ context,
138
+ "INVALID_NUMERIC",
139
+ message || "Must contain only numbers",
140
+ soft
141
+ );
142
+ }
143
+ return null;
144
+ };
145
+
146
+ // src/validators/string/lowercase.ts
147
+ var lowercaseValidator = (value, params, context) => {
148
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
149
+ const soft = params?.soft;
150
+ const message = params?.message;
151
+ if (!chunkOIYG5D2I_js.isString(value)) {
152
+ return chunkOIYG5D2I_js.createError(context, "INVALID_LOWERCASE", "Value must be a string", soft);
153
+ }
154
+ if (value !== value.toLowerCase()) {
155
+ return chunkOIYG5D2I_js.createError(
156
+ context,
157
+ "INVALID_LOWERCASE",
158
+ message || "Must be lowercase",
159
+ soft
160
+ );
161
+ }
162
+ return null;
163
+ };
164
+
165
+ // src/validators/string/uppercase.ts
166
+ var uppercaseValidator = (value, params, context) => {
167
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
168
+ const soft = params?.soft;
169
+ const message = params?.message;
170
+ if (!chunkOIYG5D2I_js.isString(value)) {
171
+ return chunkOIYG5D2I_js.createError(context, "INVALID_UPPERCASE", "Value must be a string", soft);
172
+ }
173
+ if (value !== value.toUpperCase()) {
174
+ return chunkOIYG5D2I_js.createError(
175
+ context,
176
+ "INVALID_UPPERCASE",
177
+ message || "Must be uppercase",
178
+ soft
179
+ );
180
+ }
181
+ return null;
182
+ };
183
+
184
+ // src/validators/string/slug.ts
185
+ var SLUG_REGEX = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
186
+ var slugValidator = (value, params, context) => {
187
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
188
+ const soft = params?.soft;
189
+ const message = params?.message;
190
+ if (!chunkOIYG5D2I_js.isString(value)) {
191
+ return chunkOIYG5D2I_js.createError(context, "INVALID_SLUG", "Slug must be a string", soft);
192
+ }
193
+ if (!SLUG_REGEX.test(value)) {
194
+ return chunkOIYG5D2I_js.createError(
195
+ context,
196
+ "INVALID_SLUG",
197
+ message || "Must be a valid URL slug (lowercase, numbers, hyphens)",
198
+ soft
199
+ );
200
+ }
201
+ return null;
202
+ };
203
+
204
+ // src/validators/string/hex.ts
205
+ var HEX_REGEX = /^(0x)?[0-9a-fA-F]+$/;
206
+ var hexValidator = (value, params, context) => {
207
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
208
+ const soft = params?.soft;
209
+ const message = params?.message;
210
+ if (!chunkOIYG5D2I_js.isString(value)) {
211
+ return chunkOIYG5D2I_js.createError(context, "INVALID_HEX", "Hex value must be a string", soft);
212
+ }
213
+ if (!HEX_REGEX.test(value)) {
214
+ return chunkOIYG5D2I_js.createError(
215
+ context,
216
+ "INVALID_HEX",
217
+ message || "Must be a valid hexadecimal string",
218
+ soft
219
+ );
220
+ }
221
+ return null;
222
+ };
223
+
224
+ // src/validators/string/base64.ts
225
+ var BASE64_REGEX = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
226
+ var base64Validator = (value, params, context) => {
227
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
228
+ const soft = params?.soft;
229
+ const message = params?.message;
230
+ if (!chunkOIYG5D2I_js.isString(value)) {
231
+ return chunkOIYG5D2I_js.createError(context, "INVALID_BASE64", "Base64 value must be a string", soft);
232
+ }
233
+ if (!BASE64_REGEX.test(value)) {
234
+ return chunkOIYG5D2I_js.createError(
235
+ context,
236
+ "INVALID_BASE64",
237
+ message || "Must be a valid base64 string",
238
+ soft
239
+ );
240
+ }
241
+ return null;
242
+ };
243
+
244
+ // src/validators/string/json.ts
245
+ var jsonValidator = (value, params, context) => {
246
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
247
+ const soft = params?.soft;
248
+ const message = params?.message;
249
+ if (!chunkOIYG5D2I_js.isString(value)) {
250
+ return chunkOIYG5D2I_js.createError(context, "INVALID_JSON", "JSON value must be a string", soft);
251
+ }
252
+ try {
253
+ JSON.parse(value);
254
+ return null;
255
+ } catch {
256
+ return chunkOIYG5D2I_js.createError(
257
+ context,
258
+ "INVALID_JSON",
259
+ message || "Must be valid JSON",
260
+ soft
261
+ );
262
+ }
263
+ };
264
+
265
+ // src/validators/string/length.ts
266
+ var lengthValidator = (value, params, context) => {
267
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
268
+ const length = params?.length;
269
+ const soft = params?.soft;
270
+ const message = params?.message;
271
+ if (!chunkOIYG5D2I_js.isString(value)) return null;
272
+ if (value.length !== length) {
273
+ return chunkOIYG5D2I_js.createError(
274
+ context,
275
+ "INVALID_LENGTH",
276
+ message || `Must be exactly ${length} characters`,
277
+ soft
278
+ );
279
+ }
280
+ return null;
281
+ };
282
+
283
+ // src/validators/string/contains.ts
284
+ var containsValidator = (value, params, context) => {
285
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
286
+ const substring = params?.substring;
287
+ const soft = params?.soft;
288
+ const message = params?.message;
289
+ if (!chunkOIYG5D2I_js.isString(value)) return null;
290
+ if (!value.includes(substring)) {
291
+ return chunkOIYG5D2I_js.createError(
292
+ context,
293
+ "INVALID_CONTAINS",
294
+ message || `Must contain "${substring}"`,
295
+ soft
296
+ );
297
+ }
298
+ return null;
299
+ };
300
+
301
+ // src/validators/string/startsWith.ts
302
+ var startsWithValidator = (value, params, context) => {
303
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
304
+ const prefix = params?.prefix;
305
+ const soft = params?.soft;
306
+ const message = params?.message;
307
+ if (!chunkOIYG5D2I_js.isString(value)) return null;
308
+ if (!value.startsWith(prefix)) {
309
+ return chunkOIYG5D2I_js.createError(
310
+ context,
311
+ "INVALID_STARTS_WITH",
312
+ message || `Must start with "${prefix}"`,
313
+ soft
314
+ );
315
+ }
316
+ return null;
317
+ };
318
+
319
+ // src/validators/string/endsWith.ts
320
+ var endsWithValidator = (value, params, context) => {
321
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
322
+ const suffix = params?.suffix;
323
+ const soft = params?.soft;
324
+ const message = params?.message;
325
+ if (!chunkOIYG5D2I_js.isString(value)) return null;
326
+ if (!value.endsWith(suffix)) {
327
+ return chunkOIYG5D2I_js.createError(
328
+ context,
329
+ "INVALID_ENDS_WITH",
330
+ message || `Must end with "${suffix}"`,
331
+ soft
332
+ );
333
+ }
334
+ return null;
335
+ };
336
+
337
+ exports.alphaValidator = alphaValidator;
338
+ exports.alphanumericValidator = alphanumericValidator;
339
+ exports.base64Validator = base64Validator;
340
+ exports.containsValidator = containsValidator;
341
+ exports.emailValidator = emailValidator;
342
+ exports.endsWithValidator = endsWithValidator;
343
+ exports.hexValidator = hexValidator;
344
+ exports.ipAddressValidator = ipAddressValidator;
345
+ exports.ipv6Validator = ipv6Validator;
346
+ exports.jsonValidator = jsonValidator;
347
+ exports.lengthValidator = lengthValidator;
348
+ exports.lowercaseValidator = lowercaseValidator;
349
+ exports.numericValidator = numericValidator;
350
+ exports.slugValidator = slugValidator;
351
+ exports.startsWithValidator = startsWithValidator;
352
+ exports.uppercaseValidator = uppercaseValidator;
353
+ exports.urlValidator = urlValidator;