Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including vfile-read with all npm packages installed. Try it out:

var vfileRead = require("vfile-read")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

vfile-read v1.3.8

Read file or directory into vfile.

vfile-read

Read a file or directory into a vfile.

Travis Coveralls github

Read a file or directory into a vfile while keeping the directories structure using vfiles contents key. Vfile-read returns a promise if no callback is given.

install

npm i vfile-read

usage

Given:

./foo
|_ bar
  |_ foo.txt
    |_ "Foo"
var read = require('vfile-read')

read('./foo')
  .then(console.log)
  .catch(console.error)

Outputs:

VFile {
  data: {},
  messages: [],
  history: ['foo'],
  cwd: './',
  contents: [
    VFile {
      data: {},
      messages: [],
      history: ["foo/bar"],
      cwd: "./",
      contents: [
        VFile {
          data: {},
          messages: [],
          history: ["foo/bar/foo.txt"],
          cwd: "./",
          contents: "Foo"
        }
      ]
    }
  ]
}

api

read (location[, options [, callback]])


location

string - Location to read from.


options?

[ string | array | object ] - If options is a string then options.encoding is set to options. If options is an array then options.ignores is set to options.

options.encoding

string - default = 'utf-8'

options.ignores

array - default = []


callback?

function - If no callback is given, then read returns a promise.


read#sync

Synchronous version of vfile-read

var read = require('vfile-read')

try {
  var file = read.sync('./', {ignores: ['node_modules'])
  ...
} catch (err) {
  ...
}

Vfile-read uses fs.readdir and fs.readFile and options will be passed down to those functions.

related

to-vfile - Create a vfile from a file-path

License

MIT © Paul Zimmer

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free