@golemui/gui-validators 1.0.2 → 1.1.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 +8 -0
- package/index.js +42 -42
- package/index.umd.cjs +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## 1.0.3 (2026-07-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
|
+
## 1.0.2 (2026-06-26)
|
|
6
|
+
|
|
7
|
+
This was a version bump only for gui-validators to align it with other projects, there were no code changes.
|
|
8
|
+
|
|
1
9
|
## 1.0.1 (2026-06-15)
|
|
2
10
|
|
|
3
11
|
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,7 +1,7 @@
|
|
|
1
1
|
import { filterTap as w, standardValidate as b, isStandardValidateSuccess as M } from "@golemui/core";
|
|
2
2
|
import "@standard-schema/spec";
|
|
3
3
|
import { iso as d } from "zod";
|
|
4
|
-
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
|
|
4
|
+
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 c, 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";
|
|
5
5
|
const g = {
|
|
6
6
|
email: { schema: R() },
|
|
7
7
|
hostname: { schema: F() },
|
|
@@ -11,7 +11,7 @@ const g = {
|
|
|
11
11
|
uuid: { schema: S() },
|
|
12
12
|
date: { schema: d.date() },
|
|
13
13
|
time: { schema: d.time() },
|
|
14
|
-
"date-time": { schema: d.datetime() },
|
|
14
|
+
"date-time": { schema: d.datetime({ local: !0, offset: !0 }) },
|
|
15
15
|
duration: { schema: d.duration() }
|
|
16
16
|
}, K = Object.keys(g), Y = (i) => (m, e) => {
|
|
17
17
|
switch (m.type) {
|
|
@@ -33,47 +33,47 @@ const g = {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
|
-
function
|
|
36
|
+
function o(i, m) {
|
|
37
37
|
if (i !== void 0)
|
|
38
38
|
return typeof i == "string" ? i : m?.translate(i.key, i.params, i.default) ?? i.default;
|
|
39
39
|
}
|
|
40
40
|
function N(i, m) {
|
|
41
41
|
return a(i, (e) => {
|
|
42
|
-
const u =
|
|
42
|
+
const u = o(e.messages?.invalid, m);
|
|
43
43
|
let s = u ? y(u) : y();
|
|
44
44
|
if (e.required === !0) {
|
|
45
|
-
const r =
|
|
46
|
-
s = s.check(
|
|
45
|
+
const r = o(e.messages?.required, m) ?? "This field is required";
|
|
46
|
+
s = s.check(c((t) => t.length > 0, { error: r }));
|
|
47
47
|
}
|
|
48
48
|
if (typeof e.minLength == "number") {
|
|
49
|
-
const r =
|
|
49
|
+
const r = o(e.messages?.minLength, m), t = e.minLength;
|
|
50
50
|
s = s.check(
|
|
51
|
-
r ?
|
|
51
|
+
r ? c((n) => n.length >= t, { error: r }) : q(t)
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
if (typeof e.maxLength == "number") {
|
|
55
|
-
const r =
|
|
55
|
+
const r = o(e.messages?.maxLength, m), t = e.maxLength;
|
|
56
56
|
s = s.check(
|
|
57
|
-
r ?
|
|
57
|
+
r ? c((n) => n.length <= t, { error: r }) : I(t)
|
|
58
58
|
);
|
|
59
59
|
}
|
|
60
60
|
if (typeof e.pattern == "string") {
|
|
61
|
-
const r =
|
|
61
|
+
const r = o(e.messages?.pattern, m), t = new RegExp(e.pattern);
|
|
62
62
|
s = s.check(
|
|
63
|
-
r ?
|
|
63
|
+
r ? c((n) => t.test(n), { error: r }) : C(t)
|
|
64
64
|
);
|
|
65
65
|
}
|
|
66
66
|
if (e.enum) {
|
|
67
|
-
const r = e.enum, t =
|
|
68
|
-
s = s.check(
|
|
67
|
+
const r = e.enum, t = o(e.messages?.enum, m);
|
|
68
|
+
s = s.check(c((n) => r.includes(n), t ? { error: t } : void 0));
|
|
69
69
|
}
|
|
70
70
|
if (e.const !== void 0) {
|
|
71
|
-
const r =
|
|
72
|
-
s = s.check(
|
|
71
|
+
const r = o(e.messages?.const, m);
|
|
72
|
+
s = s.check(c((t) => t === e.const, r ? { error: r } : void 0));
|
|
73
73
|
}
|
|
74
74
|
if (e.format !== void 0)
|
|
75
75
|
if (K.includes(e.format)) {
|
|
76
|
-
const r =
|
|
76
|
+
const r = o(e.messages?.format, m);
|
|
77
77
|
s = s.check(
|
|
78
78
|
r ? V((t, n) => {
|
|
79
79
|
const h = b(
|
|
@@ -96,70 +96,70 @@ const D = (i, m) => {
|
|
|
96
96
|
};
|
|
97
97
|
function G(i, m) {
|
|
98
98
|
return a(i, (e) => {
|
|
99
|
-
const u =
|
|
99
|
+
const u = o(e.messages?.invalid, m);
|
|
100
100
|
let s = u ? k(u) : k();
|
|
101
101
|
if (e.type === "integer" && (s = s.check($())), e.minimum !== void 0) {
|
|
102
|
-
const r =
|
|
103
|
-
s = s.check(r ?
|
|
102
|
+
const r = o(e.messages?.minimum, m), t = e.minimum;
|
|
103
|
+
s = s.check(r ? c((n) => n >= t, { error: r }) : A(t));
|
|
104
104
|
}
|
|
105
105
|
if (e.maximum !== void 0) {
|
|
106
|
-
const r =
|
|
107
|
-
s = s.check(r ?
|
|
106
|
+
const r = o(e.messages?.maximum, m), t = e.maximum;
|
|
107
|
+
s = s.check(r ? c((n) => n <= t, { error: r }) : B(t));
|
|
108
108
|
}
|
|
109
109
|
if (e.exclusiveMinimum !== void 0) {
|
|
110
|
-
const r =
|
|
111
|
-
s = s.check(
|
|
110
|
+
const r = o(e.messages?.exclusiveMinimum, m), t = e.exclusiveMinimum;
|
|
111
|
+
s = s.check(c((n) => n > t, r ? { error: r } : void 0));
|
|
112
112
|
}
|
|
113
113
|
if (e.exclusiveMaximum !== void 0) {
|
|
114
|
-
const r =
|
|
115
|
-
s = s.check(
|
|
114
|
+
const r = o(e.messages?.exclusiveMaximum, m), t = e.exclusiveMaximum;
|
|
115
|
+
s = s.check(c((n) => n < t, r ? { error: r } : void 0));
|
|
116
116
|
}
|
|
117
117
|
if (e.multipleOf !== void 0) {
|
|
118
|
-
const r =
|
|
118
|
+
const r = o(e.messages?.multipleOf, m), t = e.multipleOf;
|
|
119
119
|
s = s.check(
|
|
120
|
-
|
|
120
|
+
c((n) => D(n, t), r ? { error: r } : void 0)
|
|
121
121
|
);
|
|
122
122
|
}
|
|
123
123
|
if (e.enum) {
|
|
124
|
-
const r = e.enum, t =
|
|
125
|
-
s = s.check(
|
|
124
|
+
const r = e.enum, t = o(e.messages?.enum, m);
|
|
125
|
+
s = s.check(c((n) => r.includes(n), t ? { error: t } : void 0));
|
|
126
126
|
}
|
|
127
127
|
if (e.const !== void 0) {
|
|
128
|
-
const r =
|
|
129
|
-
s = s.check(
|
|
128
|
+
const r = o(e.messages?.const, m);
|
|
129
|
+
s = s.check(c((t) => t === e.const, r ? { error: r } : void 0));
|
|
130
130
|
}
|
|
131
131
|
return s;
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
134
|
function H(i, m) {
|
|
135
135
|
return a(i, (e) => {
|
|
136
|
-
const u =
|
|
136
|
+
const u = o(e.messages?.invalid, m);
|
|
137
137
|
let s = u ? x(u) : x();
|
|
138
138
|
if (e.const !== void 0) {
|
|
139
|
-
const r =
|
|
140
|
-
s = s.check(
|
|
139
|
+
const r = o(e.messages?.const, m);
|
|
140
|
+
s = s.check(c((t) => t === e.const, r ? { error: r } : void 0));
|
|
141
141
|
}
|
|
142
142
|
return s;
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
145
|
function J(i, m) {
|
|
146
146
|
return a(i, (e) => {
|
|
147
|
-
const u =
|
|
147
|
+
const u = o(e.messages?.invalid, m);
|
|
148
148
|
let s = u ? l(f(), u) : l(f());
|
|
149
149
|
if (e.required === !0) {
|
|
150
|
-
const r =
|
|
151
|
-
s = s.check(
|
|
150
|
+
const r = o(e.messages?.required, m) ?? "This field is required";
|
|
151
|
+
s = s.check(c((t) => t.length > 0, { error: r }));
|
|
152
152
|
}
|
|
153
153
|
if (typeof e.minItems == "number") {
|
|
154
|
-
const r =
|
|
154
|
+
const r = o(e.messages?.minItems, m), t = e.minItems;
|
|
155
155
|
s = s.check(
|
|
156
|
-
r ?
|
|
156
|
+
r ? c((n) => n.length >= t, { error: r }) : q(t)
|
|
157
157
|
);
|
|
158
158
|
}
|
|
159
159
|
if (typeof e.maxItems == "number") {
|
|
160
|
-
const r =
|
|
160
|
+
const r = o(e.messages?.maxItems, m), t = e.maxItems;
|
|
161
161
|
s = s.check(
|
|
162
|
-
r ?
|
|
162
|
+
r ? c((n) => n.length <= t, { error: r }) : I(t)
|
|
163
163
|
);
|
|
164
164
|
}
|
|
165
165
|
return s;
|
package/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(i,d){typeof exports=="object"&&typeof module<"u"?d(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"],d):(i=typeof globalThis<"u"?globalThis:i||self,d(i["gui-validators"]={},i.core,null,i.zod,i.mini))})(this,(function(i,d,O,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 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 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 q(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 V(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"})}));
|
|
1
|
+
(function(i,d){typeof exports=="object"&&typeof module<"u"?d(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"],d):(i=typeof globalThis<"u"?globalThis:i||self,d(i["gui-validators"]={},i.core,null,i.zod,i.mini))})(this,(function(i,d,O,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({local:!0,offset:!0})},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 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 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 q(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 V(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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@golemui/gui-validators",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.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.0
|
|
26
|
+
"@golemui/core": "1.1.0"
|
|
27
27
|
},
|
|
28
28
|
"repository": {
|
|
29
29
|
"type": "git",
|