colinhacks / zod

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

[feat] `z.number().latitude()` and `z.number().longitude()` #2600

Open hudson-bruno opened 1 year ago

hudson-bruno commented 1 year ago

Latitude and longitude are used in a variety of applications, it feels like this simple validation is missing, currently is possible to validate chaining min and max but it would be better if this validation was abstracted away.

const latitude = z.number().min(-90).max(90)
const longitude = z.number().min(-180).max(180)

// Proposed
const latitude = z.number().latitude()
const longitude = z.number().longitude()
csulit commented 5 months ago

I hope this gets shipped soon.