Closed llermaly closed 2 years ago
That works! Really, any so-called "predicate function" (a function that takes an input and returns true
or false
) works here and validator.js just happens to be a library full of such functions.
Going to close for now, but feel free to follow-up on this issue with any questions or problems you might run into.
I think it would still be useful to clarify if the validator.js are already implemented in zod or not. Asking because I can see the TS intellisense showing something like that for zod.string()
It is very clear how any "predicate function" can be used, but it is not clear if validator.js is already implemented in zod.
it is not clear if validator.js is already implemented in zod.
Validator.js is unrelated to Zod, and is just our recommendation. Hopefully that's clear from the fact we're linking out to them rather than documenting some alternative API like you're showing in your screenshot. To be clear, this is what you'd do:
import { z } from "zod";
import validator from "validator";
const url = z.string().refine(validator.isURL);
Open to suggestion on how to make the documentation more clear.
Check out validator.js for a bunch of other useful string validation functions that can be used in conjunction with Refinements.
I think a more specific mention this is only an external library would have been more clear to me.
Check out validator.js for a bunch of other useful string validation functions that can be used in conjunction with Refinements (validator.js is an external library consisting of string validation functions which can be passed as arguments to our Refinements functions).
Thank you very much for addressing my issue so promptly and thank you for your work.
I have an application using zod but I'd like to use some methods from a different library (validator.js) zod documentation says:
Not sure if that means this functions are implemented on zod, or I have to also install validator.js, in that other case how I can use both libraries together? cant find any example.
I got this answer from stackoverflow, is this the way you refer in your docs?
Thanks!