node package manager

not-defined

not-defined

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

Installation | Usage | License

KLP

Installation

npm install not-defined --save

Usage

This snippet of code

var 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

var no = require('not-defined')
 
if (no(foo)) {
  // do something, usually throw a TypeError 
}

Pros

  • Type less.
  • Better readability (even your boss will understand your code ^:).
  • Can save bytes in your builds.
  • Easier to autocomplete in editors.

Annotated source

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

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

License

MIT