nn-validate
v1.2.5
Published
Validation functions.
Downloads
2
Readme
nn-validate
Common validation functions.
Usage
import { getType } from 'nn-validate';
import { isDef } from 'nn-validate';
import { isVoid } from 'nn-validate';
import { isUndefined } from 'nn-validate';
import { isNull } from 'nn-validate';
import { isBoolean } from 'nn-validate';
import { isInteger } from 'nn-validate';
import { isNumber } from 'nn-validate';
import { isInfinity } from 'nn-validate';
import { isString } from 'nn-validate';
import { isPrimitive } from 'nn-validate';
import { isArray } from 'nn-validate';
import { isObject } from 'nn-validate';
import { isObjectExArray } from 'nn-validate';
import { isDate } from 'nn-validate';
import { isDateValid } from 'nn-validate';
import { isFunction } from 'nn-validate';
import { isSymbol } from 'nn-validate';
import { isEmpty } from 'nn-validate';
import { isArrayEmpty } from 'nn-validate';
import { isObjectEmpty } from 'nn-validate';
import { isPrimitive } from 'nn-validate';
import { isPromiseLike } from 'nn-validate';
const value = 'Some value';
// Get value type.
getType( value ) // Returns "[object String]"
// Checks if value is not undefined or null.
isDef( value ) // Returns true
// Checks if value is undefined or null.
isVoid( value ) // Returns false, same as !isDef( value )
// Checks if value is undefined.
isUndefined( value ) // Returns false
// Checks if value is null.
isNull( value ) // Returns false
// Checks if value is a boolean.
isBoolean( value ) // Returns false
// Checks if value is an integer.
isInteger( value ) // Returns false
// Checks if value is an number.
isNumber( value ) // Returns false
// Checks if value is infinity or -infinity.
isInfinity( value ) // Returns false
// Checks if value is a string.
isString( value ) // Returns true
// Checks if value is an array.
isArray( value ) // Returns false
// Checks if value is an object.
isObject( value ) // Returns false
// Checks if value is an object but not an array.
isObjectExArray( [] ) // Returns false
isObjectExArray( {} ) // Returns true
// Checks if value is date.
isDate( 0 ) // Returns false
isDate( new Date( 1970, 0, 1, 0, 0, 0, 0 ) ) // Returns true
// Checks if value is valid date.
isDateValid( new Date( 'Abc' ) ) // Returns false
isDateValid( new Date( 1970, 0, 1, 0, 0, 0, 0 ) ) // Returns true
// Checks if value is function.
isFunction( value ) // Returns false
// Checks if value is a symbol.
isSymbol( Symbol() ) // Returns true
// Checks if value is empty. A value is considered empty if it is: undefined, null, empty string,
// empty array, object without any keys (e.g. {}).
isEmpty( value ) // Returns false
// Checks if value is an empty array.
isArrayEmpty( value ) // Returns false
// Checks if value is an empty object (i.e. object without any keys).
isObjectEmpty( value ) // Returns false
// Checks if value is undefined, null, boolean, number, infinity, string, or symbol.
isPrimitive( value ) // Returns true
// Checks if value is like a promise (i.e. must have 'then' and 'catch' functions).
isPromiseLike( new Promise( ( resolve, reject ) => resolve() ) ) // Returns true