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

tree-visit

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tree-visit - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

2

lib/diagram/directoryDiagram.js

@@ -8,3 +8,3 @@ "use strict";

LinePrefix["LastChild"] = "\u2514\u2500\u2500 ";
LinePrefix["NestedChild"] = "\u2502\u00A0\u00A0 ";
LinePrefix["NestedChild"] = "\u2502 ";
LinePrefix["LastNestedChild"] = " ";

@@ -11,0 +11,0 @@ })(LinePrefix || (LinePrefix = {}));

{
"name": "tree-visit",
"version": "0.1.1",
"version": "0.1.2",
"description": "A tree traversal library.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -249,23 +249,14 @@ # tree-visit

### `visit`
### `flat`
Visit each node in the tree, calling an optional `onEnter` and `onLeave` for each.
Returns an array containing the root node and all of its descendants.
From `onEnter`:
This is analogous to `Array.prototype.flat` for flattening arrays.
- return nothing or `undefined` to continue
- return `"skip"` to skip the children of that node and the subsequent `onLeave`
- return `"stop"` to end traversal
**Type**: `function flat<T>(node: T, options: BaseOptions<T>): T[]`
From `onLeave`:
- return nothing or `undefined` to continue
- return `"stop"` to end traversal
**Type**: `function visit<T>(node: T, options: VisitOptions<T>): void`
#### Example
```js
import { visit } from 'tree-visit'
import { flat } from 'tree-visit'

@@ -285,9 +276,4 @@ const getChildren = (node) => node.children || []

visit(rootNode, {
getChildren,
onEnter: (node) => {
console.log(node)
},
})
// #=> a, b, c, d
flat(rootNode, { getChildren }).map((node) => node.name)
// #=> ['a', 'b', 'c', 'd']
```

@@ -297,14 +283,23 @@

### `flat`
### `visit`
Returns an array containing the root node and all of its descendants.
Visit each node in the tree, calling an optional `onEnter` and `onLeave` for each.
This is analogous to `Array.prototype.flat` for flattening arrays.
From `onEnter`:
**Type**: `function flat<T>(node: T, options: BaseOptions<T>): T[]`
- return nothing or `undefined` to continue
- return `"skip"` to skip the children of that node and the subsequent `onLeave`
- return `"stop"` to end traversal
From `onLeave`:
- return nothing or `undefined` to continue
- return `"stop"` to end traversal
**Type**: `function visit<T>(node: T, options: VisitOptions<T>): void`
#### Example
```js
import { flat } from 'tree-visit'
import { visit } from 'tree-visit'

@@ -324,4 +319,9 @@ const getChildren = (node) => node.children || []

flat(rootNode, { getChildren }).map((node) => node.name)
// #=> ['a', 'b', 'c', 'd']
visit(rootNode, {
getChildren,
onEnter: (node) => {
console.log(node)
},
})
// #=> a, b, c, d
```

@@ -328,0 +328,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