Revert "fix: coerce"

This reverts commit 0f508a511c.
This commit is contained in:
手瓜一十雪
2025-04-19 10:53:29 +08:00
parent d36c5b98a5
commit ef59181dcd
7 changed files with 35 additions and 40 deletions

View File

@@ -1,26 +1,14 @@
import { z } from 'zod';
const boolean = () => z.preprocess(
val => val === null || val === undefined
? val
: typeof val === 'string' && (val.toLowerCase() === 'false' || val === '0')
? false
: Boolean(val),
val => typeof val === 'string' && (val.toLowerCase() === 'false' || val === '0') ? false : Boolean(val),
z.boolean()
);
const number = () => z.preprocess(
val => val === null || val === undefined
? val
: typeof val !== 'number' ? Number(val) : val,
val => typeof val !== 'number' ? Number(val) : val,
z.number()
);
const string = () => z.preprocess(
val => val === null || val === undefined
? val
: typeof val !== 'string' ? String(val) : val,
val => typeof val !== 'string' ? String(val) : val,
z.string()
);
export const coerce = { boolean, number, string };