Skip to content

Commit

Permalink
Merge 17e80dc into c138a4c
Browse files Browse the repository at this point in the history
  • Loading branch information
mrodrig committed Oct 10, 2022
2 parents c138a4c + 17e80dc commit cc22767
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ let path = require('doc-path');

If the key does not exist, `undefined` is returned.

If the object's structure is extremely deep, then an error may be thrown if the maximum call stack size is exceeded while traversing the object.

##### path.evaluatePath Example:

```javascript
Expand Down Expand Up @@ -87,6 +89,7 @@ console.log(path.evaluatePath(document, 'Features.packages.name'));

If the key does not exist, then the object will be built up to have that path.
If no document is provided, an error will be thrown.
If the object's structure is extremely deep, then an error may be thrown if the maximum call stack size is exceeded while traversing the object.

#### path.setPath Example:

Expand Down
8 changes: 8 additions & 0 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ module.exports = {
setPath
};

/**
* Main function that evaluates the path in a particular object
* @param {Object|Array} obj object to evaluate path in
* @param {String} kp key path
* @returns {*|null} value at key path
* @throws {Error} possible error if call stack size is exceeded
*/
function evaluatePath(obj, kp) {
if (!obj) {
return null;
Expand Down Expand Up @@ -46,6 +53,7 @@ function evaluatePath(obj, kp) {
* @param kp {String} key path
* @param v {*} value to be set
* @returns {Object|Array}
* @throws {Error} possible error if call stack size is exceeded
*/
function setPath(obj, kp, v) {
if (!obj) {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "mrodrig",
"name": "doc-path",
"description": "A document path library for Node",
"version": "3.0.5",
"version": "3.0.6",
"homepage": "https://mrodrig.github.io/doc-path",
"repository": {
"type": "git",
Expand Down

0 comments on commit cc22767

Please sign in to comment.