2.0.1 • Published 6 years ago
vfile-visit v2.0.1
vfile-visit
Convert vfile contents to vfiles and walk over nodes in contents
Converts vfile contents to vfiles if contents is an array. Optionally if a visitor function is supplied, then it will be called on each node in contents breadth first.
install
npm i -S vfile-visit
usage
var visit = require('vfile-visit')
var vfile = require('vfile')
var foo = visit({
path: 'foo',
contents: [{
path: 'bar',
contents: 'bar'
}]
})
console.log(foo)
Outputs:
VFile {
data: {},
messages: [],
history: ['foo'],
cwd: './',
contents: [
VFile {
data: {},
messages: [],
cwd: './',
contents: 'bar'
}
]
}
api
visit (file[, visitor])
file
VFile
| Object
- File or object to walk over
visitor
Function?
- Optional visitor to call while walking over nodes
Returns
- modified copy of VFile
visitor (current, index, parent)
current
VFile
- current node
index
Number
- index of current in parent.contents
parent
VFile
- parent of current node