fabiospampinato / is

The definitive collection of is* functions for runtime type checking. Lodash-compatible, tree-shakable, with types.
MIT License
16 stars 2 forks source link

`isDefined` should count `null` as defined #4

Open danielbayley opened 3 months ago

danielbayley commented 3 months ago

Should isDefined not actually count null as being defined—as in be the exact opposite of isUndefined? Particularly since we already have isNil for null or undefined

fabiospampinato commented 3 months ago

isDefined is currently the opposite of isNil, as you say. The idea is that you can do arr.filter(isNil), but you can't do arr.filter(!isNil). Some libraries would allow you to do arr.filter(not(isNil)), but it may be nice to have something built-in.

Maybe the name could be changed, any suggestions?

danielbayley commented 3 months ago

Well since you can define something as null, I would say isDefined is the thing that might be unexpected here…

it may be nice to have something built-in. Maybe the name could be changed, any suggestions?

I’m good with isNil, as also a Ruby fan… I think it’s opposite could be something like isntNil—to play nice with .filter—and then have isDefined be !== undefined, the opposite of isUndefined, as mentioned. What do you think?