3 ms·
I mean, it depends on context what “numbers” are acceptable. For an overly general solution: const allowNumbers = { all: () => true, notNaN: n => !Nu
by dragonwriter 5y ago
I mean, it depends on context what “numbers” are acceptable. For an overly general solution:
const allowNumbers = {
all: () => true,
notNaN: n => !Number.isNaN(n),
finite: Number.isFinite,
integer: Number.isInteger,
smol: n => Math.abs(n) < Number.EPSILON,
lorge: n => n > Number.MAX_SAFE_INTEGER || n < Number.MIN_SAFE_INTEGER,
}
function isNumber(n, allow = allowNumbers.all) {
return ("number" === typeof n) && allow(n);
}
- twic 5y agoThis isn't bad, but for maintainability, it should be split into at least nine packages.