https://github.com/normancarcamo/deep-object-search
Performs a traversal on a tree object.
https://github.com/normancarcamo/deep-object-search
Last synced: 3 months ago
JSON representation
Performs a traversal on a tree object.
- Host: GitHub
- URL: https://github.com/normancarcamo/deep-object-search
- Owner: normancarcamo
- License: mit
- Created: 2018-07-25T09:17:44.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-07-25T09:58:01.000Z (almost 7 years ago)
- Last Synced: 2025-03-01T20:46:27.045Z (3 months ago)
- Language: JavaScript
- Size: 22.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# deep-object-search
Performs a traversal on a tree object.Install
=======
`npm install deep-object-search --save`Usage
=====
```javascript
import deepSearch from 'deep-object-search'let tree = {
body: {
data: {
firstname: 'Norman',
lastname: 'Carcamo',
house:399,
games: {
console: true,
gameboy: undefined,
physic: null
}
}
},
sports: {
tennis: true,
basketball: true,
football: true,
rugby: false,
}
}deepSearch(tree, 'body.data.games.console')
/* output:
{
"found": true,
"search": "body.data.games",
"value": true,
"parent": {
"name": "body",
"content": {
"data": {
"firstname": "Norman",
"lastname": "Carcamo",
"house": 399,
"games": {
"console": true,
"physic": null
}
}
}
},
"path": "root.body.data.body.data.games"
}
*/
```**deepSearch(object, path, options)**
* `object` {Object} The "tree" to search.
* `path` {String} Used to search a path or a key name.
* `options` {Object} An optional object to change the root key name.
* `rootLabel` {String} The name of the first key appended to the end path. Defaults to `root`.