How to validate name of a function? #817
-
Hi, I would like to make sure that a variable is a function but also check that the name of the function is of a specific value. How can I do that? One solution I guess is to pipe function with custom and check in custom, but the issue is the value passed to custom is of type v.pipe(
v.function()
v.custom(fn => ...)
) Or
but I was wondering if there is a better way? |
Beta Was this translation helpful? Give feedback.
Answered by
fabian-hiller
Sep 5, 2024
Replies: 1 comment 2 replies
-
You should use import * as v from 'valibot';
const Schema = v.pipe(
v.function(),
v.check(
(func) => func.name === 'foo',
(issue) => `The name is "${issue.input.name}" instead of "foo"`,
),
); |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
fabian-hiller
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should use
check
instead ofcustom
. Try it out in our playground.