Is
A JavaScript library for checking the type of a value for browsers.
Installing
npm i @lvchengbin/is --save
Usage
Generally, when we are using some toolkit such as rollup, we don't want to compile a huge library into our project, therefore, to import the files you really need.
import isFunction from '@lvchengbin/is/src/function';
import array from '@lvchengbin/is/src/array';
isFunction( async () => {} );
isArray( [] );
If you want to invoke the whole package:
import is from '@lvchengbin/is';
is.function( () => {} );
is.array( [] );
Using in browsers
If you want to invoke this package to browsers with <script>
tag or something like that, use is.js. For old browsers which are not supporting ES5 syntax, use is.bc.js.
Method List
Method | Importing |
---|
is.arguments | import isArguments from '@lvchengbin/is/src/arguments' |
is.array | import isArray from '@lvchengbin/is/src/array' |
is.arrowFunction | import isArrowFunction from '@lvchengbin/is/src/arrow-function' |
is.asyncFunction | import isAsyncFunction from '@lvchengbin/is/src/async-function' |
is.boolean | import isBoolean from '@lvchengbin/is/src/boolean' |
is.class | import isClass from '@lvchengbin/is/src/class' |
is.date | import isDate from '@lvchengbin/is/src/date' |
is.elementNode | import isElementNode from '@lvchengbin/is/src/element-node' |
is.email | import isEmail from '@lvchengbin/is/src/email' |
is.empty | import isEmpty from '@lvchengbin/is/src/empty' |
is.error | import isError from '@lvchengbin/is/src/error' |
is.false | import isFalse from '@lvchengbin/is/src/false' |
is.fragmentNode | import isFragmentNode from '@lvchengbin/is/src/fragment-node' |
is.function | import isFunction from '@lvchengbin/is/src/function' |
is.generator | import isGenerator from '@lvchengbin/is/src/generator' |
is.integer | import isInteger from '@lvchengbin/is/src/integer' |
is.ip | import isIP from '@lvchengbin/is/src/ip' |
is.ipv4 | import isIPv4 from '@lvchengbin/is/src/ipv4' |
is.ipv6 | import isIPv6 from '@lvchengbin/is/src/ipv6' |
is.iterable | import isIterable from '@lvchengbin/is/src/iterable' |
is.leapYear | import isLeapYear from '@lvchengbin/is/src/leap-year' |
is.map | import isMap from '@lvchengbin/is/src/map' |
is.node | import isNode from '@lvchengbin/is/src/node' |
is.number | import isNumber from '@lvchengbin/is/src/number' |
is.object | import isObject from '@lvchengbin/is/src/object' |
is.oneDimensionalArray | import isOneDimensionalArray from '@lvchengbin/is/src/one-dimensional-array' |
is.plainObject | import isPlainObject from '@lvchengbin/is/src/plain-object' |
is.promise | import isPromise from '@lvchengbin/is/src/promise' |
is.regexp | import isRegexp from '@lvchengbin/is/src/regexp' |
is.set | import isSet from '@lvchengbin/is/src/set' |
is.string | import isString from '@lvchengbin/is/src/string' |
is.true | import isTrue from '@lvchengbin/is/src/true' |
is.undefined | import isUndefined from '@lvchengbin/is/src/undefined' |
is.url | import isUrl from '@lvchengbin/is/src/url' |
is.textNode | import isTextNode from '@lvchengbin/is/src/text-node' |
is.window | import isWindow from '@lvchengbin/is/src/window' |
is.date
For checking if an object is a Date
instance.
import isDate from '@lvchengbin/is/src/date';
isDate( new Date );
is.empty
an empty value could be am empty object({}
), an empty string, an empty array([]
), a number 0
or a false
|
For checking if a value is empty, and empty values include empty object ({}), empty string (''), empty array ([]), number 0, false.
import isEmpty from '@lvchengbin/is/src/empty';
isEmpty( '' );
isEmpty( [] );
isEmpty( {} );
isEmpty( 0 );
isEmpty( false );
is.false
For checking if a value is false
, if the second argument is true
(by default), the function will check a generalized false
, it means that the following strings all mean false
: "false", "no", "0", "", "nay", "n", "disagree".
import isFalse from '@lvchengbin/is/src/false';
isFalse( false );
isFalse( 'false' );
isFalse( 'false', false );
is.true
For checking if a value is true
, if the second argument is true
(by default), the function will check a generalized true
, it means that the following strings all mean true
: "true", "true", "yes", "ok", "1", "yea", "yep", "y", "agree".
import isTrue from '@lvchengbin/is/src/true';
isTrue( true );
isTrue( 'true' );
isTrue( 'true', false );