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