fix: coerce
Build Release / check-version (push) Canceled after 0s
Build Release / Build-LiteLoader (push) Canceled after 0s
Build Release / Build-Shell (push) Canceled after 0s
Build Release / release-napcat (push) Canceled after 0s
Build Action / Build-LiteLoader (push) Canceled after 0s
Build Action / Build-Shell (push) Canceled after 0s

This commit is contained in:
手瓜一十雪 committed 2025-04-17 22:17:35 +08:00
1 parent 9df7c341a9
commit fb20b2e16c
7 files changed
+40 -35

No files matched your search

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