Class: Path

Path

new Path(pathopt)

Path object used to resolve object paths and retrieve data from objects by using paths.
Parameters:
Name Type Attributes Description
path String <optional>
The path to assign.
Source:

Methods

aggregate(obj, path) → {Array}

Retrieves all the values inside an object based on the passed path string. Will automatically traverse any arrays it encounters and assumes array indexes are not part of the specifed path.
Parameters:
Name Type Description
obj Object | Array An object or array of objects to scan paths for.
path String The path string delimited by a period.
Source:
Returns:
An array of values found at the end of each path termination.
Type
Array

clean(str) → {*}

Removes leading period (.) from string and returns it.
Parameters:
Name Type Description
str String The string to clean.
Source:
Returns:
Type
*

countKeys(testObj) → {Number}

Counts the total number of key endpoints in the passed object.
Parameters:
Name Type Description
testObj Object The object to count key endpoints for.
Source:
Returns:
The number of endpoints.
Type
Number

countObjectPaths(testKeys, testObj) → {Object}

Tests if the passed object has the paths that are specified and that a value exists in those paths and if so returns the number matched.
Parameters:
Name Type Description
testKeys Object The object describing the paths to test for.
testObj Object The object to test paths against.
Source:
Returns:
Stats on the matched keys
Type
Object

get(obj, path) → {*}

Gets a single value from the passed object and given path.
Parameters:
Name Type Description
obj Object The object to inspect.
path String The path to retrieve data from.
Source:
Returns:
Type
*

hasObjectPaths(testKeys, testObj) → {Boolean}

Tests if the passed object has the paths that are specified and that a value exists in those paths.
Parameters:
Name Type Description
testKeys Object The object describing the paths to test for.
testObj Object The object to test paths against.
Source:
Returns:
True if the object paths exist.
Type
Boolean

keyValue(obj, pathopt) → {Array}

Gets the value(s) that the object contains for the currently assigned path string with their associated keys.
Parameters:
Name Type Attributes Description
obj Object The object to evaluate the path against.
path String <optional>
A path to use instead of the existing one passed in path().
Source:
Returns:
An array of values for the given path with the associated key.
Type
Array

parse(obj, withValueopt) → {Object}

Takes a non-recursive object and converts the object hierarchy into a path string.
Parameters:
Name Type Attributes Description
obj Object The object to parse.
withValue Boolean <optional>
If true will include a 'value' key in the returned object that represents the value the object path points to.
Source:
Returns:
Type
Object

parseArr() → {Array}

Takes a non-recursive object and converts the object hierarchy into an array of path strings that allow you to target all possible paths in an object. The options object accepts an "ignore" field with a regular expression as the value. If any key matches the expression it is not included in the results. The options object accepts a boolean "verbose" field. If set to true the results will include all paths leading up to endpoints as well as they endpoints themselves.
Source:
Returns:
Type
Array

path(pathopt)

Gets / sets the given path for the Path instance.
Parameters:
Name Type Attributes Description
path String <optional>
The path to assign.
Source:

push(obj, path, val) → {*}

Push a value to an array on an object for the specified path.
Parameters:
Name Type Description
obj Object The object to update.
path String The path to the array to push to.
val * The value to push to the array at the object path.
Source:
Returns:
Type
*

set(obj, path, val) → {*}

Sets a value on an object for the specified path.
Parameters:
Name Type Description
obj Object The object to update.
path String The path to update.
val * The value to set the object path to.
Source:
Returns:
Type
*

set(obj, path, val) → {*}

Sets a value on an object for the specified path.
Parameters:
Name Type Description
obj Object The object to update.
path String The path to update.
val * The value to set the object path to.
Source:
Returns:
Type
*

value(obj, pathopt, optionsopt) → {Array}

Gets the value(s) that the object contains for the currently assigned path string.
Parameters:
Name Type Attributes Description
obj Object The object to evaluate the path against.
path String <optional>
A path to use instead of the existing one passed in path().
options Object <optional>
An optional options object.
Source:
Returns:
An array of values for the given path.
Type
Array