Javascript helper functions
npm install hlprHelperJS is a collection of javascript functions and utilities to help developers code faster, bigger and better apps. It does not have dependencies, it is written entirely in vanilla javascript, so it will not install unnecessary packages and libraries increasing your project's bundle size.
npm install hlpr
or
yarn add hlpr
```
const hlpr = require('hlpr');
console.log(hlpr.isArray([1,2,3])); // true
or
``
import { isArray } from 'hlpr';
console.log(isArray([1,2,3])); // true
It determines if the given value is an array.
isArray(val, strictMode)
| Parameter | Description |
|------------|---------------------------------------------------------------------------------------------------|
| val | Required. The value to be tested. |
| strictMode | Optional. Defaults to true. Validation strategy, it determines if an empty array is valid or not. |
It determines if the given value is one of the following: true|false|0|1.
isBinary(val)
| Parameter | Description |
|-----------|-----------------------------------|
| val | Required. The value to be tested. |
It determines if the given value is boolean.
isBoolean(val)
| Parameter | Description |
|-----------|-----------------------------------|
| val | Required. The value to be tested. |
It determines if the given value is a date.
isDate(val)
| Parameter | Description |
|-----------|-----------------------------------|
| val | Required. The value to be tested. |
It determines if the given value is decimal or float.
isDecimal(val)
| Parameter | Description |
|-----------|-----------------------------------|
| val | Required. The value to be tested. |
It determines if the given value is an email.
isEmail(val)
| Parameter | Description |
|-----------|-----------------------------------|
| val | Required. The value to be tested. |
It determines if the given value is an empty/blank string.
isEmpty(val)
| Parameter | Description |
|-----------|-----------------------------------|
| val | Required. The value to be tested. |
It determines if the given value is an even number.
isEven(val)
| Parameter | Description |
|-----------|-----------------------------------|
| val | Required. The value to be tested. |
It determines if the given value is FALSE.
isFalse(val)
| Parameter | Description |
|-----------|-----------------------------------|
| val | Required. The value to be tested. |
It determines if the given value is a function.
isFunction(val)
| Parameter | Description |
|-----------|-----------------------------------|
| val | Required. The value to be tested. |
It determines if the given value is integer.
isInteger(val)
| Parameter | Description |
|-----------|-----------------------------------|
| val | Required. The value to be tested. |
It determines if the given value is a valid JSON.
isJson(val, strictMode)
| Parameter | Description |
|------------------|---------------------------------------------------------------------------------------------------------|
| val | Required. The value to be tested. |
| strictMode | Optional. Defaults to true. Validation strategy, it determines if an empty JSON object is valid or not. |
It determines if the given value is NULL.
isNull(val)
| Parameter | Description |
|-----------|-----------------------------------|
| val | Required. The value to be tested. |
It determines if the given value is numeric.
isNumber(val, strictMode)
| Parameter | Description |
|------------|--------------------------------------------------------------------------------------------------------|
| val | Required. The value to be tested. |
| strictMode | Optional. Defaults to true. Validation strategy, it determines if numbers as strings are valid or not. |
It determines if the given value is an object. It will return false for Array and Date.
isObject(val, strictMode)
| Parameter | Description |
|------------|----------------------------------------------------------------------------------------------------|
| val | Required. The value to be tested. |
| strictMode | Optional. Defaults to true. Validation strategy, it determines if an empty object is valid or not. |
It determines if the given value is an odd number.
isOdd(val)
| Parameter | Description |
|-----------|-----------------------------------|
| val | Required. The value to be tested. |
It determines if the given value has been set/declare as a string, number, date, array, object, etc.
isSet(val)
| Parameter | Description |
|-----------|-----------------------------------|
| val | Required. The value to be tested. |
It determines if the given value is a valid format social security number. 000-00-0000.
isSsn(val)
| Parameter | Description |
|-----------|-----------------------------------|
| val | Required. The value to be tested. |
It determines if the given value is a string.
isString(val, strictMode)
| Parameter | Description |
|------------------|----------------------------------------------------------------------------------------------------|
| val | Required. The value to be tested. |
| strictMode | Optional. Defaults to true. Validation strategy, it determines if an empty string is valid or not. |
It determines if the given value is TRUE.
isTrue(val)
| Parameter | Description |
|-----------|-----------------------------------|
| val | Required. The value to be tested. |
It returns the data type of the given value, number, string, array, etc.
isType(val)
| Parameter | Description |
|-----------|-----------------------------------|
| val | Required. The value to be tested. |
It determines if the given value UNDEFINED.
isUndefined(val)
| Parameter | Description |
|-----------|-----------------------------------|
| val | Required. The value to be tested. |
It sorts arrays ascendingly.
- [1,3,4,2].sort(ascending) // [1,2,3,4]
- ['c','d','a','b'].sort(ascending) // ['a','b','c','d']
It also sorts array of objects, but it requires the property name to be sorted by.
[{p:3}, {p:1}, {p:2}].sort(ascending('p')) // [{p:1}, {p:2}, {p:3}]
It sorts arrays descendingly.
- [1,3,4,2].sort(descending) // [4,3,2,1]
- ['c','d','a','b'].sort(descending) // ['d','c','b','a']
It also sorts array of objects, but it requires the property name to be sorted by.
[{p:3}, {p:1}, {p:2}].sort(ascending('p')) // [{p:3}, {p:2}, {p:1}]`