mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-06-06 13:48:51 +08:00
15 lines
396 B
TypeScript
15 lines
396 B
TypeScript
export async function parse_bool<T extends boolean | null>(
|
|
value: FormDataEntryValue | null,
|
|
def: T,
|
|
): Promise<boolean | T> {
|
|
if (value === null) return def;
|
|
const nv = typeof value === "string" ? value : await value.text();
|
|
const v = nv.toLowerCase();
|
|
const n = parseInt(v);
|
|
if (isNaN(n)) {
|
|
return v === "true";
|
|
} else {
|
|
return n !== 0;
|
|
}
|
|
}
|