Javascript Helper Functions
Install
Via npm
$ npm i -S @la40/js-helpers
Via yarn
$ yarn add @la40/js-helpers
Use
import { arrayMove, isEmpty } from @la40/js-helpers;
Functions
-
arrayMove(arr, oldIndex, newIndex) ⇒
array
-
Move an array item from an index to another
-
arrayToObjectByProperty(arr, property, compact) ⇒
object
-
Convert an array with objects to an object like {"property value x": [object x, object y ...], "property value y": [object z, object c ...]}
-
arrayContainsSomeArray(arr1, arr2) ⇒
boolean
-
Determine if an array contains one or more items from another array.
-
arrayGetFirstFoundInArray(arr1, arr2) ⇒
null
|any
-
Get first found item in arr1.
-
stringToBoolean(string) ⇒
boolean
-
Convert boolean string like "false|no|0|''" to false everything else to true
-
isEmpty(value) ⇒
boolean
-
Check if value not empty (null,'',undefined,{},{ k1: null, k2: "" },[],[null,''])
-
isEuDateTime(euDateTimeString) ⇒
boolean
-
Check if given string fulfill european data time format dd.mm.yyyy hh:mm:ss
-
isDeepEqual(object1, object2) ⇒
boolean
-
Check if two objects are deep equal
-
isObject(o) ⇒
boolean
-
Check if an object inherits Object, {}
-
recursiveDeepCopy(o) ⇒
object
-
Will create a recursive deep copy of an object
array
arrayMove(arr, oldIndex, newIndex) ⇒ Move an array item from an index to another
Kind: global function
Returns: array
- The new array
Param | Type |
---|---|
arr | array |
oldIndex | int |
newIndex | int |
object
arrayToObjectByProperty(arr, property, compact) ⇒ Convert an array with objects to an object like {"property value x": [object x, object y ...], "property value y": [object z, object c ...]}
Kind: global function
Returns: object
- The new object
Param | Type | Description |
---|---|---|
arr | array |
array with objects to convert |
property | string |
property to use |
compact | boolean |
default to true will remove the property from objects x,y,z,c , if false will leave the objects as is |
boolean
arrayContainsSomeArray(arr1, arr2) ⇒ Determine if an array contains one or more items from another array.
Kind: global function
Param | Type | Description |
---|---|---|
arr1 | array |
the array to search |
arr2 | array |
the array providing items to check for in the arr1 |
null
| any
arrayGetFirstFoundInArray(arr1, arr2) ⇒ Get first found item in arr1.
Kind: global function
Returns: null
| any
- null when not found or the found item from arr1
Param | Type | Description |
---|---|---|
arr1 | array |
the array to get the first found item from |
arr2 | array |
the array to search in |
boolean
stringToBoolean(string) ⇒ Convert boolean string like "false|no|0|''" to false everything else to true
Kind: global function
Param | Type |
---|---|
string | string |
boolean
isEmpty(value) ⇒ Check if value not empty (null,'',undefined,{},{ k1: null, k2: "" },[],[null,''])
Kind: global function
Param | Type |
---|---|
value | any |
boolean
isEuDateTime(euDateTimeString) ⇒ Check if given string fulfill european data time format dd.mm.yyyy hh:mm:ss
Kind: global function
Param | Type |
---|---|
euDateTimeString | string |
boolean
isDeepEqual(object1, object2) ⇒ Check if two objects are deep equal
Kind: global function
Param | Type |
---|---|
object1 | object |
object2 | object |
boolean
isObject(o) ⇒ Check if an object inherits Object, {}
Kind: global function
Param | Type |
---|---|
o | object |
object
recursiveDeepCopy(o) ⇒ Will create a recursive deep copy of an object
Kind: global function
Param | Type |
---|---|
o | object |
Testing
$ npm run test
Change log
Please see CHANGELOG for more information on what has changed recently.
Security
If you discover any security related issues, please email lachezar@grigorov.website instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.