2.0.1 • Published 5 years ago

vfile-visit v2.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

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

2.0.1

5 years ago

2.0.0

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.0

6 years ago

1.0.0

6 years ago