Add: Optional parseInt (parseIntNull)

This commit is contained in:
Donatas Kirda 2024-05-17 09:04:09 +03:00
parent 33aa98e456
commit d8b25b59dc
Signed by: bloodwiing
GPG Key ID: 63020D8D3F4A164F

View File

@ -29,3 +29,12 @@ export function gotoNamedId(id, name) {
const page = getNamedId(id, name);
goto(page, { replaceState: true });
}
/**
* @param {string | null | undefined} string
* @returns {number | null}
*/
export function parseIntNull(string) {
const r = string ? parseInt(string) : null;
return Number.isNaN(r) ? null : r;
}