Socket
Socket
Sign inDemoInstall

unist-util-visit-parents

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unist-util-visit-parents - npm Package Compare versions

Comparing version 3.1.0 to 3.1.1

81

index.js

@@ -17,5 +17,6 @@ 'use strict'

function visitParents(tree, test, visitor, reverse) {
var step
var is
if (func(test) && !func(visitor)) {
if (typeof test === 'function' && typeof visitor !== 'function') {
reverse = visitor

@@ -27,28 +28,32 @@ visitor = test

is = convert(test)
step = reverse ? -1 : 1
one(tree, null, [])()
factory(tree, null, [])()
function one(child, index, parents) {
var value = object(child) ? child : {}
function factory(node, index, parents) {
var value = typeof node === 'object' && node !== null ? node : {}
var name
if (string(value.type)) {
name = string(value.tagName)
? value.tagName
: string(value.name)
? value.name
: undefined
if (typeof value.type === 'string') {
name =
typeof value.tagName === 'string'
? value.tagName
: typeof value.name === 'string'
? value.name
: undefined
node.displayName =
visit.displayName =
'node (' + color(value.type + (name ? '<' + name + '>' : '')) + ')'
}
return node
return visit
function node() {
function visit() {
var grandparents = parents.concat(node)
var result = []
var subresult
var offset
if (!test || is(child, index, parents[parents.length - 1] || null)) {
result = toResult(visitor(child, parents))
if (!test || is(node, index, parents[parents.length - 1] || null)) {
result = toResult(visitor(node, parents))

@@ -60,28 +65,18 @@ if (result[0] === EXIT) {

if (!child.children || result[0] === SKIP) {
return result
}
if (node.children && result[0] !== SKIP) {
offset = (reverse ? node.children.length : -1) + step
subresult = toResult(children(child.children, parents.concat(child)))
return subresult[0] === EXIT ? subresult : result
}
}
while (offset > -1 && offset < node.children.length) {
subresult = factory(node.children[offset], offset, grandparents)()
// Visit children in `parent`.
function children(children, parents) {
var min = -1
var step = reverse ? -1 : 1
var index = (reverse ? children.length : min) + step
var child
var result
if (subresult[0] === EXIT) {
return subresult
}
while (index > min && index < children.length) {
child = children[index]
result = one(child, index, parents)()
if (result[0] === EXIT) {
return result
offset =
typeof subresult[1] === 'number' ? subresult[1] : offset + step
}
}
index = typeof result[1] === 'number' ? result[1] : index + step
return result
}

@@ -92,3 +87,3 @@ }

function toResult(value) {
if (object(value) && 'length' in value) {
if (value !== null && typeof value === 'object' && 'length' in value) {
return value

@@ -103,13 +98,1 @@ }

}
function func(d) {
return typeof d === 'function'
}
function string(d) {
return typeof d === 'string'
}
function object(d) {
return typeof d === 'object' && d !== null
}
{
"name": "unist-util-visit-parents",
"version": "3.1.0",
"version": "3.1.1",
"description": "unist utility to recursively walk over nodes, with ancestral information",

@@ -48,15 +48,16 @@ "license": "MIT",

"devDependencies": {
"browserify": "^16.0.0",
"dtslint": "^3.0.0",
"browserify": "^17.0.0",
"dtslint": "^4.0.0",
"nyc": "^15.0.0",
"prettier": "^2.0.0",
"remark": "^12.0.0",
"remark-cli": "^8.0.0",
"remark-preset-wooorm": "^7.0.0",
"remark": "^13.0.0",
"remark-cli": "^9.0.0",
"remark-gfm": "^1.0.0",
"remark-preset-wooorm": "^8.0.0",
"strip-ansi": "^6.0.0",
"tape": "^5.0.0",
"tinyify": "^2.0.0",
"typescript": "^3.0.0",
"tinyify": "^3.0.0",
"typescript": "^4.0.0",
"unified": "^9.0.0",
"xo": "^0.32.0"
"xo": "^0.34.0"
},

@@ -63,0 +64,0 @@ "scripts": {

@@ -187,5 +187,5 @@ # unist-util-visit-parents

[chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://spectrum.chat/unified/syntax-tree
[chat]: https://github.com/syntax-tree/unist/discussions

@@ -192,0 +192,0 @@ [npm]: https://docs.npmjs.com/cli/install

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