Home Manual Reference Source Test Repository
public class | source

ObjectUtil

Provides common object manipulation utilities.

Static Method Summary

Static Public Methods
public static

depthTraverse(data: object | Array, func: function): *

Performs a naive depth traversal of an object / array.

public static

Returns a list of accessor keys by traversing the given object.

public static

safeAccess(data: object, accessor: string, defaultValue: *): *

Provides a way to safely access an objects data / entries given an accessor string which describes the entries to walk.

public static

safeEqual(source: object, target: object): boolean

Compares a source object and values of entries against a target object.

public static

safeSet(data: object, accessor: string, value: *, operation: string): boolean

Provides a way to safely set an objects data / entries given an accessor string which describes the entries to walk.

Static Public Methods

public static depthTraverse(data: object | Array, func: function): * source

Performs a naive depth traversal of an object / array. The data structure must not have circular references. The result of the callback function is used to modify in place the given data.

Params:

NameTypeAttributeDescription
data object | Array

An object or array.

func function

A callback function to process leaf values in children arrays or object members.

Return:

*

public static getAccessorList(data: object): Array source

Returns a list of accessor keys by traversing the given object.

Params:

NameTypeAttributeDescription
data object

An object to traverse for accessor keys.

Return:

Array

public static safeAccess(data: object, accessor: string, defaultValue: *): * source

Provides a way to safely access an objects data / entries given an accessor string which describes the entries to walk. To access deeper entries into the object format the accessor string with . between entries to walk.

Params:

NameTypeAttributeDescription
data object

An object to access entry data.

accessor string

A string describing the entries to access.

defaultValue *

(Optional) A default value to return if an entry for accessor is not found.

Return:

*

public static safeEqual(source: object, target: object): boolean source

Compares a source object and values of entries against a target object. If the entries in the source object match the target object then true is returned otherwise false. If either object is undefined or null then false is returned.

Params:

NameTypeAttributeDescription
source object

Source object.

target object

Target object.

Return:

boolean

public static safeSet(data: object, accessor: string, value: *, operation: string): boolean source

Provides a way to safely set an objects data / entries given an accessor string which describes the entries to walk. To access deeper entries into the object format the accessor string with . between entries to walk.

Params:

NameTypeAttributeDescription
data object

An object to access entry data.

accessor string

A string describing the entries to access.

value *

A new value to set if an entry for accessor is found.

operation string

(Optional) Operation to perform including: 'add', 'div', 'mult', 'set', 'sub'; default (set).

Return:

boolean

True if successful.