1.0.0 • Published 7 years ago

vfile-glob v1.0.0

Weekly downloads
238
License
ISC
Repository
github
Last release
7 years ago

vfile-glob

npm version Build Status Build status Coverage Status

Search files with glob pattern and create VFile objects from them

const vfileGlob = require('vfile-glob');

vfileGlob('index.*').subscribe({
  start() {
    console.log('Glob started.');
  },
  next(file) {
    file;
    /*=> VFile {
      data: {},
      messages: [],
      history: ['index.js'],
      cwd: '/Users/shinnn/github/vfile-glob',
      contents: <Buffer ... >
    } */
  },
  complete() {
    console.log('Glob completed.');
  }
});

Installation

Use npm.

npm install vfile-glob

API

const vfileGlob = require('vfile-glob');

vfileGlob(pattern , options)

pattern: string (glob pattern)
options: Object (read-glob options) or string (encoding)
Return: Observable (zenparsing's implementation)

When the Observable is subscribed, it starts searching files matching the given glob pattern, create VFiles from matched files and successively sends them to its Observer.

vfileGlob('hi.txt').subscribe(file => {
  file.cwd; //=> '/Users/example'
  file.path; //=> 'hi.txt',
  file.contents; //=> <Buffer 48 69>
});

vfileGlob('exmaple/hi.txt', {
  cwd: '..',
  encoding: 'utf8'
}).subscribe(file => {
  file.cwd; //=> '/Users'
  file.path; //=> 'example/hi.txt'
  file.contents; //=> 'Hi'
});

License

ISC License © 2018 Shinnosuke Watanabe