check-defined
Simple Javascript utility function for checking if your complex object are defined all along the path. For example:
//instead of writingif typeof a !== 'undefined' && typeof ab !== 'undefined' && typeof abc !== 'undefined' //writeif
Installation
Use npm to install
npm install check-defined
Include with node.js, browserify or webpack:
var isDefined = ;
Or you could add index.js
on your page with a <script>
tag and it will export a global isDefined
method, or define the module if you are using RequireJS.
Usage
isDefined
function takes one or two arguments. One argument version works just as your regular check for typeof === 'undefined'
. Two parameter version checks every object of the object chain for undefined.
var a = {};ab = {};; // => true; // => true; // => false
Planned features
- Add checks for
null
andNaN