@golemui/gui-validators 0.0.2
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/CHANGELOG.md +295 -0
- package/README.md +11 -0
- package/index.d.ts +2 -0
- package/index.js +125 -0
- package/index.umd.cjs +1 -0
- package/lib/json-schema.d.ts +7 -0
- package/lib/validators.d.ts +78 -0
- package/package.json +27 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
## 0.19.0 (2026-03-02)
|
|
2
|
+
|
|
3
|
+
This was a version bump only for gui-validators to align it with other projects, there were no code changes.
|
|
4
|
+
|
|
5
|
+
## 0.18.0 (2026-01-13)
|
|
6
|
+
|
|
7
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
8
|
+
|
|
9
|
+
## 0.17.0 (2026-01-11)
|
|
10
|
+
|
|
11
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
12
|
+
|
|
13
|
+
## 0.16.0 (2026-01-05)
|
|
14
|
+
|
|
15
|
+
### 🩹 Fixes
|
|
16
|
+
|
|
17
|
+
- **vanilla-validators:** empty string when field is required is a validation error ([84d7458](https://github.com/golemui/formforge/commit/84d7458))
|
|
18
|
+
- **vanilla-validators:** add correct check for string length ([28babd9](https://github.com/golemui/formforge/commit/28babd9))
|
|
19
|
+
- **vanilla-validators:** empty string when field is required is a validation error ([0ba6bbd](https://github.com/golemui/formforge/commit/0ba6bbd))
|
|
20
|
+
|
|
21
|
+
### ❤️ Thank You
|
|
22
|
+
|
|
23
|
+
- Joan Llenas
|
|
24
|
+
|
|
25
|
+
## 0.15.2 (2026-01-03)
|
|
26
|
+
|
|
27
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
28
|
+
|
|
29
|
+
## 0.15.1 (2025-12-27)
|
|
30
|
+
|
|
31
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
32
|
+
|
|
33
|
+
## 0.15.0 (2025-12-27)
|
|
34
|
+
|
|
35
|
+
### 🩹 Fixes
|
|
36
|
+
|
|
37
|
+
- expand ReactiveFieldFunction support to events ([9478304](https://github.com/golemui/formforge/commit/9478304))
|
|
38
|
+
|
|
39
|
+
### ❤️ Thank You
|
|
40
|
+
|
|
41
|
+
- Joan Llenas
|
|
42
|
+
|
|
43
|
+
## 0.14.11 (2025-12-21)
|
|
44
|
+
|
|
45
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
46
|
+
|
|
47
|
+
## 0.14.10 (2025-12-20)
|
|
48
|
+
|
|
49
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
50
|
+
|
|
51
|
+
## 0.14.9 (2025-12-20)
|
|
52
|
+
|
|
53
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
54
|
+
|
|
55
|
+
## 0.14.8 (2025-12-20)
|
|
56
|
+
|
|
57
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
58
|
+
|
|
59
|
+
## 0.14.7 (2025-12-18)
|
|
60
|
+
|
|
61
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
62
|
+
|
|
63
|
+
## 0.14.6 (2025-12-18)
|
|
64
|
+
|
|
65
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
66
|
+
|
|
67
|
+
## 0.14.5 (2025-12-17)
|
|
68
|
+
|
|
69
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
70
|
+
|
|
71
|
+
## 0.14.4 (2025-12-17)
|
|
72
|
+
|
|
73
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
74
|
+
|
|
75
|
+
## 0.14.3 (2025-12-16)
|
|
76
|
+
|
|
77
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
78
|
+
|
|
79
|
+
## 0.14.2 (2025-12-16)
|
|
80
|
+
|
|
81
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
82
|
+
|
|
83
|
+
## 0.14.1 (2025-12-15)
|
|
84
|
+
|
|
85
|
+
### 🩹 Fixes
|
|
86
|
+
|
|
87
|
+
- reverse exclusiveMaximum validator ([fabf4a1](https://github.com/golemui/formforge/commit/fabf4a1))
|
|
88
|
+
|
|
89
|
+
### ❤️ Thank You
|
|
90
|
+
|
|
91
|
+
- Raul Jimenez @Elecash
|
|
92
|
+
|
|
93
|
+
## 0.14.0 (2025-12-14)
|
|
94
|
+
|
|
95
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
96
|
+
|
|
97
|
+
## 0.13.0 (2025-12-11)
|
|
98
|
+
|
|
99
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
100
|
+
|
|
101
|
+
## 0.12.0 (2025-12-11)
|
|
102
|
+
|
|
103
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
104
|
+
|
|
105
|
+
## 0.11.0 (2025-12-08)
|
|
106
|
+
|
|
107
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
108
|
+
|
|
109
|
+
## 0.10.0 (2025-12-08)
|
|
110
|
+
|
|
111
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
112
|
+
|
|
113
|
+
## 0.9.0 (2025-12-08)
|
|
114
|
+
|
|
115
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
116
|
+
|
|
117
|
+
## 0.8.0 (2025-12-07)
|
|
118
|
+
|
|
119
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
120
|
+
|
|
121
|
+
## 0.7.1 (2025-12-07)
|
|
122
|
+
|
|
123
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
124
|
+
|
|
125
|
+
## 0.7.0 (2025-12-04)
|
|
126
|
+
|
|
127
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
128
|
+
|
|
129
|
+
## 0.6.0 (2025-12-03)
|
|
130
|
+
|
|
131
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
132
|
+
|
|
133
|
+
## 0.5.0 (2025-11-30)
|
|
134
|
+
|
|
135
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
136
|
+
|
|
137
|
+
## 0.4.0 (2025-11-30)
|
|
138
|
+
|
|
139
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
140
|
+
|
|
141
|
+
## 0.3.26 (2025-11-29)
|
|
142
|
+
|
|
143
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
144
|
+
|
|
145
|
+
## 0.3.25 (2025-11-27)
|
|
146
|
+
|
|
147
|
+
### 🩹 Fixes
|
|
148
|
+
|
|
149
|
+
- **angular:** force installation of zod v4 ([964f529](https://github.com/golemui/formforge/commit/964f529))
|
|
150
|
+
|
|
151
|
+
### ❤️ Thank You
|
|
152
|
+
|
|
153
|
+
- Raul Jimenez @Elecash
|
|
154
|
+
|
|
155
|
+
## 0.3.24 (2025-11-27)
|
|
156
|
+
|
|
157
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
158
|
+
|
|
159
|
+
## 0.3.23 (2025-11-27)
|
|
160
|
+
|
|
161
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
162
|
+
|
|
163
|
+
## 0.3.22 (2025-11-27)
|
|
164
|
+
|
|
165
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
166
|
+
|
|
167
|
+
## 0.3.21 (2025-11-27)
|
|
168
|
+
|
|
169
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
170
|
+
|
|
171
|
+
## 0.3.20 (2025-11-26)
|
|
172
|
+
|
|
173
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
174
|
+
|
|
175
|
+
## 0.3.19 (2025-11-26)
|
|
176
|
+
|
|
177
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
178
|
+
|
|
179
|
+
## 0.3.18 (2025-11-26)
|
|
180
|
+
|
|
181
|
+
### 🩹 Fixes
|
|
182
|
+
|
|
183
|
+
- build all libraries with vite ([2880d7f](https://github.com/golemui/formforge/commit/2880d7f))
|
|
184
|
+
|
|
185
|
+
### ❤️ Thank You
|
|
186
|
+
|
|
187
|
+
- Raul Jimenez @Elecash
|
|
188
|
+
|
|
189
|
+
## 0.3.17 (2025-11-25)
|
|
190
|
+
|
|
191
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
192
|
+
|
|
193
|
+
## 0.3.16 (2025-11-25)
|
|
194
|
+
|
|
195
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
196
|
+
|
|
197
|
+
## 0.3.15 (2025-11-25)
|
|
198
|
+
|
|
199
|
+
### 🩹 Fixes
|
|
200
|
+
|
|
201
|
+
- build with nx ([3f423b4](https://github.com/golemui/formforge/commit/3f423b4))
|
|
202
|
+
|
|
203
|
+
### ❤️ Thank You
|
|
204
|
+
|
|
205
|
+
- Raul Jimenez @Elecash
|
|
206
|
+
|
|
207
|
+
## 0.3.14 (2025-11-24)
|
|
208
|
+
|
|
209
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
210
|
+
|
|
211
|
+
## 0.3.13 (2025-11-24)
|
|
212
|
+
|
|
213
|
+
### 🩹 Fixes
|
|
214
|
+
|
|
215
|
+
- include correct paths in shared and validators ([a676081](https://github.com/golemui/formforge/commit/a676081))
|
|
216
|
+
|
|
217
|
+
### ❤️ Thank You
|
|
218
|
+
|
|
219
|
+
- Raul Jimenez @Elecash
|
|
220
|
+
|
|
221
|
+
## 0.3.12 (2025-11-24)
|
|
222
|
+
|
|
223
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
224
|
+
|
|
225
|
+
## 0.3.11 (2025-11-24)
|
|
226
|
+
|
|
227
|
+
### 🩹 Fixes
|
|
228
|
+
|
|
229
|
+
- build files to output cjs and js ([20d24ec](https://github.com/golemui/formforge/commit/20d24ec))
|
|
230
|
+
|
|
231
|
+
### ❤️ Thank You
|
|
232
|
+
|
|
233
|
+
- Raul Jimenez @Elecash
|
|
234
|
+
|
|
235
|
+
## 0.3.10 (2025-11-24)
|
|
236
|
+
|
|
237
|
+
### 🩹 Fixes
|
|
238
|
+
|
|
239
|
+
- shared and validators package exports ([f160cea](https://github.com/golemui/formforge/commit/f160cea))
|
|
240
|
+
|
|
241
|
+
### ❤️ Thank You
|
|
242
|
+
|
|
243
|
+
- Raul Jimenez @Elecash
|
|
244
|
+
|
|
245
|
+
## 0.3.9 (2025-11-24)
|
|
246
|
+
|
|
247
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
248
|
+
|
|
249
|
+
## 0.3.8 (2025-11-24)
|
|
250
|
+
|
|
251
|
+
### 🩹 Fixes
|
|
252
|
+
|
|
253
|
+
- build libs for es2022 and commonjs ([7a7c037](https://github.com/golemui/formforge/commit/7a7c037))
|
|
254
|
+
|
|
255
|
+
### ❤️ Thank You
|
|
256
|
+
|
|
257
|
+
- Raul Jimenez @Elecash
|
|
258
|
+
|
|
259
|
+
## 0.3.7 (2025-11-23)
|
|
260
|
+
|
|
261
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
262
|
+
|
|
263
|
+
## 0.3.6 (2025-11-23)
|
|
264
|
+
|
|
265
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
266
|
+
|
|
267
|
+
## 0.3.5 (2025-11-23)
|
|
268
|
+
|
|
269
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
270
|
+
|
|
271
|
+
## 0.3.4 (2025-11-23)
|
|
272
|
+
|
|
273
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
274
|
+
|
|
275
|
+
## 0.3.3 (2025-11-23)
|
|
276
|
+
|
|
277
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
278
|
+
|
|
279
|
+
## 0.3.2 (2025-11-23)
|
|
280
|
+
|
|
281
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
|
282
|
+
|
|
283
|
+
## 0.3.1 (2025-11-23)
|
|
284
|
+
|
|
285
|
+
### 🩹 Fixes
|
|
286
|
+
|
|
287
|
+
- add validators-vanilla to package ([bf69a9c](https://github.com/golemui/formforge/commit/bf69a9c))
|
|
288
|
+
|
|
289
|
+
### ❤️ Thank You
|
|
290
|
+
|
|
291
|
+
- Joan Llenas
|
|
292
|
+
|
|
293
|
+
## 0.3.0 (2025-11-23)
|
|
294
|
+
|
|
295
|
+
This was a version bump only for validators-vanilla to align it with other projects, there were no code changes.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# gui-validators
|
|
2
|
+
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).
|
|
4
|
+
|
|
5
|
+
## Building
|
|
6
|
+
|
|
7
|
+
Run `nx build gui-validators` to build the library.
|
|
8
|
+
|
|
9
|
+
## Running unit tests
|
|
10
|
+
|
|
11
|
+
Run `nx test gui-validators` to execute the unit tests via [Vitest](https://vitest.dev/).
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { standardValidate as k, isStandardValidateSuccess as b } from "@golemui/core";
|
|
2
|
+
import { iso as c } from "zod";
|
|
3
|
+
import { uuid as x, url as y, ipv6 as V, ipv4 as w, hostname as O, email as L, success as S, any as m, optional as q, string as j, refine as o, minLength as E, maxLength as M, regex as F, number as T, int as I, minimum as R, maximum as _, boolean as $, superRefine as B } from "zod/mini";
|
|
4
|
+
const C = (i) => ({
|
|
5
|
+
type: "string",
|
|
6
|
+
...i || {}
|
|
7
|
+
}), D = (i) => ({
|
|
8
|
+
type: "number",
|
|
9
|
+
...i || {}
|
|
10
|
+
}), K = (i) => ({
|
|
11
|
+
type: "integer",
|
|
12
|
+
...i || {}
|
|
13
|
+
}), N = (i) => ({
|
|
14
|
+
type: "boolean",
|
|
15
|
+
...i || {}
|
|
16
|
+
}), W = {
|
|
17
|
+
stringValidator: C,
|
|
18
|
+
booleanValidator: N,
|
|
19
|
+
numberValidator: D,
|
|
20
|
+
integerValidator: K
|
|
21
|
+
}, u = {
|
|
22
|
+
email: { schema: L() },
|
|
23
|
+
hostname: { schema: O() },
|
|
24
|
+
ipv4: { schema: w() },
|
|
25
|
+
ipv6: { schema: V() },
|
|
26
|
+
url: { schema: y() },
|
|
27
|
+
uuid: { schema: x() },
|
|
28
|
+
date: { schema: c.date() },
|
|
29
|
+
time: { schema: c.time() },
|
|
30
|
+
"date-time": { schema: c.datetime() },
|
|
31
|
+
duration: { schema: c.duration() }
|
|
32
|
+
}, z = Object.keys(u), X = (i) => (e) => {
|
|
33
|
+
switch (e.type) {
|
|
34
|
+
case "string":
|
|
35
|
+
return A(e);
|
|
36
|
+
case "integer":
|
|
37
|
+
case "number":
|
|
38
|
+
return G(e);
|
|
39
|
+
case "boolean":
|
|
40
|
+
return H(e);
|
|
41
|
+
case "array":
|
|
42
|
+
return console.warn("TODO: array validator not yet supported"), S(m());
|
|
43
|
+
case "custom": {
|
|
44
|
+
if (!i)
|
|
45
|
+
throw new Error(
|
|
46
|
+
'Validator type "custom" requires a customValidators object, but it was not supplied.'
|
|
47
|
+
);
|
|
48
|
+
return J(e, i);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
function A(i) {
|
|
53
|
+
return s(i, (e) => {
|
|
54
|
+
let t = j();
|
|
55
|
+
if (e.required === !0 && (t = t.check(o((n) => n.length > 0, { error: "This field is required" }))), typeof e.minLength == "number" && (t = t.check(E(e.minLength))), typeof e.maxLength == "number" && (t = t.check(M(e.maxLength))), typeof e.pattern == "string" && (t = t.check(F(new RegExp(e.pattern)))), e.enum) {
|
|
56
|
+
const n = e.enum;
|
|
57
|
+
t = t.check(o((r) => n.includes(r)));
|
|
58
|
+
}
|
|
59
|
+
return e.const !== void 0 && (t = t.check(o((n) => n === e.const))), e.format !== void 0 && (z.includes(e.format) ? t = t.check(u[e.format].schema) : console.error(`The string validation format "${e.format}" is not supported`)), t;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function G(i) {
|
|
63
|
+
return s(i, (e) => {
|
|
64
|
+
let t = T();
|
|
65
|
+
if (e.type === "integer" && (t = t.check(I())), e.minimum !== void 0 && (t = t.check(R(e.minimum))), e.maximum !== void 0 && (t = t.check(_(e.maximum))), e.exclusiveMinimum !== void 0) {
|
|
66
|
+
const n = e.exclusiveMinimum;
|
|
67
|
+
t = t.check(o((r) => r > n));
|
|
68
|
+
}
|
|
69
|
+
if (e.exclusiveMaximum !== void 0) {
|
|
70
|
+
const n = e.exclusiveMaximum;
|
|
71
|
+
t = t.check(o((r) => r < n));
|
|
72
|
+
}
|
|
73
|
+
if (e.multipleOf !== void 0) {
|
|
74
|
+
const n = e.multipleOf;
|
|
75
|
+
t = t.check(o((r) => r % n === 0));
|
|
76
|
+
}
|
|
77
|
+
if (e.enum) {
|
|
78
|
+
const n = e.enum;
|
|
79
|
+
t = t.check(o((r) => n.includes(r)));
|
|
80
|
+
}
|
|
81
|
+
return e.const !== void 0 && (t = t.check(o((n) => n === e.const))), t;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function H(i) {
|
|
85
|
+
return s(i, (e) => {
|
|
86
|
+
let t = $();
|
|
87
|
+
return e.const !== void 0 && (t = t.check(o((n) => n === e.const))), t;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function J(i, e) {
|
|
91
|
+
return s(i, (t) => {
|
|
92
|
+
let n = m();
|
|
93
|
+
return Object.keys(t).filter((r) => r !== "type" && r !== "required").forEach((r) => {
|
|
94
|
+
const h = t[r], d = e[r], f = d(h);
|
|
95
|
+
n = n.check(
|
|
96
|
+
B((l, p) => {
|
|
97
|
+
const a = k(
|
|
98
|
+
f,
|
|
99
|
+
l
|
|
100
|
+
);
|
|
101
|
+
if (!b(a)) {
|
|
102
|
+
const g = a.issues[0];
|
|
103
|
+
p.addIssue({
|
|
104
|
+
code: "custom",
|
|
105
|
+
path: [],
|
|
106
|
+
message: g?.message || `Validation failed for ${r}`
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
}), n;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function s(i, e) {
|
|
115
|
+
const t = e(i);
|
|
116
|
+
return i.required ? t : q(t);
|
|
117
|
+
}
|
|
118
|
+
export {
|
|
119
|
+
N as booleanValidator,
|
|
120
|
+
X as initValidators,
|
|
121
|
+
K as integerValidator,
|
|
122
|
+
W as jsonSchemaValidators,
|
|
123
|
+
D as numberValidator,
|
|
124
|
+
C as stringValidator
|
|
125
|
+
};
|
package/index.umd.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@golemui/core"),require("zod"),require("zod/mini")):typeof define=="function"&&define.amd?define(["exports","@golemui/core","zod","zod/mini"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s["gui-validators"]={},s.core,s.zod,s.mini))})(this,(function(s,c,a,r){"use strict";const m=n=>({type:"string",...n||{}}),d=n=>({type:"number",...n||{}}),f=n=>({type:"integer",...n||{}}),l=n=>({type:"boolean",...n||{}}),g={stringValidator:m,booleanValidator:l,numberValidator:d,integerValidator:f},h={email:{schema:r.email()},hostname:{schema:r.hostname()},ipv4:{schema:r.ipv4()},ipv6:{schema:r.ipv6()},url:{schema:r.url()},uuid:{schema:r.uuid()},date:{schema:a.iso.date()},time:{schema:a.iso.time()},"date-time":{schema:a.iso.datetime()},duration:{schema:a.iso.duration()}},y=Object.keys(h),V=n=>e=>{switch(e.type){case"string":return b(e);case"integer":case"number":return k(e);case"boolean":return x(e);case"array":return console.warn("TODO: array validator not yet supported"),r.success(r.any());case"custom":{if(!n)throw new Error('Validator type "custom" requires a customValidators object, but it was not supplied.');return S(e,n)}}};function b(n){return u(n,e=>{let t=r.string();if(e.required===!0&&(t=t.check(r.refine(o=>o.length>0,{error:"This field is required"}))),typeof e.minLength=="number"&&(t=t.check(r.minLength(e.minLength))),typeof e.maxLength=="number"&&(t=t.check(r.maxLength(e.maxLength))),typeof e.pattern=="string"&&(t=t.check(r.regex(new RegExp(e.pattern)))),e.enum){const o=e.enum;t=t.check(r.refine(i=>o.includes(i)))}return e.const!==void 0&&(t=t.check(r.refine(o=>o===e.const))),e.format!==void 0&&(y.includes(e.format)?t=t.check(h[e.format].schema):console.error(`The string validation format "${e.format}" is not supported`)),t})}function k(n){return u(n,e=>{let t=r.number();if(e.type==="integer"&&(t=t.check(r.int())),e.minimum!==void 0&&(t=t.check(r.minimum(e.minimum))),e.maximum!==void 0&&(t=t.check(r.maximum(e.maximum))),e.exclusiveMinimum!==void 0){const o=e.exclusiveMinimum;t=t.check(r.refine(i=>i>o))}if(e.exclusiveMaximum!==void 0){const o=e.exclusiveMaximum;t=t.check(r.refine(i=>i<o))}if(e.multipleOf!==void 0){const o=e.multipleOf;t=t.check(r.refine(i=>i%o===0))}if(e.enum){const o=e.enum;t=t.check(r.refine(i=>o.includes(i)))}return e.const!==void 0&&(t=t.check(r.refine(o=>o===e.const))),t})}function x(n){return u(n,e=>{let t=r.boolean();return e.const!==void 0&&(t=t.check(r.refine(o=>o===e.const))),t})}function S(n,e){return u(n,t=>{let o=r.any();return Object.keys(t).filter(i=>i!=="type"&&i!=="required").forEach(i=>{const q=t[i],O=e[i],j=O(q);o=o.check(r.superRefine((w,L)=>{const p=c.standardValidate(j,w);if(!c.isStandardValidateSuccess(p)){const T=p.issues[0];L.addIssue({code:"custom",path:[],message:T?.message||`Validation failed for ${i}`})}}))}),o})}function u(n,e){const t=e(n);return n.required?t:r.optional(t)}s.booleanValidator=l,s.initValidators=V,s.integerValidator=f,s.jsonSchemaValidators=g,s.numberValidator=d,s.stringValidator=m,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BooleanValidator, NumberValidator, StringValidator, Validator } from './validators';
|
|
2
|
+
import { JsonSchemaValidators } from '@golemui/core';
|
|
3
|
+
export declare const stringValidator: (config?: Omit<StringValidator, "type">) => StringValidator;
|
|
4
|
+
export declare const numberValidator: (config?: Omit<NumberValidator, "type">) => NumberValidator;
|
|
5
|
+
export declare const integerValidator: (config?: Omit<NumberValidator, "type">) => NumberValidator;
|
|
6
|
+
export declare const booleanValidator: (config?: Omit<BooleanValidator, "type">) => BooleanValidator;
|
|
7
|
+
export declare const jsonSchemaValidators: JsonSchemaValidators<Validator>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { ValidatorFn } from '@golemui/core';
|
|
2
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
|
+
import { iso } from 'zod';
|
|
4
|
+
interface BaseValidator {
|
|
5
|
+
const?: unknown;
|
|
6
|
+
enum?: unknown[];
|
|
7
|
+
required?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare const stringFormat: {
|
|
10
|
+
email: {
|
|
11
|
+
schema: import('zod/mini').ZodMiniEmail;
|
|
12
|
+
};
|
|
13
|
+
hostname: {
|
|
14
|
+
schema: import('zod/mini').ZodMiniCustomStringFormat<"hostname">;
|
|
15
|
+
};
|
|
16
|
+
ipv4: {
|
|
17
|
+
schema: import('zod/mini').ZodMiniIPv4;
|
|
18
|
+
};
|
|
19
|
+
ipv6: {
|
|
20
|
+
schema: import('zod/mini').ZodMiniIPv6;
|
|
21
|
+
};
|
|
22
|
+
url: {
|
|
23
|
+
schema: import('zod/mini').ZodMiniURL;
|
|
24
|
+
};
|
|
25
|
+
uuid: {
|
|
26
|
+
schema: import('zod/mini').ZodMiniUUID;
|
|
27
|
+
};
|
|
28
|
+
date: {
|
|
29
|
+
schema: iso.ZodISODate;
|
|
30
|
+
};
|
|
31
|
+
time: {
|
|
32
|
+
schema: iso.ZodISOTime;
|
|
33
|
+
};
|
|
34
|
+
'date-time': {
|
|
35
|
+
schema: iso.ZodISODateTime;
|
|
36
|
+
};
|
|
37
|
+
duration: {
|
|
38
|
+
schema: iso.ZodISODuration;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
type StringFormat = keyof typeof stringFormat;
|
|
42
|
+
export interface StringValidator extends BaseValidator {
|
|
43
|
+
type: 'string';
|
|
44
|
+
minLength?: number;
|
|
45
|
+
maxLength?: number;
|
|
46
|
+
pattern?: string;
|
|
47
|
+
format?: StringFormat;
|
|
48
|
+
}
|
|
49
|
+
export interface NumberValidator extends BaseValidator {
|
|
50
|
+
type: 'number' | 'integer';
|
|
51
|
+
minimum?: number;
|
|
52
|
+
maximum?: number;
|
|
53
|
+
exclusiveMinimum?: number;
|
|
54
|
+
exclusiveMaximum?: number;
|
|
55
|
+
multipleOf?: number;
|
|
56
|
+
}
|
|
57
|
+
export interface BooleanValidator extends BaseValidator {
|
|
58
|
+
type: 'boolean';
|
|
59
|
+
}
|
|
60
|
+
export interface ArrayValidator extends BaseValidator {
|
|
61
|
+
type: 'array';
|
|
62
|
+
minItems?: number;
|
|
63
|
+
maxItems?: number;
|
|
64
|
+
uniqueItems?: boolean;
|
|
65
|
+
items?: Validator;
|
|
66
|
+
}
|
|
67
|
+
export interface CustomValidator {
|
|
68
|
+
type: 'custom';
|
|
69
|
+
required?: boolean;
|
|
70
|
+
[key: string]: unknown;
|
|
71
|
+
}
|
|
72
|
+
export type CustomValidatorSchemaFn = (input: any) => StandardSchemaV1;
|
|
73
|
+
export type CustomValidatorSchemas = {
|
|
74
|
+
[key: string]: CustomValidatorSchemaFn;
|
|
75
|
+
};
|
|
76
|
+
export type Validator = StringValidator | NumberValidator | BooleanValidator | ArrayValidator | CustomValidator;
|
|
77
|
+
export declare const initValidators: (customValidators?: CustomValidatorSchemas) => ValidatorFn<Validator>;
|
|
78
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@golemui/gui-validators",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./index.umd.cjs",
|
|
6
|
+
"module": "./index.js",
|
|
7
|
+
"types": "./index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"import": "./index.js",
|
|
12
|
+
"require": "./index.umd.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"lib",
|
|
17
|
+
"index.d.ts",
|
|
18
|
+
"index.js",
|
|
19
|
+
"index.umd.cjs",
|
|
20
|
+
"*.md"
|
|
21
|
+
],
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"zod": "^4.0.0",
|
|
24
|
+
"@standard-schema/spec": "^1.0.0",
|
|
25
|
+
"@golemui/core": "*"
|
|
26
|
+
}
|
|
27
|
+
}
|