Revert "fix: coerce"

This reverts commit fb20b2e16c.
This commit is contained in:
手瓜一十雪 committed 2025-04-19 10:53:29 +08:00
1 parent a5455e27d1
commit ceea50b116
7 files changed
+35 -40

No files matched your search

+3 -15
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 };