emnida
v2.0.1
Published
This library will using for the check to some type on the javascript.
Downloads
212
Maintainers
Readme
emnida
The emnida library will be used when the check a data type or compare an any value
Install
npm i emnida
Support Platforms
IE9 later, All modern browsers(Chrome, Safari, Edge ...), NodeJS(10.0.0
version later).
How to Use
Type check apis
These features will be use to check data type
import {
isString,
isArray,
isBigInt,
isBoolean,
isDate,
isFunction,
isMap,
isNull,
isNumber,
isPlainObject,
isRegExp,
isSet,
isSymbol,
isUndefined,
isWeakMap,
isWeakSet,
isObject,
isJSONPlainObjectString,
isJSONArrayString,
isJSONObjectString,
} from 'emnida';
isString('test'); // true
isNumber(1); // true
isBoolean(true); // true
isNull(null); // true
isUndefined(undefined); // true
isSymbol(Symbol(1)); // true
isBigInt(10n); // true
isPlainObject({}); // true
isArray([]); // true
isFunction(() => {}); // true
isMap(new Map()); // true
isWeakMap(new WeakMap()); // true
isSet(new Set())); // true
isWeakSet(new WeakSet()); // true
isDate(new Date()); // true
isRegExp(new RegExp('\\s+')); // true
isObject([]); // true
isJSONPlainObjectString('{ "x": "1", "y": 1, "z": true, "xx": null, "yy": {}, "zz": [] }'); // true
isJSONArrayString('["1", 1, true, null, {}, []]'); // true
isJSONObjectString('{ "x": "1", "y": 1, "z": true, "xx": null, "yy": {}, "zz": [] }'); // true
isJSONObjectString('["1", 1, true, null, {}, []]'); // true
Special Type check apis
These features will be use in special cases like the DOM element or empty value check
import { isArrayLikeObject, isElement, isEmpty, isIterableObject, isPrimitive } from 'emnida';
isPrimitive('test'); // true
isPrimitive(1); // true
isPrimitive(true); // true
isPrimitive(null); // true
isPrimitive(undefined); // true
isPrimitive(Symbol(1)); // true
isPrimitive(10n); // true
isElement(document.documentElement); // true
isArrayLikeObject('test'); // true
isEmpty(null); // true
isIterableObject([]); // true
Number Type check apis
These features will be evaluates an arguments in the various cases of number type
import {
isInteger,
isZero,
isLessOrEqual,
isGreaterOrEqual,
isGreater,
isNaN,
isInfinite,
isFinite,
isFloat,
isLess,
} from 'emnida';
isInteger(1); // true
isInteger(0.1); // false
isZero(0) // true
isLess(1, 10); // true
isLess(10, 1); // false
isLessOrEqual(10, 10); // true
isLessOrEqual(10, 12); // true
isGreater(10, 1); // true
isGreater(1, 10); // false
isGreaterOrEqual(10, 10); // true
isGreaterOrEqual(12, 10); // true
isNaN(0 / 0); // true
isInfinite(Infinity); // true
isFinite(Infinity); // false
isFloat(0.1); // true
isFloat(1); // false
isEqual
This feature will be use to compare two arguments like the code follows
import { isEqual } from 'emnida';
// Primitive type examples
isEqual('1', '1'); // true
isEqual(2, 2); // true
isEqual(true, true); // true
isEqual(undefined, null); // false
isEqual(null, ''); // false
isEqual(Symbol(3), Symbol(3)); // false
// Object type examples
isEqual({ x: 2, y: 1 }, { y: 1, x: 2 }); // true
isEqual({ x: 2, y: 1 }, { x: 2, y: 1 }); // true
isEqual([1, 3, 4, 5], [1, 3, 4, 5]); // true
isEqual([1, { xx: 1 }, 4, 5], [1, { yy: 1 }, 4, 5]); // false
isEqual([1, { xx: 1 }, 4, 5], [1, { xx: 1 }, 4, 5, '7']); // false
isEqual([1, 3, 4, () => {}], [1, 3, 4, () => {}, { x: 2 }]); // false
isEqual(
function() {
console.log(2);
},
function() {
console.log(2);
}
); // false
isEqual(
() => {
console.log(1);
},
() => {
console.log(1);
}
); // false
// Constructor type examples
isEqual(new String(1), new String(1)); // true
isEqual(new Number(1), new Number(1)); // true
isEqual(new Boolean(true), new Boolean(true)); // true
isEqual(new Function('1)'), new Function('3333)')); // false
isEqual(new RegExp('\\d+'), new RegExp('[a-z]+')); // false
isEqual(new RegExp('\\s+'), new RegExp('\\s*')); // false
// MAP type examples
const map1 = new Map();
map1.set('x', 1);
map1.set('y', 2);
const map2 = new Map();
map2.set('x', 1);
map2.set('y', 2);
const map3 = new Map();
map3.set('x', 1);
map3.set('y', 2);
map3.set('z', 3);
isEqual(new Map(), new Map()); // true
isEqual(map1, map2); // true
isEqual(map1, map3); // false
isEqual(map2, map3); // false
// SET type examples
const set1 = new Set();
set1.add(1);
set1.add(2);
const set2 = new Set();
set2.add(1);
set2.add(2);
const set3 = new Set();
set3.add(1);
set3.add(2);
set3.add(33);
isEqual(set1, set2); // true
isEqual(set1, set3); // false
isEqualAtStringFunction or isEqualAtStringSymbol
Below code will be evaluated to a false
by the javascript mechanism, but you may will be able to turn to a true
via use these features to use.
import { isEqual, isEqualAtStringFunction, isEqualAtStringSymbol } from 'emnida';
isEqual(() => {}, () => {}); // false
isEqual(Symbol(3), Symbol(3)); // false
isEqualAtStringFunction(() => {}, () => {}); // true
isEqualAtStringSymbol(Symbol(3), Symbol(3)); // true
Functions
isString(value) ⇒ boolean
This function evaluates whether an arguments is string type
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isString('test'); // true
isNumber(value) ⇒ boolean
This function evaluates whether an arguments is number type
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isNumber(1); // true
isBoolean(value) ⇒ boolean
This function evaluates whether an arguments is boolean type
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isBoolean(true); // true
isUndefined(value) ⇒ boolean
This function evaluates whether an arguments is undefined
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isUndefined(undefined); // true
isDefined(value) ⇒ boolean
This function evaluates whether an arguments is defined
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isDefined(undefined); // false
isNull(value) ⇒ boolean
This function evaluates whether an arguments is null
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isNull(null); // true
isSymbol(value) ⇒ boolean
This function evaluates whether an arguments is symbol type
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isSymbol(Symbol(1)); // true
isBigInt(value) ⇒ boolean
This function evaluates whether an arguments is bigint type
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isBigInt(10n); // true
isFunction(value) ⇒ boolean
This function evaluates whether an arguments is function type
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isFunction(function(){}); // true
isObject(value) ⇒ boolean
This function evaluates whether an arguments is object type
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isObject(null); // true
isObjectNotIncludeNull(value) ⇒ boolean
This function evaluates whether an arguments is object type not included null
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isObject(null); // false
isPlainObject(value) ⇒ boolean
This function evaluates whether an arguments is plain object
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isPlainObject({}); // true
isArray(value) ⇒ boolean
This function evaluates whether an arguments is array type
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isArray([]); // true
isRegExp(value) ⇒ boolean
This function evaluates whether an arguments is regex
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isRegExp(new RegExp('\s+')); // true
isElement(value) ⇒ boolean
This function evaluates whether an arguments is element
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isElement(document.documentElement); // true
isDate(value) ⇒ boolean
This function evaluates whether an arguments is date
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isDate(new Date()); // true
isArrayLikeObject(value) ⇒ boolean
This function evaluates whether an arguments is array like object
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isArrayLikeObject([]); // true
isIterableObject(value) ⇒ boolean
This function evaluates whether an arguments is iterable object
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isIterableObject([]); // true
isMap(value) ⇒ boolean
This function evaluates whether an arguments is Map
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isMap(new Map()); // true
isSet(value) ⇒ boolean
This function evaluates whether an arguments is Set
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isSet(new Set()); // true
isWeakMap(value) ⇒ boolean
This function evaluates whether an arguments is WeakMap
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isWeakMap(new WeakMap()); // true
isWeakSet(value) ⇒ boolean
This function evaluates whether an arguments is WeakSet
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isWeakSet(new WeakSet()); // true
isPrimitive(value) ⇒ boolean
This function evaluates whether an arguments is primitive type
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isPrimitive('test'); // true
isEmpty(value) ⇒ boolean
This function evaluates whether an arguments is empty
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isEmpty(1); // true
isJSONPlainObjectString(value) ⇒ boolean
This function evaluates whether an arguments is json plain object string
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isJSONPlainObjectString('{ "x": 1 }'); // true
isJSONArrayString(value) ⇒ boolean
This function evaluates whether an arguments is json array string
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isJSONArrayString('[1]'); // true
isJSONObjectString(value) ⇒ boolean
This function evaluates whether an arguments is json plain object string or json array string
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isJSONObjectString('{ "x": 1 }'); // true
isFloat(value) ⇒ boolean
This function evaluates whether an arguments is floating point number
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isFloat(1.1); // true
isFinite(value) ⇒ boolean
This function evaluates whether an arguments is finite number
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isFinite(1); // true
isInfinite(value) ⇒ boolean
This function evaluates whether an arguments is infinite number
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isInfinite(null); // true
isNaN(value) ⇒ boolean
This function evaluates whether an arguments is not a number
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isNaN(NaN); // true
isGreater(value, comparisonValue) ⇒ boolean
This function evaluates whether first argument is greater
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value which will be compared | | comparisonValue | * | An any value which will be compared |
Example
isGreater(10, 1); // true
isGreaterOrEqual(value, comparisonValue) ⇒ boolean
This function evaluates whether first argument is greater or equal
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value which will be compared | | comparisonValue | * | An any value which will be compared |
Example
isGreaterOrEqual(10, 10); // true
isLess(value, comparisonValue) ⇒ boolean
This function evaluates whether first argument is less
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value which will be compared | | comparisonValue | * | An any value which will be compared |
Example
isLess(1, 10); // true
isLessOrEqual(value, comparisonValue) ⇒ boolean
This function evaluates whether first argument is less or equal
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value which will be compared | | comparisonValue | * | An any value which will be compared |
Example
isLessOrEqual(10, 10); // true
isZero(value) ⇒ boolean
This function evaluates whether an arguments is zero
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isZero(0); // true
isInteger(value) ⇒ boolean
This function evaluates whether an arguments is integer
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value |
Example
isInteger(1); // true
isEqual(value, comparisonValue) ⇒ boolean
This function evaluates whether equal first argument and second argument
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | * | An any value which will be compared | | comparisonValue | * | An any value which will be compared |
Example
isEqual(1, 1); // true
isEqualAtStringFunction(value, comparisonValue) ⇒ boolean
This function evaluates whether equal first function and second function casted as string
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | function | A function which will be compared | | comparisonValue | function | A function which will be compared |
Example
isEqualAtStringFunction(function() {}, function() {}); // true
isEqualAtStringSymbol(value, comparisonValue) ⇒ boolean
This function evaluates whether equal first symbol and second symbol casted as string
Kind: global function
| Param | Type | Description | | --- | --- | --- | | value | Symbol | A symbol which will be compared | | comparisonValue | Symbol | A symbol which will be compared |
Example
isEqualAtStringSymbol(Symbol(1), Symbol(1)); // true