vfile-frontmatter
v0.0.0
Published
Extract a front matter from a VFile and assign parsed data to its `data` property
Downloads
2
Maintainers
Readme
vfile-frontmatter
Extract a front matter from a VFile and assign parsed data to its data
property
const vfileGlob = require('vfile-frontmatter');
vfileGlob('index.*').subscribe({
start() {
console.log('Glob started.');
},
next(file) {
file;
/*=> VFile {
data: {},
messages: [],
history: ['index.js'],
cwd: '/Users/shinnn/github/vfile-frontmatter',
contents: <Buffer ... >
} */
},
complete() {
console.log('Glob completed.');
}
});
Installation
npm install vfile-frontmatter
API
const vfileGlob = require('vfile-frontmatter');
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 VFile
s 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