Skip to content

Commit

Permalink
Add error info (#29)
Browse files Browse the repository at this point in the history
* docs: add possible error info

* chore(rel): 3.0.6
  • Loading branch information
mrodrig authored Oct 10, 2022
1 parent c138a4c commit 5fe23a7
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 5fe23a7

Please sign in to comment.