web_lib

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

schema.ts (912B)


      1 import { z } from "zod";
      2 import { parse_int } from "../numbers/index.js";
      3 import { util_rxp } from "./regex.js";
      4 
      5 export const zf_area_unit = z.union([
      6     z.literal(`ac`),
      7     z.literal(`ft2`),
      8     z.literal(`ha`),
      9     z.literal(`m2`),
     10 ]);
     11 
     12 export const zf_mass_unit = z.union([
     13     z.literal(`kg`),
     14     z.literal(`lb`),
     15     z.literal(`g`),
     16 ]);
     17 
     18 export const zf_price_amount = z.preprocess((input) => {
     19     return parse_int(String(input), 1.00);
     20 }, z.number().positive().multipleOf(0.01));
     21 
     22 export const zf_quantity_amount = z.preprocess((input) => {
     23     return parse_int(String(input), 1);
     24 }, z.number().int().positive());
     25 
     26 export const zf_price = z.number().positive().multipleOf(0.01);
     27 
     28 export const zf_numi_pos = z.number().int().positive();
     29 
     30 export const zf_numf_pos = z.number().positive();
     31 
     32 export const zf_email = z.string().email();
     33 
     34 export const zf_username = z.string().regex(util_rxp.profile_name);