Skip to content

Commit 62cae59

Browse files
committed
feat: add validator combinators for forms
1 parent ca7d5fc commit 62cae59

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

lua/nui-components/validators.lua

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,42 @@ function M.compose(...)
4040
end
4141
end
4242

43+
function M.none(...)
44+
local validators = { ... }
45+
return function(value)
46+
for _, fn in ipairs(validators) do
47+
if fn(value) then
48+
return false
49+
end
50+
end
51+
return true
52+
end
53+
end
54+
55+
function M.any(...)
56+
local validators = { ... }
57+
return function(value)
58+
for _, fn in ipairs(validators) do
59+
if fn(value) then
60+
return true
61+
end
62+
end
63+
return false
64+
end
65+
end
66+
67+
function M.all(...)
68+
local validators = { ... }
69+
70+
return function(value)
71+
for _, fn in ipairs(validators) do
72+
if not fn(value) then
73+
return false
74+
end
75+
end
76+
77+
return true
78+
end
79+
end
80+
4381
return M

0 commit comments

Comments
 (0)