A simple, basic, and robust set of utilities for javascript - inspired by, but not copied from, lodash.
$ npm i -S isdo
const { is } = require('isdo');
let foo;
is.defined(foo); // => false
is.missing(foo); // => true
foo = null;
is.defined(foo) // => true
is.missing(foo) // => true
const arry = [];
is.array(arry); // => true
is.empty(arry); // => true
arry.push(1);
is.empty(arry); // => false
You can add your own useful comparisons and checks by using is.extend.
type comparisons
- .array
- .boolean
- .float
- .function
- .integer
- .iterable
- .map
- .null
- .number
- .object
- .set
- .string
- .undefined
presence checks
quality checks
truthy/falsey checks
extending with custom methods
presence checks
truthy/falsey checks
presence checks
truthy/falsey checks
Returns
true
if target is an array, otherwise false
.
Returns
true
if target is a boolean, otherwise false
.
Returns
true
if target is a float, otherwise false
.
Returns
true
if target is a function, otherwise false
.
Returns
true
if target is an integer, otherwise false
.
Returns
true
if target conforms to the iterable protocol, otherwise false
.
Returns
true
if target is a map, otherwise false
.
Returns
true
if target is a number (integer or float), otherwise false
.
Returns
true
if target is a plain object, otherwise false
.
Returns
true
if target is a set, otherwise false
.
Returns
true
if target is a string, otherwise false
.
Returns
true
if target is NOT undefined, otherwise false
.
Returns
true
if target is either undefined or null, otherwise false
.
Returns
true
if target is anything other than null, even undefined, otherwise false
.
Returns
true
if target is both defined and not null, otherwise false
.
Returns
true
if target string is missing or has length < 1, otherwise false
.
Returns
true
if target's length < 1, otherwise false
.
If target is an array or string, length = target.length, if target is a map or set, length = target.size, if target is an object, length = number of keys in target, otherwise length = 0.
Returns
true
if target is a string and is one of ["t", "true", "1"]
, or if target is a number and is > 0, or if target is a boolean and is true
, otherwise returns false
.
Ignores capitalization.
Returns
true
if target is a string and is one of ["f", "false", "0"]
, or if target is a number and is <= 0, or if target is a boolean and is false
, otherwise returns false
.
Ignores capitalization.
Transfers functions and nested functions from source to is
.
Example
const moment = require('moment');
const isdo = require('is');
const is = isdo.is.extend({
date: obj => moment.isDate(obj),
});
is.date('foo'); // => false
is.date(new Date()); // => true
Returns
true
if all targets are defined, otherwise false
.
Returns
true
if all targets are undefined, otherwise false
.
Returns
true
if all targets are neither null nor undefined, otherwise false
.
Returns
true
if all targets are null or undefined, otherwise false
.
Returns
true
if all targets are truthy, otherwise false
.
Returns
true
if all targets are falsey, otherwise false
.
Returns
true
if at least one of targets are defined, otherwise false
.
Returns
true
if at least one of targets are undefined, otherwise false
.
Returns
true
if at least one of targets are neither null nor undefined, otherwise false
.
Returns
true
if at least one of targets are null or undefined, otherwise false
.
Returns
true
if at least one of targets are truthy, otherwise false
.
Returns
true
if at least one of targets are falsey, otherwise false
.
-
is
module for common comparisons and checks i/e undefined, null, object, etc -
do
module for common functions i/e merge, get, etc - Get feedback and iterate