JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 560486
  • Score
    100M100P100Q175323F
  • License MIT

Create a vfile from a file-path

Package Exports

  • to-vfile

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (to-vfile) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

to-vfile Build Status Coverage Status

Create a vfile from a file-path. Optionally populates them from the file-system as well. Can write virtual files to file-system too.

Installation

npm:

npm install to-vfile

Note: the file-system stuff is not available in the browser.

Usage

Dependencies:

var toVFile = require('to-vfile');

Create a virtual file by its file-path:

toVFile('readme.md');

Yields:

VFile {
  data: {},
  messages: [],
  history: [ 'readme.md' ],
  cwd: '/Users/tilde/projects/oss/to-vfile' }

Populate a virtual file:

toVFile.readSync('.git/HEAD', 'utf8');

Yields:

VFile {
  data: {},
  messages: [],
  history: [ '.git/HEAD' ],
  cwd: '/Users/tilde/projects/oss/to-vfile',
  contents: 'ref: refs/heads/master\n' }

API

toVFile(options)

Create a virtual file. Works like the vfile constructor, except when options is string or Buffer, in which case it’s treated as {path: options} instead of {contents: options}.

toVFile.read(options[, encoding], callback)

Creates a virtual file from options (toVFile(options)), reads the file from the file-system and populates file.contents with the result. If encoding is specified, it’s passed to fs.readFile. Invokes callback with either an error or the populated virtual file.

toVFile.readSync(options[, encoding])

Like toVFile.read but synchronous. Either throws an error or returns a populated virtual file.

toVFile.write(options[, fsOptions], callback)

Creates a virtual file from options (toVFile(options)), writes the file to the file-system. fsOptions are passed to fs.writeFile. Invokes callback with an error, if any.

toVFile.writeSync(options[, fsOptions])

Like toVFile.write but synchronous. Throws an error, if any.

License

MIT © Titus Wormer