not-defined

is a shortcut to (typeof foo === 'undefined') || (foo === null)

Installation | Usage | Annotated source | License

KLP

Installation

npm install not-defined --save

Usage

This snippet of code

const notDefined = require('not-defined')

if (notDefined(foo)) {
  // do something, usually throw a TypeError
}

is equivalent to

if ((typeof foo === 'undefined') || (foo === null)) {
  // do something, usually throw a TypeError
}

You can also use a shorter but still semantic form like

const no = require('not-defined')

if (no(foo)) {
  // do something, usually throw a TypeError
}

Pros

Annotated source

This is my first npm package written using KISS Literate Programming. It is a very basic, plain ES5 function that is 69 characters long

module.exports=function(x){return typeof x==='undefined'||x === null}

License

MIT