Open this example in the interactive library
Source code
const parse = (text) =>
/^[+-]?\d+$/.test(text) && Number.isSafeInteger(Number(text))
? Number(text)
: null;
console.log(["-12", "12px", "9007199254740993"].map(parse));
Sample output
[ -12, null, null ]
