Add: Optional parseInt (parseIntNull)

This commit is contained in:
2024-05-17 09:04:09 +03:00
parent 33aa98e456
commit d8b25b59dc
+9
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;
}