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

unist-util-visit

Package Overview
Dependencies
Maintainers
2
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unist-util-visit - npm Package Compare versions

Comparing version 3.1.0 to 4.0.0

58

index.d.ts

@@ -1,22 +0,36 @@

export const visit: (<T extends import('unist').Node>(
tree: Node,
test:
| T['type']
| Partial<T>
| import('unist-util-is').TestFunctionPredicate<T>
| (
| T['type']
| Partial<T>
| import('unist-util-is').TestFunctionPredicate<T>
)[],
visitor: Visitor<T>,
reverse?: boolean
/**
* Visit children of tree which pass a test
*
* @param tree Abstract syntax tree to walk
* @param test Test, optional
* @param visitor Function to run for each node
* @param reverse Fisit the tree in reverse, defaults to false
*/
export const visit: (<
Tree extends import('unist').Node<import('unist').Data>,
Check extends import('unist-util-is').Test
>(
tree: Tree,
test: Check,
visitor: Visitor<
import('unist-util-visit-parents/complex-types').Matches<
import('unist-util-visit-parents/complex-types').InclusiveDescendant<
Tree,
void
>,
Check
>
>,
reverse?: boolean | undefined
) => void) &
((
tree: Node,
test: Test,
visitor: Visitor<Node>,
reverse?: boolean
) => void) &
((tree: Node, visitor: Visitor<Node>, reverse?: boolean) => void)
(<Tree_1 extends import('unist').Node<import('unist').Data>>(
tree: Tree_1,
visitor: Visitor<
import('unist-util-visit-parents/complex-types').InclusiveDescendant<
Tree_1,
void
>
>,
reverse?: boolean | undefined
) => void)
export type Node = import('unist').Node

@@ -27,3 +41,3 @@ export type Parent = import('unist').Parent

/**
* Invoked when a node (matching test, if given) is found.
* Called when a node (matching test, if given) is found.
* Visitors are free to transform node.

@@ -38,3 +52,3 @@ * They can also transform the parent of node (the last of ancestors).

*/
export type Visitor<V extends import('unist').Node> = (
export type Visitor<V extends import('unist').Node<import('unist').Data>> = (
node: V,

@@ -41,0 +55,0 @@ index: number | null,

@@ -9,3 +9,3 @@ /**

/**
* Invoked when a node (matching test, if given) is found.
* Called when a node (matching test, if given) is found.
* Visitors are free to transform node.

@@ -32,8 +32,15 @@ * They can also transform the parent of node (the last of ancestors).

/**
* Visit children of tree which pass a test
*
* @param tree Abstract syntax tree to walk
* @param test Test, optional
* @param visitor Function to run for each node
* @param reverse Fisit the tree in reverse, defaults to false
*/
export const visit =
/**
* @type {(
* (<T extends Node>(tree: Node, test: T['type']|Partial<T>|import('unist-util-is').TestFunctionPredicate<T>|Array.<T['type']|Partial<T>|import('unist-util-is').TestFunctionPredicate<T>>, visitor: Visitor<T>, reverse?: boolean) => void) &
* ((tree: Node, test: Test, visitor: Visitor<Node>, reverse?: boolean) => void) &
* ((tree: Node, visitor: Visitor<Node>, reverse?: boolean) => void)
* (<Tree extends Node, Check extends Test>(tree: Tree, test: Check, visitor: Visitor<import('unist-util-visit-parents/complex-types').Matches<import('unist-util-visit-parents/complex-types').InclusiveDescendant<Tree>, Check>>, reverse?: boolean) => void) &
* (<Tree extends Node>(tree: Tree, visitor: Visitor<import('unist-util-visit-parents/complex-types').InclusiveDescendant<Tree>>, reverse?: boolean) => void)
* )}

@@ -43,8 +50,6 @@ */

/**
* Visit children of tree which pass a test
*
* @param {Node} tree Abstract syntax tree to walk
* @param {Test} test test Test node
* @param {Visitor<Node>} visitor Function to run for each node
* @param {boolean} [reverse] Fisit the tree in reverse, defaults to false
* @param {Node} tree
* @param {Test} test
* @param {Visitor<Node>} visitor
* @param {boolean} [reverse]
*/

@@ -65,3 +70,3 @@ function (tree, test, visitor, reverse) {

function overload(node, parents) {
var parent = parents[parents.length - 1]
const parent = parents[parents.length - 1]
return visitor(

@@ -68,0 +73,0 @@ node,

{
"name": "unist-util-visit",
"version": "3.1.0",
"version": "4.0.0",
"description": "unist utility to visit nodes",

@@ -52,3 +52,3 @@ "license": "MIT",

"unist-util-is": "^5.0.0",
"unist-util-visit-parents": "^4.0.0"
"unist-util-visit-parents": "^5.0.0"
},

@@ -65,7 +65,6 @@ "devDependencies": {

"tape": "^5.0.0",
"tsd": "^0.14.0",
"tsd": "^0.17.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"unified": "^9.0.0",
"xo": "^0.39.0"
"xo": "^0.42.0"
},

@@ -89,7 +88,3 @@ "scripts": {

"xo": {
"prettier": true,
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off"
}
"prettier": true
},

@@ -96,0 +91,0 @@ "remarkConfig": {

@@ -50,2 +50,8 @@ # unist-util-visit

Note: this example also uses `unist-builder`, to run the example ensure both `unist-builder` and `unist-util-visit` are installed:
```sh
npm install unist-builder unist-util-visit
```
## API

@@ -64,3 +70,3 @@

Instead of being passed an array of ancestors, `visitor` is invoked with the
Instead of being passed an array of ancestors, `visitor` is called with the
`node`’s [`index`][index] and its [`parent`][parent]. The optional return value

@@ -67,0 +73,0 @@ `next` is documented in [`unist-util-visit-parents`][vp]’s readme.

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