DEV Community

I just created my first NPM package. It ain't much but it's honest work

Ivan Spoljaric on July 24, 2020

Yesterday I learned that these NPM packages exist: https://www.npmjs.com/package/is-odd https://www.npmjs.com/package/is-even https://www.npmjs....
Collapse
 
fatardy profile image
Aradhya Alamuru

Haha I had a very similar post planned - you beat me to it!

The is-even package has a dependency - is-odd lolol

var isOdd = require('is-odd');
module.exports = function isEven(i) {
  return !isOdd(i);
};
Enter fullscreen mode Exit fullscreen mode
Collapse
 
ispoljari profile image
Ivan Spoljaric

Yeah, but that is some genius level stuff :)

Collapse
 
fatardy profile image
Aradhya Alamuru

Lol the only thing left is to get it into the react core or something

Collapse
 
nomade55 profile image
Lucas G. Terracino

I was surprised with the is-odd and is-even download amount. But you know, sometimes you just need to know wether it is or not.

Collapse
 
konradlinkowski profile image
Konrad Linkowski

Those useless packages have so many downloads, because some basic,useful package use it. And for example webpack use this useful package. So now everyone installing webpack or something that uses webpack (basically any top is framework) is counted as download.

Collapse
 
intrnl profile image
intrnl

would be more appropriate to say that webpack doesn't actually use is-odd and is-even, one of the dependencies uses it.

Collapse
 
richytong profile image
Richard Tong

I think the idea of your package is actually pretty useful. Just found something similar that has ~2k weekly downloads.

npmjs.com/package/range

My guess is it's just preference for is-odd and is-even.

Collapse
 
orkhanfarmanli profile image
Orkhan Farmanli

JS community fascinates me every passing day

Collapse
 
elleattwell profile image
Harry Balls

Well, that's odd!

Collapse
 
fasani profile image
Michael Fasani

Keeps the playing field even!

Collapse
 
coly010 profile image
Colum Ferry

Gotta check the numbers on that one

Collapse
 
raounek profile image
touibeg mohamed

thank you for your short work ...

Collapse
 
ispoljari profile image
Ivan Spoljaric

No problem. Thank you for taking the time to read my post.

Collapse
 
milan997 profile image
milan997

Why is line "num - num === 0" needed?

Collapse
 
ispoljari profile image
Ivan Spoljaric • Edited

Ambar explained it pretty well.

I think the best, and easiest way, to check if a variable is of type 'number' in JS, is to use the

Number.isFinite(num)

method.

It will weed out anything that is not a number, including NaN and Infinity.

Collapse
 
supercoww profile image
Ambar Mutha • Edited

If simply true is returned, input NaN (not a number) will also return true. It turns out typeof NaN is number. Also NaN - NaN is NaN so this expression num - num === 0 returns true only when num is a number except NaN.

Collapse
 
ispoljari profile image
Ivan Spoljaric • Edited

Yeah. And same goes for Infinity and -Infinity.