@john-yuan/utils
v1.1.2
Published
Basic utils.
Downloads
3
Readme
Basic Utils for JavaScript
The basic utils for javascript. This library will keep the utils as small as possible. You can import the module you want to use on demand. Here is an example:
var isArray = require('@john-yuan/utils/isArray');
if (!isArray(it)) {
throw new TypeError('it is not an array');
}
Install
npm i @john-yuan/utils
Modules
API
isAbsoluteURL(url)
url
{string}- Returns: {boolean}
Check whether the url is absolute url. Returns true
if the url is abosolute, otherwise false
is returned.
isArray(it)
it
{any}- Returns: {boolean}
Check whether the variable is an instance of Array
. Returns true
if the variable is an instance of Array
, otherwise false
is returned.
isFunction(it)
it
{any}- Returns: {boolean}
Check whether the variable is a function. Returns true
if the variable is a function, otherwise false
is returned.
isPlainObject(it)
it
{any}- Returns: {boolean}
Check whether the variable is a plain object. Returns true
if the variable is a plain object, otherwise false
is returned.
merge(target, ...source)
target
{Object}source
{Object}- Returns: {Object}
Copy any non-undefined values of source to target and overwrites the corresponding original values. This function will modify the target object. Returns the modified target object.
trim(str)
str
{string}- Returns: {string}
Removes the leading and trailing white space and line terminator characters from a string. If str
is null
or undefined
, it is treated as an empty string. If str
is not a string, it will be converted to a string first. This function retruns the trimed string.