glob-observable

0.8.0 • Public • Published

glob-observable

npm version Build Status Build status Coverage Status

Observable-based version of node-glob:

Match files using the patterns the shell uses, like stars and stuff.

const globObservable = require('glob-observable');
 
globObservable('*.js').subscribe({
  next: ({path}) => console.log(path), // index.js, test.js, ...
  complete: () => console.log('Glob completed.')
});

Installation

Use npm.

npm install glob-observable

API

const globObservable = require('glob-observable');

globObservable(pattern [, options])

pattern: string (glob pattern)
options: Object (glob options with strict and silent default to true)
Return: Observable (zenparsing's implementation)

Match result

Type: Object

When the observable is subscribed, it starts glob search and send a result object to the observer on every match. Unlike node-glob's match event, all results are deduplicated if nounique option is disabled.

Each result object has the following properties:

cwd

Type: string

The current working directory where to search.

path

Type: string

The path of matched file or directory.

It'll be an absolute path if absolute option is enabled, otherwise relative to cwd. Also, it'll be resolved to a realpath if realpath option is enabled.

stat

Type: fs.Stats

Information about the matched file or directory, for example mode and size. Only available if stat option is enabled.

const globObservable = require('glob-observable');
 
const observable = globObservable('*.json', {stat: true});
const subscription = observable.subscribe(result => {
  result.cwd; //=> '/Users/me/projects/...'
  result.path; //=> 'package.json'
  result.stat; //=> { dev: 16666220, mode: 16877, ... }
  result.stat.isDirectory(); //=> false
});
 
// You can abort matching at any time.
subscription.unsubscribe();

License

ISC License © 2017 Shinnosuke Watanabe

Package Sidebar

Install

npm i glob-observable

Weekly Downloads

1,266

Version

0.8.0

License

ISC

Unpacked Size

8.33 kB

Total Files

4

Last publish

Collaborators

  • shinnn