Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tree-crawl

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tree-crawl - npm Package Compare versions

Comparing version 1.0.5 to 1.1.0-0

dist/tree-crawl.esm.js

6

package.json
{
"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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc