Object Util
The object-util Library provides methods to easily transform object to and from path/value arrays. Path/value arrays are used when updating devices and information for most of the objects on the Leverege platform.
Install
npm install --save @leverege/object-util
const ObjectUtil = require( '@leverege/object-util' );
copy( toCopy )
returns a copy if it is passed an array or object.
assignFields( dst, src, fields, copyFields )
- dst - object to have fields added to it
- src - object to have fields copied from
- fields - array of strings of keys to have copied
- copyFields - defaults to false, if true will deep copy the fields
flatten( obj, options )
Turns a deep object into a shallow object with keys to represent placement of deep values
- obj - object to be flattened
- options - value to separate keys
unflatten( data, opts )
Takes a shallow object and transforms it into a deep array
- data - the object to be unflattened
- opts - divider of the keys in data
toPathValue( obj )
Returns an array of path and value objects from the obj
fromPathValue( arr )
returns a deep object of the path value array
pathValue( arr, path, dValue )
Scans arr for the path and returns the corresponding value.