existjs

Check variable existence


Keywords
exist, exists, is, not, or, isObject, isNumber, isString, isArray, isFunction, isBoolean
License
MIT
Install
npm install existjs@2.1.0

Documentation

existjs

v2.1.0 ( last update: 20 mar 2018 )

Does the variable exist and what is its type? The easy way to know. Typescript included.

Install

npm

npm install existjs --save

Node.js

const { exist, or, ... } = require('existjs');

Typescript

import { exist, or, ... } from 'existjs';

Browser

<script src='/node_modules/existjs/dist/existjs-min.js'></script>
<script>
  // How to use:
  // existjs.exist();
  // existjs.or();
  // ...
</script>

exist()

Does the variable exist?

exist(null); // false
exist(undefined); // false
exist(NaN); // false
exist(0); // true
exist(''); // true
exist([]); // true
exist({}); // true
exist(false); // true
exist('hello'); // true

or()

It chooses first existing variable

var c = or(null, null, undefined, 72, 12, null, 'hi'); // c = 72
var c = or(undefined, 0, 2); // c = 0

Check types

isObject({ age: 99 }); // true
isNumber(122); // true
isString('deal with it'); // true
isArray([ 1, 2, 3 ]); // true
isFunction(function() {}); // true
isBoolean(false); // true