PathObject

PathObject Convenient way to work with JSON datastructures.

Constructor

new PathObject(propertiesopt)

Constructor

Parameters:
NameTypeAttributesDefaultDescription
propertiesobject<optional>
{}

Initial literal

Example
const po = new PathObject(
 {
    "a" : "Hello",
    "b" : {
        "c" : "World"
    }
 }
);

po.get( "b.c" );
// Returns "World"
po.set( "b.c", "InfrontJS" );
po.get( "b.c" );
// Return "InfrontJS"
po.get( "b.d", "what?" );
// Returns "what?"

Methods

get(path, defaultValueopt) → {*}

Taken from lodash. Refer to: https://github.com/lodash/lodash/blob/4.17.15/lodash.js#L13126

Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.

Parameters:
NameTypeAttributesDefaultDescription
pathArray | string

The path of the property to get.

defaultValue*<optional>
null

The value returned for undefined resolved values. Default is null

Returns:

Returns the resolved value.

Type: 
*
Example
const pathObject = new PathObject( { 'a': [{ 'b': { 'c': 3 } }] } );

pathObject.get('a[0].b.c');
// => 3

pathObject.get(['a', '0', 'b', 'c']);
// => 3

pathObject.get('a.b.c', 'default');
// => 'default'