Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Search files with glob pattern and create VFile objects from them

License

Notifications You must be signed in to change notification settings

shinnn/vfile-glob

Repository files navigation

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

About

Search files with glob pattern and create VFile objects from them

Resources

License

Stars

Watchers

Forks

Packages

No packages published