|
const isIntegerRegex = /^-?\d+$/u;
|
|
|
|
export function ParseStrInt(val: unknown): number | null {
|
|
if (typeof val !== "string") {
|
|
return null;
|
|
}
|
|
|
|
if (!isIntegerRegex.test(val)) {
|
|
return null;
|
|
}
|
|
|
|
const v = Number(val);
|
|
|
|
if (!Number.isSafeInteger(v)) {
|
|
return null;
|
|
}
|
|
|
|
return v;
|
|
}
|