tree-crawl
Advanced tools
Comparing version 1.0.5 to 1.1.0-0
{ | ||
"name": "tree-crawl", | ||
"version": "1.0.5", | ||
"version": "1.1.0-0", | ||
"description": "Agnostic tree traversal library.", | ||
@@ -10,3 +10,3 @@ "author": "Nicolas Gryman <ngryman@gmail.com> (http://ngryman.sh/)", | ||
"browser": "dist/tree-crawl.js", | ||
"module": "index.js", | ||
"module": "dist/tree-crawl.ems.js", | ||
"jsnext:main": "index.js", | ||
@@ -73,3 +73,3 @@ "types": "index.d.ts", | ||
"clone": "^2.0.0", | ||
"codecov": "^2.1.0", | ||
"codecov": "^3.7.1", | ||
"cross-env": "^5.0.0", | ||
@@ -76,0 +76,0 @@ "documentation": "^5.3.3", |
@@ -87,2 +87,22 @@ # tree-crawl [![travis][travis-image]][travis-url] [![codecov][codecov-image]][codecov-url] [![greenkeeper][greenkeeper-image]][greenkeeper-url] [![size][size-image]][size-url] | ||
## FAQ | ||
### How can I get the path of the current node ([#37](https://github.com/ngryman/tree-crawl/issues/37))? | ||
**tl;dr It's easy for DFS, less easy for BFS** | ||
If you are using DFS you can use the following utility function: | ||
```javascript | ||
const getPath = context => | ||
context.cursor.stack.xs.reduce((path, item) => { | ||
if (item.node) { | ||
path.push(item.node) | ||
} | ||
return path | ||
}, []) | ||
``` | ||
If you are really concerned about performance, you could read items from the stack directly. Each item has a `node` and `index` property that you can use. The first item in the stack can be discarded and will have a `node` set to `null`. Be aware that you should not mutate the stack, or it will break the traversal. | ||
If you are using BFS, things gets more complex. A *simple hacky* way to do so is to traverse the tree using DFS first. You can ad a `path` property to your nodes using the method above. And then do your regular BFS traversal using that `path` property. | ||
## API | ||
@@ -89,0 +109,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41706
18
1086
303
2