New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add .toLowerCase()
and .toUpperCase()
to ZodString
#2038
Conversation
✅ Deploy Preview for guileless-rolypoly-866f8a ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
This already works: console.log( z.string().parse( 'LOWERCASE' ).toLowerCase() ) // 'lowercase' So why do we need another way of doing this? |
Than why is there this: console.log(z.string().trim().parse(' trim ')) // 'trim' If you could just do this: console.log(z.string().parse(' trim ').trim()) // 'trim' |
Personally, I don't know why we need the trim method, because like you said, we can just do this: console.log(z.string().parse(' trim ').trim()) // 'trim' But ultimately, it's not my call weather or not things like this make it in. I'm just trying to ask for your reasoning about why we need |
Obviously you are right but I know it's not ideal but imagine something like this: const UserSchema = z.object({
name: z.string().trim().lowerCase(),
email: z.string().trim().lowerCase().email(),
)}
const User = UserSchema.parse(userData)
// or
const User = {
name: userData.name.trim().toLowerCase(),
email: userData.email.trim().toLowerCase(),
} With zod you could reuse the Schema and don't have to pay attention to things like |
There's value in only needing to declare this transform once, instead of per-parse. I reluctantly added |
.toLowerCase()
and .toUpperCase()
to ZodString
This adds
lowerCase()
toZodString
.