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. |
Methods
- aggregate(obj, path) → {Array}
- clean(str) → {*}
- countKeys(testObj) → {Number}
- countObjectPaths(testKeys, testObj) → {Object}
- get(obj, path) → {*}
- hasObjectPaths(testKeys, testObj) → {Boolean}
- keyValue(obj, pathopt) → {Array}
- parse(obj, withValueopt) → {Object}
- parseArr() → {Array}
- path(pathopt)
- push(obj, path, val) → {*}
- set(obj, path, val) → {*}
- set(obj, path, val) → {*}
- value(obj, pathopt, optionsopt) → {Array}
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. |
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. |
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. |
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. |
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. |
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. |
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(). |
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. |
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.
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. |
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. |
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. |
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. |
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. |
Returns:
An array of values for the given path.
- Type
- Array