Re:NPM – "is-even", 160k weekly downloads
by madeofpalk on Tuesday November 16, 2021 @12:05PM
(#29243065)
Unfortunately "not a number" is typeof "number"
"number" === typeof NaN
Returns true.
Re:NPM – "is-even", 160k weekly downloads
by dragonwriter on Tuesday November 16, 2021 @01:04PM
(#29244021)
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);
}This isn't bad, but for maintainability, it should be split into at least nine packages.
Re:NPM – "is-even", 160k weekly downloads
by marshray on Tuesday November 16, 2021 @02:45PM
(#29245481)
In the type of things that Javascript considers 'numbers', it's a value used to indicate that it's not of the type of things that math considers 'numbers'.
Re:NPM – "is-even", 160k weekly downloads
by organsnyder on Tuesday November 16, 2021 @12:32PM
(#29243490)
That's a tricky one that I think would depend on use case. Yes, of course NaN isn't a number, but it's still kind of a number, depending on context.
Re:NPM – "is-even", 160k weekly downloads
by ohgodplsno on Tuesday November 16, 2021 @12:54PM
(#29243828)
NaN is a float according to IEEE754. All numbers in Javascript being floats, it makes sense that typeof NaN === "number".
Now, the fact that IEEE754 is insane is something else, but JS does nothing wrong (aside from not having not-floats)
Re:NPM – "is-even", 160k weekly downloads
by Ginden on Tuesday November 16, 2021 @01:41PM
(#29244671)
> Now, the fact that IEEE754 is insane is something else, but JS does nothing wrong (aside from not having not-floats)
JS has BigInt - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Re:NPM – "is-even", 160k weekly downloads
by ohgodplsno on Tuesday November 16, 2021 @03:10PM
(#29245793)
BigInt is relatively recent, all things considered. JS only having floats is a conception flaw.
Although maybe you meant to include
In your examples?