1.0.19 • Published 2 years ago

hlpr v1.0.19

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

HelperJS 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.

Installation

npm install hlpr

or

yarn add hlpr

Import or Require

const hlpr = require('hlpr');
console.log(hlpr.isArray([1,2,3])); // true

or

import { isArray } from 'hlpr';
console.log(isArray([1,2,3])); // true

Validation Functions

isArray

It determines if the given value is an array.

isArray(val, strictMode)

ParameterDescription
valRequired. The value to be tested.
strictModeOptional. Defaults to true. Validation strategy, it determines if an empty array is valid or not.

isBinary

It determines if the given value is one of the following: true|false|0|1.

isBinary(val)

ParameterDescription
valRequired. The value to be tested.

isBoolean

It determines if the given value is boolean.

isBoolean(val)

ParameterDescription
valRequired. The value to be tested.

isDate

It determines if the given value is a date.

isDate(val)

ParameterDescription
valRequired. The value to be tested.

isDecimal

It determines if the given value is decimal or float.

isDecimal(val)

ParameterDescription
valRequired. The value to be tested.

isEmail

It determines if the given value is an email.

isEmail(val)

ParameterDescription
valRequired. The value to be tested.

isEmpty

It determines if the given value is an empty/blank string.

isEmpty(val)

ParameterDescription
valRequired. The value to be tested.

isEven

It determines if the given value is an even number.

isEven(val)

ParameterDescription
valRequired. The value to be tested.

isFalse

It determines if the given value is FALSE.

isFalse(val)

ParameterDescription
valRequired. The value to be tested.

isFunction

It determines if the given value is a function.

isFunction(val)

ParameterDescription
valRequired. The value to be tested.

isInteger

It determines if the given value is integer.

isInteger(val)

ParameterDescription
valRequired. The value to be tested.

isJson

It determines if the given value is a valid JSON.

isJson(val, strictMode)

ParameterDescription
valRequired. The value to be tested.
strictModeOptional. Defaults to true. Validation strategy, it determines if an empty JSON object is valid or not.

isNull

It determines if the given value is NULL.

isNull(val)

ParameterDescription
valRequired. The value to be tested.

isNumber

It determines if the given value is numeric.

isNumber(val, strictMode)

ParameterDescription
valRequired. The value to be tested.
strictModeOptional. Defaults to true. Validation strategy, it determines if numbers as strings are valid or not.

isObject

It determines if the given value is an object. It will return false for Array and Date.

isObject(val, strictMode)

ParameterDescription
valRequired. The value to be tested.
strictModeOptional. Defaults to true. Validation strategy, it determines if an empty object is valid or not.

isOdd

It determines if the given value is an odd number.

isOdd(val)

ParameterDescription
valRequired. The value to be tested.

isSet

It determines if the given value has been set/declare as a string, number, date, array, object, etc.

isSet(val)

ParameterDescription
valRequired. The value to be tested.

isSsn

It determines if the given value is a valid format social security number. 000-00-0000.

isSsn(val)

ParameterDescription
valRequired. The value to be tested.

isString

It determines if the given value is a string.

isString(val, strictMode)

ParameterDescription
valRequired. The value to be tested.
strictModeOptional. Defaults to true. Validation strategy, it determines if an empty string is valid or not.

isTrue

It determines if the given value is TRUE.

isTrue(val)

ParameterDescription
valRequired. The value to be tested.

isType

It returns the data type of the given value, number, string, array, etc.

isType(val)

ParameterDescription
valRequired. The value to be tested.

isUndefined

It determines if the given value UNDEFINED.

isUndefined(val)

ParameterDescription
valRequired. The value to be tested.

Other Validation Functions

isNotArray

isNotBoolean

isNotDate

isNotFunction

isNotJson

isNotNull

isNotNumber

isNotObject

isNotSet

isNotString

isNotUndefined

Array Sorting Functions

ascending

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}]

descending

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}]

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago