vfile-visit

2.0.1 • Public • Published

vfile-visit

Convert vfile contents to vfiles and walk over nodes in contents

Travis Coveralls github

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

Package Sidebar

Install

npm i vfile-visit

Weekly Downloads

1

Version

2.0.1

License

MIT

Unpacked Size

3.7 kB

Total Files

5

Last publish

Collaborators

  • mrzmmr