colinhacks / zod

TypeScript-first schema validation with static type inference
https://zod.dev
MIT License
33.95k stars 1.19k forks source link

feat: z.string.cidr() - support CIDR notation #3820

Open wataryooou opened 2 weeks ago

wataryooou commented 2 weeks ago

This PR supported CIDR notation. (This PR doesn't support IP address range.) FYI: https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing

const cidr = z.string().cidr();
cidr.parse("192.168.0.0/24"); // pass
cidr.parse("2001:db8::/32"); // pass
cidr.parse("192.168.1.1/33"); // fail
cidr.parse("2001:db8::1/129"); // fail
netlify[bot] commented 2 weeks ago

Deploy Preview for guileless-rolypoly-866f8a ready!

Built without sensitive environment variables

Name Link
Latest commit 7aaa27046ce2957f0c2388d6a5e7514edc907ccb
Latest deploy log https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/6730bbf6c7c2c800083212cc
Deploy Preview https://deploy-preview-3820--guileless-rolypoly-866f8a.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

colinhacks commented 6 days ago

Is there are argument for making this z.string().cidr()?

wataryooou commented 2 days ago

@colinhacks

Is there are argument for making this z.string().cidr()?

That's a great idea 👍 I've made the changes accordingly. Could you review it once more?