web_lib

Common web application libraries
git clone https://radroots.dev/git/web_lib.git
Log | Files | Refs | LICENSE

commit 0d62fc75ba58f3a3410dee770cdf12d32cab0ad3
parent 7fb108082fa6a85910ff3a2542eec03f3c56f576
Author: triesap <137732411+triesap@users.noreply.github.com>
Date:   Sun, 27 Apr 2025 05:30:14 +0000

utils: refactor zod validation schema fields

Diffstat:
Mutils/src/*validation.ts | 24++++++++++++------------
Mutils/src/unit.ts | 6+++---
2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/utils/src/*validation.ts b/utils/src/*validation.ts @@ -1,44 +1,44 @@ import { type GeolocationAddress, type GeolocationPoint, parse_int, util_rxp } from "$root"; import { z } from "zod"; -export const vu_area_unit = z.union([ +export const zf_area_unit = z.union([ z.literal(`ac`), z.literal(`ft2`), z.literal(`ha`), z.literal(`m2`), ]); -export const vu_mass_unit = z.union([ +export const zf_mass_unit = z.union([ z.literal(`kg`), z.literal(`lb`), z.literal(`g`), ]); -export const vs_geolocation_address: z.ZodSchema<GeolocationAddress> = z.object({ +export const schema_geolocation_address: z.ZodSchema<GeolocationAddress> = z.object({ primary: z.string().regex(util_rxp.addr_primary), admin: z.string().regex(util_rxp.addr_admin), country: z.string().regex(util_rxp.country_code_a2) }); -export const vs_geolocation_point: z.ZodSchema<GeolocationPoint> = z.object({ +export const schema_geolocation_point: z.ZodSchema<GeolocationPoint> = z.object({ lat: z.number().min(-90).max(90), lng: z.number().min(-180).max(180), }); -export const ve_price_amount = z.preprocess((input) => { +export const zf_price_amount = z.preprocess((input) => { return parse_int(String(input), 1.00); }, z.number().positive().multipleOf(0.01)); -export const ve_quantity_amount = z.preprocess((input) => { +export const zf_quantity_amount = z.preprocess((input) => { return parse_int(String(input), 1); }, z.number().int().positive()); -export const zod_numf_price = z.number().positive().multipleOf(0.01); +export const zf_price = z.number().positive().multipleOf(0.01); -export const zod_numi_pos = z.number().int().positive(); +export const zf_numi_pos = z.number().int().positive(); -export const zod_numf_pos = z.number().positive(); +export const zf_numf_pos = z.number().positive(); -export const vf_email = z.string().email(); +export const zf_email = z.string().email(); -export const vf_username = z.string().regex(util_rxp.profile_name); -\ No newline at end of file +export const zf_username = z.string().regex(util_rxp.profile_name); +\ No newline at end of file diff --git a/utils/src/unit.ts b/utils/src/unit.ts @@ -1,10 +1,10 @@ -import type { vu_area_unit, vu_mass_unit } from "$root"; +import type { zf_area_unit, zf_mass_unit } from "$root"; import { z } from "zod"; -export type AreaUnit = z.infer<typeof vu_area_unit>; +export type AreaUnit = z.infer<typeof zf_area_unit>; export const area_units: AreaUnit[] = [`ac`, `ha`, `ft2`, `m2`] as const; -export type MassUnit = z.infer<typeof vu_mass_unit>; +export type MassUnit = z.infer<typeof zf_mass_unit>; export const mass_units: MassUnit[] = [`kg`, `lb`, `g`] as const; export function parse_mass_unit_default(val?: string): MassUnit {