@golemui/gui-validators 0.0.2 → 0.12.1
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 +2 -294
- package/README.md +15 -6
- package/index.d.ts +0 -1
- package/index.js +170 -93
- package/index.umd.cjs +1 -1
- package/lib/validators.d.ts +2 -1
- package/package.json +7 -2
- package/lib/json-schema.d.ts +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,295 +1,3 @@
|
|
|
1
|
-
## 0.
|
|
1
|
+
## 0.12.0 (2026-05-16)
|
|
2
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.
|
|
3
|
+
This was a version bump only for gui-validators to align it with other projects, there were no code changes.
|
package/README.md
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
# gui-validators
|
|
1
|
+
# @golemui/gui-validators
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[Golem UI](https://golemui.com): the declarative form engine.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
```bash
|
|
8
|
+
npm install @golemui/gui-validators
|
|
9
|
+
```
|
|
8
10
|
|
|
9
|
-
##
|
|
11
|
+
## Documentation
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
- Website: https://golemui.com
|
|
14
|
+
- Repository: https://github.com/golemui/golemui
|
|
15
|
+
- Source: https://github.com/golemui/golemui/tree/main/libs/gui/validators
|
|
16
|
+
- Issues: https://github.com/golemui/golemui/issues
|
|
17
|
+
|
|
18
|
+
## License
|
|
19
|
+
|
|
20
|
+
MIT
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,125 +1,202 @@
|
|
|
1
|
-
import { standardValidate as
|
|
2
|
-
import { iso as
|
|
3
|
-
import { uuid as
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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) {
|
|
1
|
+
import { filterTap as w, standardValidate as b, isStandardValidateSuccess as M } from "@golemui/core";
|
|
2
|
+
import { iso as d } from "zod";
|
|
3
|
+
import { uuid as S, url as T, ipv6 as j, ipv4 as E, hostname as F, email as R, optional as _, any as f, superRefine as V, array as l, refine as o, minLength as q, maxLength as I, boolean as x, number as k, int as $, minimum as A, maximum as B, string as y, regex as C } from "zod/mini";
|
|
4
|
+
const g = {
|
|
5
|
+
email: { schema: R() },
|
|
6
|
+
hostname: { schema: F() },
|
|
7
|
+
ipv4: { schema: E() },
|
|
8
|
+
ipv6: { schema: j() },
|
|
9
|
+
url: { schema: T() },
|
|
10
|
+
uuid: { schema: S() },
|
|
11
|
+
date: { schema: d.date() },
|
|
12
|
+
time: { schema: d.time() },
|
|
13
|
+
"date-time": { schema: d.datetime() },
|
|
14
|
+
duration: { schema: d.duration() }
|
|
15
|
+
}, K = Object.keys(g), X = (i) => (m, e) => {
|
|
16
|
+
switch (m.type) {
|
|
34
17
|
case "string":
|
|
35
|
-
return
|
|
18
|
+
return N(m, e);
|
|
36
19
|
case "integer":
|
|
37
20
|
case "number":
|
|
38
|
-
return G(e);
|
|
21
|
+
return G(m, e);
|
|
39
22
|
case "boolean":
|
|
40
|
-
return H(e);
|
|
23
|
+
return H(m, e);
|
|
41
24
|
case "array":
|
|
42
|
-
return
|
|
25
|
+
return J(m, e);
|
|
43
26
|
case "custom": {
|
|
44
27
|
if (!i)
|
|
45
28
|
throw new Error(
|
|
46
29
|
'Validator type "custom" requires a customValidators object, but it was not supplied.'
|
|
47
30
|
);
|
|
48
|
-
return
|
|
31
|
+
return P(m, i);
|
|
49
32
|
}
|
|
50
33
|
}
|
|
51
34
|
};
|
|
52
|
-
function
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
35
|
+
function c(i, m) {
|
|
36
|
+
if (i !== void 0)
|
|
37
|
+
return typeof i == "string" ? i : m?.translate(i.key, i.params, i.default) ?? i.default;
|
|
38
|
+
}
|
|
39
|
+
function N(i, m) {
|
|
40
|
+
return a(i, (e) => {
|
|
41
|
+
const u = c(e.messages?.invalid, m);
|
|
42
|
+
let s = u ? y(u) : y();
|
|
43
|
+
if (e.required === !0) {
|
|
44
|
+
const r = c(e.messages?.required, m) ?? "This field is required";
|
|
45
|
+
s = s.check(o((t) => t.length > 0, { error: r }));
|
|
46
|
+
}
|
|
47
|
+
if (typeof e.minLength == "number") {
|
|
48
|
+
const r = c(e.messages?.minLength, m), t = e.minLength;
|
|
49
|
+
s = s.check(
|
|
50
|
+
r ? o((n) => n.length >= t, { error: r }) : q(t)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
if (typeof e.maxLength == "number") {
|
|
54
|
+
const r = c(e.messages?.maxLength, m), t = e.maxLength;
|
|
55
|
+
s = s.check(
|
|
56
|
+
r ? o((n) => n.length <= t, { error: r }) : I(t)
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
if (typeof e.pattern == "string") {
|
|
60
|
+
const r = c(e.messages?.pattern, m), t = new RegExp(e.pattern);
|
|
61
|
+
s = s.check(
|
|
62
|
+
r ? o((n) => t.test(n), { error: r }) : C(t)
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
if (e.enum) {
|
|
66
|
+
const r = e.enum, t = c(e.messages?.enum, m);
|
|
67
|
+
s = s.check(o((n) => r.includes(n), t ? { error: t } : void 0));
|
|
68
|
+
}
|
|
69
|
+
if (e.const !== void 0) {
|
|
70
|
+
const r = c(e.messages?.const, m);
|
|
71
|
+
s = s.check(o((t) => t === e.const, r ? { error: r } : void 0));
|
|
72
|
+
}
|
|
73
|
+
if (e.format !== void 0)
|
|
74
|
+
if (K.includes(e.format)) {
|
|
75
|
+
const r = c(e.messages?.format, m);
|
|
76
|
+
s = s.check(
|
|
77
|
+
r ? V((t, n) => {
|
|
78
|
+
const h = b(
|
|
79
|
+
g[e.format].schema,
|
|
80
|
+
t
|
|
81
|
+
);
|
|
82
|
+
M(h) || n.addIssue({ code: "custom", path: [], message: r });
|
|
83
|
+
}) : g[e.format].schema
|
|
84
|
+
);
|
|
85
|
+
} else
|
|
86
|
+
console.error(`The string validation format "${e.format}" is not supported`);
|
|
87
|
+
return s;
|
|
60
88
|
});
|
|
61
89
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
90
|
+
const D = (i, m) => {
|
|
91
|
+
if (m === 0)
|
|
92
|
+
return !1;
|
|
93
|
+
const e = i / m;
|
|
94
|
+
return Math.abs(e - Math.round(e)) < 1e-10;
|
|
95
|
+
};
|
|
96
|
+
function G(i, m) {
|
|
97
|
+
return a(i, (e) => {
|
|
98
|
+
const u = c(e.messages?.invalid, m);
|
|
99
|
+
let s = u ? k(u) : k();
|
|
100
|
+
if (e.type === "integer" && (s = s.check($())), e.minimum !== void 0) {
|
|
101
|
+
const r = c(e.messages?.minimum, m), t = e.minimum;
|
|
102
|
+
s = s.check(r ? o((n) => n >= t, { error: r }) : A(t));
|
|
103
|
+
}
|
|
104
|
+
if (e.maximum !== void 0) {
|
|
105
|
+
const r = c(e.messages?.maximum, m), t = e.maximum;
|
|
106
|
+
s = s.check(r ? o((n) => n <= t, { error: r }) : B(t));
|
|
107
|
+
}
|
|
108
|
+
if (e.exclusiveMinimum !== void 0) {
|
|
109
|
+
const r = c(e.messages?.exclusiveMinimum, m), t = e.exclusiveMinimum;
|
|
110
|
+
s = s.check(o((n) => n > t, r ? { error: r } : void 0));
|
|
68
111
|
}
|
|
69
112
|
if (e.exclusiveMaximum !== void 0) {
|
|
70
|
-
const
|
|
71
|
-
|
|
113
|
+
const r = c(e.messages?.exclusiveMaximum, m), t = e.exclusiveMaximum;
|
|
114
|
+
s = s.check(o((n) => n < t, r ? { error: r } : void 0));
|
|
72
115
|
}
|
|
73
116
|
if (e.multipleOf !== void 0) {
|
|
74
|
-
const
|
|
75
|
-
|
|
117
|
+
const r = c(e.messages?.multipleOf, m), t = e.multipleOf;
|
|
118
|
+
s = s.check(
|
|
119
|
+
o((n) => D(n, t), r ? { error: r } : void 0)
|
|
120
|
+
);
|
|
76
121
|
}
|
|
77
122
|
if (e.enum) {
|
|
78
|
-
const
|
|
79
|
-
|
|
123
|
+
const r = e.enum, t = c(e.messages?.enum, m);
|
|
124
|
+
s = s.check(o((n) => r.includes(n), t ? { error: t } : void 0));
|
|
80
125
|
}
|
|
81
|
-
|
|
126
|
+
if (e.const !== void 0) {
|
|
127
|
+
const r = c(e.messages?.const, m);
|
|
128
|
+
s = s.check(o((t) => t === e.const, r ? { error: r } : void 0));
|
|
129
|
+
}
|
|
130
|
+
return s;
|
|
82
131
|
});
|
|
83
132
|
}
|
|
84
|
-
function H(i) {
|
|
85
|
-
return
|
|
86
|
-
|
|
87
|
-
|
|
133
|
+
function H(i, m) {
|
|
134
|
+
return a(i, (e) => {
|
|
135
|
+
const u = c(e.messages?.invalid, m);
|
|
136
|
+
let s = u ? x(u) : x();
|
|
137
|
+
if (e.const !== void 0) {
|
|
138
|
+
const r = c(e.messages?.const, m);
|
|
139
|
+
s = s.check(o((t) => t === e.const, r ? { error: r } : void 0));
|
|
140
|
+
}
|
|
141
|
+
return s;
|
|
88
142
|
});
|
|
89
143
|
}
|
|
90
|
-
function J(i,
|
|
91
|
-
return
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
})
|
|
144
|
+
function J(i, m) {
|
|
145
|
+
return a(i, (e) => {
|
|
146
|
+
const u = c(e.messages?.invalid, m);
|
|
147
|
+
let s = u ? l(f(), u) : l(f());
|
|
148
|
+
if (e.required === !0) {
|
|
149
|
+
const r = c(e.messages?.required, m) ?? "This field is required";
|
|
150
|
+
s = s.check(o((t) => t.length > 0, { error: r }));
|
|
151
|
+
}
|
|
152
|
+
if (typeof e.minItems == "number") {
|
|
153
|
+
const r = c(e.messages?.minItems, m), t = e.minItems;
|
|
154
|
+
s = s.check(
|
|
155
|
+
r ? o((n) => n.length >= t, { error: r }) : q(t)
|
|
110
156
|
);
|
|
111
|
-
}
|
|
157
|
+
}
|
|
158
|
+
if (typeof e.maxItems == "number") {
|
|
159
|
+
const r = c(e.messages?.maxItems, m), t = e.maxItems;
|
|
160
|
+
s = s.check(
|
|
161
|
+
r ? o((n) => n.length <= t, { error: r }) : I(t)
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
return s;
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
function P(i, m) {
|
|
168
|
+
return a(i, (e) => {
|
|
169
|
+
let u = f();
|
|
170
|
+
return w(
|
|
171
|
+
Object.keys(e),
|
|
172
|
+
// filter non-custom validator keys
|
|
173
|
+
(s) => s !== "type" && s !== "required",
|
|
174
|
+
(s) => {
|
|
175
|
+
const r = e[s], t = m[s], n = t(r);
|
|
176
|
+
u = u.check(
|
|
177
|
+
V((h, L) => {
|
|
178
|
+
const p = b(
|
|
179
|
+
n,
|
|
180
|
+
h
|
|
181
|
+
);
|
|
182
|
+
if (!M(p)) {
|
|
183
|
+
const O = p.issues[0];
|
|
184
|
+
L.addIssue({
|
|
185
|
+
code: "custom",
|
|
186
|
+
path: [],
|
|
187
|
+
message: O?.message || `Validation failed for ${s}`
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
), u;
|
|
112
194
|
});
|
|
113
195
|
}
|
|
114
|
-
function
|
|
115
|
-
const
|
|
116
|
-
return i.required ?
|
|
196
|
+
function a(i, m) {
|
|
197
|
+
const e = m(i);
|
|
198
|
+
return i.required ? e : _(e);
|
|
117
199
|
}
|
|
118
200
|
export {
|
|
119
|
-
|
|
120
|
-
X as initValidators,
|
|
121
|
-
K as integerValidator,
|
|
122
|
-
W as jsonSchemaValidators,
|
|
123
|
-
D as numberValidator,
|
|
124
|
-
C as stringValidator
|
|
201
|
+
X as initValidators
|
|
125
202
|
};
|
package/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(i,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("@golemui/core"),require("zod"),require("zod/mini")):typeof define=="function"&&define.amd?define(["exports","@golemui/core","zod","zod/mini"],d):(i=typeof globalThis<"u"?globalThis:i||self,d(i["gui-validators"]={},i.core,i.zod,i.mini))})(this,(function(i,d,h,n){"use strict";const g={email:{schema:n.email()},hostname:{schema:n.hostname()},ipv4:{schema:n.ipv4()},ipv6:{schema:n.ipv6()},url:{schema:n.url()},uuid:{schema:n.uuid()},date:{schema:h.iso.date()},time:{schema:h.iso.time()},"date-time":{schema:h.iso.datetime()},duration:{schema:h.iso.duration()}},x=Object.keys(g),y=u=>(o,e)=>{switch(o.type){case"string":return k(o,e);case"integer":case"number":return M(o,e);case"boolean":return V(o,e);case"array":return q(o,e);case"custom":{if(!u)throw new Error('Validator type "custom" requires a customValidators object, but it was not supplied.');return L(o,u)}}};function m(u,o){if(u!==void 0)return typeof u=="string"?u:o?.translate(u.key,u.params,u.default)??u.default}function k(u,o){return f(u,e=>{const a=m(e.messages?.invalid,o);let s=a?n.string(a):n.string();if(e.required===!0){const r=m(e.messages?.required,o)??"This field is required";s=s.check(n.refine(t=>t.length>0,{error:r}))}if(typeof e.minLength=="number"){const r=m(e.messages?.minLength,o),t=e.minLength;s=s.check(r?n.refine(c=>c.length>=t,{error:r}):n.minLength(t))}if(typeof e.maxLength=="number"){const r=m(e.messages?.maxLength,o),t=e.maxLength;s=s.check(r?n.refine(c=>c.length<=t,{error:r}):n.maxLength(t))}if(typeof e.pattern=="string"){const r=m(e.messages?.pattern,o),t=new RegExp(e.pattern);s=s.check(r?n.refine(c=>t.test(c),{error:r}):n.regex(t))}if(e.enum){const r=e.enum,t=m(e.messages?.enum,o);s=s.check(n.refine(c=>r.includes(c),t?{error:t}:void 0))}if(e.const!==void 0){const r=m(e.messages?.const,o);s=s.check(n.refine(t=>t===e.const,r?{error:r}:void 0))}if(e.format!==void 0)if(x.includes(e.format)){const r=m(e.messages?.format,o);s=s.check(r?n.superRefine((t,c)=>{const p=d.standardValidate(g[e.format].schema,t);d.isStandardValidateSuccess(p)||c.addIssue({code:"custom",path:[],message:r})}):g[e.format].schema)}else console.error(`The string validation format "${e.format}" is not supported`);return s})}const b=(u,o)=>{if(o===0)return!1;const e=u/o;return Math.abs(e-Math.round(e))<1e-10};function M(u,o){return f(u,e=>{const a=m(e.messages?.invalid,o);let s=a?n.number(a):n.number();if(e.type==="integer"&&(s=s.check(n.int())),e.minimum!==void 0){const r=m(e.messages?.minimum,o),t=e.minimum;s=s.check(r?n.refine(c=>c>=t,{error:r}):n.minimum(t))}if(e.maximum!==void 0){const r=m(e.messages?.maximum,o),t=e.maximum;s=s.check(r?n.refine(c=>c<=t,{error:r}):n.maximum(t))}if(e.exclusiveMinimum!==void 0){const r=m(e.messages?.exclusiveMinimum,o),t=e.exclusiveMinimum;s=s.check(n.refine(c=>c>t,r?{error:r}:void 0))}if(e.exclusiveMaximum!==void 0){const r=m(e.messages?.exclusiveMaximum,o),t=e.exclusiveMaximum;s=s.check(n.refine(c=>c<t,r?{error:r}:void 0))}if(e.multipleOf!==void 0){const r=m(e.messages?.multipleOf,o),t=e.multipleOf;s=s.check(n.refine(c=>b(c,t),r?{error:r}:void 0))}if(e.enum){const r=e.enum,t=m(e.messages?.enum,o);s=s.check(n.refine(c=>r.includes(c),t?{error:t}:void 0))}if(e.const!==void 0){const r=m(e.messages?.const,o);s=s.check(n.refine(t=>t===e.const,r?{error:r}:void 0))}return s})}function V(u,o){return f(u,e=>{const a=m(e.messages?.invalid,o);let s=a?n.boolean(a):n.boolean();if(e.const!==void 0){const r=m(e.messages?.const,o);s=s.check(n.refine(t=>t===e.const,r?{error:r}:void 0))}return s})}function q(u,o){return f(u,e=>{const a=m(e.messages?.invalid,o);let s=a?n.array(n.any(),a):n.array(n.any());if(e.required===!0){const r=m(e.messages?.required,o)??"This field is required";s=s.check(n.refine(t=>t.length>0,{error:r}))}if(typeof e.minItems=="number"){const r=m(e.messages?.minItems,o),t=e.minItems;s=s.check(r?n.refine(c=>c.length>=t,{error:r}):n.minLength(t))}if(typeof e.maxItems=="number"){const r=m(e.messages?.maxItems,o),t=e.maxItems;s=s.check(r?n.refine(c=>c.length<=t,{error:r}):n.maxLength(t))}return s})}function L(u,o){return f(u,e=>{let a=n.any();return d.filterTap(Object.keys(e),s=>s!=="type"&&s!=="required",s=>{const r=e[s],t=o[s],c=t(r);a=a.check(n.superRefine((p,S)=>{const l=d.standardValidate(c,p);if(!d.isStandardValidateSuccess(l)){const I=l.issues[0];S.addIssue({code:"custom",path:[],message:I?.message||`Validation failed for ${s}`})}}))}),a})}function f(u,o){const e=o(u);return u.required?e:n.optional(e)}i.initValidators=y,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
|
package/lib/validators.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { ValidatorFn } from '@golemui/core';
|
|
1
|
+
import { Localizable, ValidatorFn } from '@golemui/core';
|
|
2
2
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
3
|
import { iso } from 'zod';
|
|
4
4
|
interface BaseValidator {
|
|
5
5
|
const?: unknown;
|
|
6
6
|
enum?: unknown[];
|
|
7
7
|
required?: boolean;
|
|
8
|
+
messages?: Record<string, Localizable>;
|
|
8
9
|
}
|
|
9
10
|
declare const stringFormat: {
|
|
10
11
|
email: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@golemui/gui-validators",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.umd.cjs",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -22,6 +22,11 @@
|
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"zod": "^4.0.0",
|
|
24
24
|
"@standard-schema/spec": "^1.0.0",
|
|
25
|
-
"@golemui/core": "
|
|
25
|
+
"@golemui/core": "0.12.1"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/golemui/golemui.git",
|
|
30
|
+
"directory": "libs/gui/validators"
|
|
26
31
|
}
|
|
27
32
|
}
|
package/lib/json-schema.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
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>;
|