This repository has been archived on 2020-11-02. You can view files and clone it, but cannot push or open issues or pull requests.
TripSit_Suite/node_modules/unist-util-visit/index.js
2020-11-01 22:46:04 +00:00

30 lines
668 B
JavaScript

'use strict'
module.exports = visit
var visitParents = require('unist-util-visit-parents')
var CONTINUE = visitParents.CONTINUE
var SKIP = visitParents.SKIP
var EXIT = visitParents.EXIT
visit.CONTINUE = CONTINUE
visit.SKIP = SKIP
visit.EXIT = EXIT
function visit(tree, test, visitor, reverse) {
if (typeof test === 'function' && typeof visitor !== 'function') {
reverse = visitor
visitor = test
test = null
}
visitParents(tree, test, overload, reverse)
function overload(node, parents) {
var parent = parents[parents.length - 1]
var index = parent ? parent.children.indexOf(node) : null
return visitor(node, index, parent)
}
}