vfile-write

Write vfile to file

Usage no npm install needed!

<script type="module">
  import vfileWrite from 'https://cdn.skypack.dev/vfile-write';
</script>

README

vfile-write

Travis Coveralls github David

Writes a VFile and any vfiles nested in its contents. Write will also create any directories needed as well as the file. Returns a promise or callback.

Install

npm i -S vfile-write

Usage

The following script:

var write = require('./lib')
var vfile = require('vfile')

var file = vfile({
    path: 'one',
    contents: [
        vfile({
            path: 'one.txt',
            contents: 'one'
        }),
        vfile({
            path: 'two',
            contents: [
                vfile({
                    path: 'two.txt',
                    contents: 'two'
                })
            ]
        })
    ]
})

write(file, 'utf-8').catch(console.error)

Will create the file structure:

one
├── one.txt
└── two
    └── two.txt

Api

write(file[, options[, callback]])

file

VFile

VFile to write.

options?

object

Options to pass to writeFile and/or mkdir.

callback?

function

Optional callback function. callback(error, files)

returns a promise or callback.

write#sync(file[, options])

Synchronous version of write.

Related

vfile-read

vfile-update

to-vfile

License

MIT © Paul Zimmer