mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-07-08 01:31:00 +08:00
Better handle bigint
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { isNumNaN, parseBigInt } from "../utils.ts";
|
||||
|
||||
export async function get_string(value: FormDataEntryValue | null) {
|
||||
if (value === null) return null;
|
||||
return typeof value === "string" ? value : await value.text();
|
||||
@@ -28,3 +30,14 @@ export async function parse_int<T extends number | null>(
|
||||
if (isNaN(n)) return def;
|
||||
return n;
|
||||
}
|
||||
|
||||
export async function parse_big_int<T extends number | bigint | null>(
|
||||
value: FormDataEntryValue | null,
|
||||
def: T,
|
||||
): Promise<number | bigint | T> {
|
||||
if (value === null) return def;
|
||||
const v = typeof value === "string" ? value : await value.text();
|
||||
const n = parseBigInt(v);
|
||||
if (isNumNaN(n)) return def;
|
||||
return n;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user