Reference Source

Function

Static Public Summary
public

accessDeep(path: array, obj: object): null | any

Safely access deeply nested values in an object.

public

arrayChunks(arr: array, len: number): array

Group an array's values into subgroups.

public

ifFunc(func: function, args: args): any

Quickly call a function or fail gracefully if it does not exist.

public

mapObj(obj: object, callback: function): array

The mapObj() method creates a new array with the results of calling a provided function on every element in the calling object.

public

setDeep(obj: object, path: array | string , value: any, setRecursively: boolean): object

Deeply nest and set a value in an object.

Static Public

public accessDeep(path: array, obj: object): null | any source

import {accessDeep} from 'project-helpers/js/object-helpers.js'

Safely access deeply nested values in an object. If the path to the value is not valid, the method will gracefully return null.

Params:

NameTypeAttributeDescription
path array

the array representation of the path to access.

obj object

the object who's value you are trying to access.

Return:

null | any

will return null on path not found, or the value found.

public arrayChunks(arr: array, len: number): array source

import {arrayChunks} from 'project-helpers/js/object-helpers.js'

Group an array's values into subgroups.

Params:

NameTypeAttributeDescription
arr array

The target array.

len number

The length of the chunks.

Return:

array

A two-dimensional segmented array.

public ifFunc(func: function, args: args): any source

Quickly call a function or fail gracefully if it does not exist.

Params:

NameTypeAttributeDescription
func function

The function to try to call.

args args

The would-be arguments of the function.

Return:

any

returns whatever the function returns.

public mapObj(obj: object, callback: function): array source

The mapObj() method creates a new array with the results of calling a provided function on every element in the calling object.

Params:

NameTypeAttributeDescription
obj object

The object to map.

callback function

The function to call per iterated value.

Return:

array

returns an array with the values of each returned value in the callback.

public setDeep(obj: object, path: array | string , value: any, setRecursively: boolean): object source

import {setDeep} from 'project-helpers/js/object-helpers.js'

Deeply nest and set a value in an object.

Params:

NameTypeAttributeDescription
obj object

The target object

path array | string

The path where the value should be nested and set.

value any

The value to set

setRecursively boolean

Should create path if the path does not exist.

Return:

object

Returns the new object for reference purposes.