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
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
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.
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) → {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(). |
Returns:
An array of values for the given path.
- Type
- Array