Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
shinnn committed Mar 29, 2018
0 parents commit aa69c9a
Show file tree
Hide file tree
Showing 11 changed files with 4,587 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = tab
tab_width = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.{md,yml}]
indent_style = space

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
* text=auto
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
.nyc_output
coverage
node_modules
5 changes: 5 additions & 0 deletions .travis.yml
@@ -0,0 +1,5 @@
branches:
except: /^v\d/
language: node_js
node_js: node
after_script: node_modules/.bin/nyc report --reporter=text-lcov | npx coveralls
6 changes: 6 additions & 0 deletions LICENSE
@@ -0,0 +1,6 @@
ISC License (ISC)
Copyright 2018 Shinnosuke Watanabe

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
74 changes: 74 additions & 0 deletions README.md
@@ -0,0 +1,74 @@
# vfile-glob

[![npm version](https://img.shields.io/npm/v/vfile-glob.svg)](https://www.npmjs.com/package/vfile-glob)
[![Build Status](https://travis-ci.org/shinnn/vfile-glob.svg?branch=master)](https://travis-ci.org/shinnn/vfile-glob)
[![Build status](https://ci.appveyor.com/api/projects/status/8jwxugh978gw12it/branch/master?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/vfile-glob/branch/master)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/vfile-glob.svg)](https://coveralls.io/github/shinnn/vfile-glob)

Search files with [glob](https://github.com/isaacs/node-glob#glob-primer) pattern and create [VFile](https://github.com/vfile/vfile) objects from them

```javascript
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](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/getting-started/what-is-npm).

```
npm install vfile-glob
```

## API

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

### vfileGlob(*pattern* [, *options*])

*pattern*: `string` (glob pattern)
*options*: `Object` ([`read-glob`](https://github.com/shinnn/node-read-glob) options) or `string` (encoding)
Return: [`Observable`](https://github.com/tc39/proposal-observable#observable) ([zenparsing's implementation](https://github.com/zenparsing/zen-observable))

When the `Observable` is [subscribe](https://tc39.github.io/proposal-observable/#observable-prototype-subscribe)d, it starts searching files matching the given glob pattern, create [`VFile`](https://github.com/vfile/vfile#vfileoptions)s from matched files and successively sends them to its [`Observer`](https://github.com/tc39/proposal-observable#observer).

```javascript
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](./LICENSE) © 2018 Shinnosuke Watanabe
9 changes: 9 additions & 0 deletions appveyor.yml
@@ -0,0 +1,9 @@
image: Visual Studio 2017
platform: x64
shallow_clone: true
skip_tags: true
install:
- ps: Install-Product node Stable x64
- npm install
build: off
test_script: node test.js
17 changes: 17 additions & 0 deletions index.js
@@ -0,0 +1,17 @@
'use strict';

const readGlob = require('read-glob');
const vfile = require('vfile');

function globResultToVfile({contents, cwd, path, stat}) {
return vfile({
contents,
cwd,
path,
data: stat ? {stat} : {}
});
}

module.exports = function vfileGlob(...args) {
return readGlob(...args).map(globResultToVfile);
};

0 comments on commit aa69c9a

Please sign in to comment.