News for hackers. Stuff that matters.
Re:NPM – "is-even", 160k weekly downloads by jazzyjackson on Tuesday November 16, 2021 @11:42AM (#29242684)
Also a check for Infinity (Infinity - Infinity -> NaN)

Which is weird since they use the isFinite built-in right after that, but I have no idea why they throw in all the string checks and trims and + for type coercion, and then use the global isFinite function which does all that internally. In fact the global function isFinite does everything this package does

(something I just learned tho checking this code out is that there is a global isNaN and isFinite which coerce strings into numbers automatically, and Number.isNaN and Number.isFinite which function similarly but without coercing the string first, so I guess this package exists as a learning aide of all the different ways to ask if something is a number)

EDIT: I now know why they check if a string input is not an empty string, because empty strings get coerced to 0, so isFinite("") returns true.

Re:NPM – "is-even", 160k weekly downloads by rezonant on Tuesday November 16, 2021 @10:16PM (#29248967)
> EDIT: I now know why they check if a string input is not an empty string, because empty strings get coerced to 0, so isFinite("") returns true.

Yes, when coerced with +:

    Number.isFinite(+'') // true
    Number.isFinite('') // false
Re:NPM – "is-even", 160k weekly downloads by jazzyjackson on Wednesday November 17, 2021 @02:51AM (#29250187)
Number.isFinite('') and Number.isNaN('') returns false, isFinite('') and isNaN('') returns true, the global versions of isFinite and isNaN first coerce their input to number, no '+' necessary.

Hence the heading "Confusing Special Case Behavior" in the mdn docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Re:NPM – "is-even", 160k weekly downloads by rezonant on Wednesday November 17, 2021 @01:05PM (#29256534)
Oh yes the global versions.