valibot
valibot copied to clipboard
Are there any similarities about zod `.superRefine`?
Hi, folks!
I'm just considering to migrate validator from zod
to valibot
.
Then, I met an issue to prevent it.
zod provides superRefine
method and it is useful like the following case;
somethingSchema.superRefine((val, ctx) => {
if (!val.length) {
ctx.addIssue({
code: z.ZodIssueCode.custom
message: "not inputted"
})
}
const overLength = val.length - MAX_LENGTH
if (overLength > 0) {
ctx.addIssue({
code: z.ZodIssueCode.custom
message: `${overLength} characters exceeded from max length`
})
}
})
I guess pipeline with custom
cannot cover this use case;
string([
custom(input => !!input.length, "not inputted"),
custom(input => input.length - MAX_LENGTH <= 0, `${input.length - MAX_LENGTH} characters exceeded from max length`) // cannot get `input.length`
])
Are there any solution about this in valibot
?
We are currently rewriting Valibot. This will most likely be possible in the future. I expect a new release in about 3 or 4 weeks. You can follow the progress in #502.
We now support rawCheck
and rawTransform
. Both APIs are similar to superRefine
in Zod.