🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

glob-fs

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glob-fs - npm Package Compare versions

Comparing version

to
0.1.2

1

index.js

@@ -89,2 +89,3 @@ 'use strict';

// if middleware are registered, use the glob, otherwise regex
var glob = this.fns.length

@@ -91,0 +92,0 @@ ? this.pattern.glob

2

lib/filter.js
'use strict';
var mm = require('minimatch');
var mm = require('micromatch');

@@ -5,0 +5,0 @@ module.exports = function (app) {

'use strict';
var mm = require('minimatch');
module.exports = function (app) {

@@ -18,4 +16,3 @@ app.visit('mixin', {

}
});
};

@@ -160,2 +160,3 @@ 'use strict';

self.count++;
self.emit('include', file);
stream.write(file);

@@ -217,9 +218,2 @@ }

});
// return stats(fp).then(function (stat) {
// if (stat.isDirectory()) {
// return this.iteratorPromise(fp);
// }
// return fp;
// });
})

@@ -234,59 +228,1 @@

};
// module.exports = function lookup(dir, fn, recurse, cb) {
// if (typeof recurse !== 'boolean') {
// cb = recurse;
// recurse = true;
// }
// if (arguments.length === 2) {
// cb = fn;
// fn = null;
// }
// fn = Array.isArray(fn) ? fn : [fn];
// fs.exists(dir, function(exists) {
// if (!exists) {
// return cb(null, []);
// }
// fs.readdir(dir, function(err, files) {
// if (err) {
// return cb(err);
// }
// files = fn.reduce(function(acc, cb) {
// return filter(acc, dir, cb, recurse);
// }, files);
// var res = [];
// async.map(files, function(fp, next) {
// fp = path.join(dir, fp);
// fs.stat(fp, function(err, stats) {
// if (err) {
// return handle(err, next);
// }
// if (!stats.isDirectory()) {
// next(null, res.push(fp));
// } else {
// lookup(fp, fn, function(err, matches) {
// res = res.concat(matches);
// next(null, res);
// });
// }
// });
// }, function(err) {
// cb(err, res);
// });
// });
// });
// };
// function handle(err, next) {
// return (err.code !== 'ENOENT')
// ? next(err)
// : next();
// }
'use strict';
var gitignore = require('../middleware/gitignore');
var gitignore = require('glob-fs-gitignore');
var dotfiles = require('glob-fs-dotfiles');
/**
* Default middleware
* Built-in middleware
*/
module.exports = function (app) {
app.use(gitignore(app.options));
if (app.options.builtins !== false) {
app.use(gitignore(app.options));
app.use(dotfiles(app.options));
}
};
'use strict';
var path = require('path');
var mm = require('minimatch');
var mm = require('micromatch');
var isGlob = require('is-glob');

@@ -46,6 +46,6 @@ var parent = require('glob-parent');

pattern = pattern.slice(1);
this.negated = true;
}
this.negated = true;
}
this.parent = parent(pattern);
this.base = path.join(cwd, this.parent);
this.base = path.join(cwd, this.parent);
pattern = this.normalizePattern(pattern);

@@ -52,0 +52,0 @@ }

'use strict';
// function any(fp, patterns, options) {
// options = options || {};
// var res = {is: [], isnt: []};
// res.file = fp;
// var len = patterns.length;
// var i = -1;
var mm = require('micromatch');
// while (++i < len) {
// var pattern = patterns[i];
// if (mm.isMatch(fp, pattern, {dot: true, contains: true})) {
// res.is.push(pattern);
// break;
// } else {
// res.isnt.push(pattern);
// }
// }
// return res;
// }
module.exports = function any(fp, patterns, options) {
options = options || {};
var res = {is: [], isnt: []};
res.file = fp;
var len = patterns.length;
var i = -1;
// var ignored = gitignore('.gitignore');
while (++i < len) {
var pattern = patterns[i];
if (mm.isMatch(fp, pattern, {dot: true, contains: true})) {
res.is.push(pattern);
break;
} else {
res.isnt.push(pattern);
}
}
return res;
};

@@ -24,0 +24,0 @@ // console.log(any('node_modules', ignored));

@@ -6,2 +6,10 @@ 'use strict';

/**
* Unignore a previously-ignored file. The below code is not a good solution,
* it's just a reminder while this is WIP
*
* @param {String} `pattern`
* @return {Object}
*/
module.exports = function (pattern, options) {

@@ -20,9 +28,2 @@ var opts = extend({ matchBase: true }, options);

/**
* Unignore a previously-ignored file.
*
* @param {String} `pattern`
* @return {Object}
*/
module.exports.exclude = function (pattern) {

@@ -29,0 +30,0 @@ for (var key in this.excludes) {

{
"name": "glob-fs",
"description": "file globbing, for node.js.",
"version": "0.1.0",
"description": "file globbing for node.js. speedy and powerful alternative to node-glob.",
"version": "0.1.2",
"homepage": "https://github.com/jonschlinkert/glob-fs",

@@ -30,6 +30,6 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

"extend-shallow": "^2.0.0",
"glob-fs-dotfiles": "^0.1.1",
"glob-fs-gitignore": "^0.1.0",
"glob-parent": "^1.2.0",
"graceful-fs": "^4.1.2",
"is-dotdir": "^0.1.0",
"is-dotfile": "^1.0.1",
"is-glob": "^2.0.0",

@@ -39,6 +39,4 @@ "kind-of": "^2.0.0",

"micromatch": "^2.1.6",
"minimatch": "^2.0.8",
"object-visit": "^0.1.0",
"object.omit": "^1.1.0",
"parse-gitignore": "^0.1.2",
"through2": "^2.0.0"

@@ -45,0 +43,0 @@ },

# glob-fs [![NPM version](https://badge.fury.io/js/glob-fs.svg)](http://badge.fury.io/js/glob-fs)
> node.js file globber.
> file globbing for node.js. speedy and powerful alternative to node-glob.
## TODO
## Usage
* [ ] Multiple pattern support
* [ ] Negation patterns (might not do this, since it can be handled in middleware)
* [x] middleware
* [x] middleware handler
* [ ] externalize middleware to modules ([prs welcome!](#contributing))
* [x] events
* [x] sync iterator
* [x] async iterator
* [x] stream iterator
* [ ] promise iterator
* [x] glob.readdir (async)
* [x] glob.readdirSync
* [x] glob.readdirStream
* [ ] glob.readdirPromise
```js
var glob = require('glob-fs')({ gitignore: true });
var files = glob.readdirSync('**/*.js');
```
[Run actual examples](./examples/):
Jump to docs sections:
* [glob.readdir](#async)
* [glob.readPromise](#promise)
* [glob.readStream](#stream)
* [glob.readdirSync](#sync)
## Table of contents
<!-- toc -->
* [Install](#install)
* [Usage](#usage)
* [API](#api)
* [Middleware](#middleware)
- [Middleware examples](#middleware-examples)
- [Middleware conventions](#middleware-conventions)
* [Globbing examples](#globbing-examples)
- [async](#async)
- [promise](#promise)
- [stream](#stream)
- [sync](#sync)
* [Events](#events)
- [Event examples](#event-examples)
* [TODO](#todo)
* [Related projects](#related-projects)
* [Running tests](#running-tests)
* [Contributing](#contributing)
* [Author](#author)
* [License](#license)
_(Table of contents generated by [verb](https://github.com/assemble/verb))_
<!-- tocstop -->
## Install

@@ -32,4 +59,26 @@

**Params**
All "read" methods take a glob pattern and an `options` object. Examples:
```js
var glob = require('glob-fs');
// sync
var files = glob.readdirSync('*.js', {});
// async
glob.readdir('*.js', function(err, files) {
console.log(files);
});
// stream
glob.readdirStream('*.js', {})
.on('data', function(file) {
console.log(file);
});
// promise
glob.readdirPromise('*.js')
.then(function(files) {
console.log(file);
});
```

@@ -118,3 +167,3 @@

### [.exclude](index.js#L155)
### [.exclude](index.js#L156)

@@ -141,3 +190,3 @@ Thin wrapper around `.use()` for easily excluding files or directories that match the given `pattern`.

### [.use](index.js#L194)
### [.use](index.js#L195)

@@ -163,32 +212,49 @@ Add a middleware to be called in the order defined.

## Related projects
## Middleware
* [braces](https://github.com/jonschlinkert/braces): Fastest brace expansion for node.js, with the most complete support for the Bash 4.3 braces… [more](https://github.com/jonschlinkert/braces)
* [fill-range](https://github.com/jonschlinkert/fill-range): Fill in a range of numbers or letters, optionally passing an increment or multiplier to… [more](https://github.com/jonschlinkert/fill-range)
* [is-glob](https://github.com/jonschlinkert/is-glob): Returns `true` if the given string looks like a glob pattern.
* [micromatch](https://github.com/jonschlinkert/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. Just… [more](https://github.com/jonschlinkert/micromatch)
glob-fs uses middleware to add file matching and exclusion capabilities, or other features that may or may not eventually become core functionality.
## Running tests
**What is a middleware?**
Install dev dependencies:
A middleware is a function that "processes" files as they're read from the file system by glob-fs.
```sh
$ npm i -d && npm test
```
**What does "process" mean?**
## Contributing
Typically, it means one of the following:
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/glob-fs/issues/new).
1. matching a `file.path`, or
2. modifying a property on the `file` object, or
3. determining whether or not to continue recursing
### Middleware conventions
### Middleware examples
* **Naming**: any middleware published to npm should be prefixed with `glob-fs-`, as in: `glob-fs-dotfiles`.
* **Keywords**: please add `glob-fs` to the keywords array in package.json
* **Options**: all middleware should return a function that takes an `options` object, as in the below [Middleware Example](#middleware-example)
* **Return `file`**: all middleware should return the `file` object after processing.
**recursing**
### Middleware example
Here is how a middleware might determine whether or not to recurse based on a glob pattern:
All middleware runs synchronously in the order in which it's defined by the user.
```js
var glob = require('glob-fs');
// this is already handled by glob-fs, but it
// makes a good example
function recurse() {
return function(file) {
// `file.pattern` is an object with a `glob` (string) property
file.recurse = file.pattern.glob.indexOf('**') !== -1;
return file;
}
}
// use the middleware
glob()
.use(recurse())
.readdir('**/*.js', function(err, files) {
console.log(files);
});
```
**exclusion**
Middleware for excluding file paths:
```js

@@ -216,2 +282,208 @@ // `notests` middleware to exclude any file in the `test` directory

### Middleware conventions
* **Naming**: any middleware published to npm should be prefixed with `glob-fs-`, as in: `glob-fs-dotfiles`.
* **Keywords**: please add `glob-fs` to the keywords array in package.json
* **Options**: all middleware should return a function that takes an `options` object, as in the [Middleware Example](#middleware-example)
* **Return `file`**: all middleware should return the `file` object after processing.
## Globbing examples
Note that the `gitignore` option is already `true` by default, it's just shown here as a placeholder for how options may be defined.
### async
```js
var glob = require('glob-fs')({ gitignore: true });
glob.readdir('**/*.js', function(err, files) {
console.log(files);
});
```
### promise
```js
var glob = require('glob-fs')({ gitignore: true });
glob.readdirPromise('**/*')
.then(function (files) {
console.log(files);
});
```
### stream
```js
var glob = require('glob-fs')({ gitignore: true });
glob.readdirStream('**/*')
.on('data', function (file) {
console.log(file.path);
})
```
### sync
```js
var glob = require('glob-fs')({ gitignore: true });
var files = glob.readdirSync('**/*.js');
console.log(files);
```
## Events
_(WIP)_
The following events are emitted with all "read" methods:
* `include`: emits a `file` object when it's matched
* `exclude`: emits a `file` object when it's ignored/excluded
* `file`: emits a `file` object when the iterator pushes it into the results array. Only applies to `sync`, `async` and `promise`.
* `dir`: emits a `file` object when the iterator finds a directory
* `end` when the iterator is finished reading
* `error` on errors
### Event examples
**async**
```js
var glob = require('..')({ gitignore: true });
glob.on('dir', function (file) {
console.log(file);
});
glob.readdir('**/*.js', function (err, files) {
if (err) return console.error(err);
console.log(files.length);
});
```
**promise**
```js
var glob = require('glob-fs')({ gitignore: true });
glob.on('include', function (file) {
console.log('including:', file.path);
});
glob.on('exclude', function (file) {
console.log('excluding:', file.path);
});
glob.readdirPromise('**/*');
```
**sync**
Also has an example of a custom event, emitted from a middleware:
```js
var glob = require('glob-fs')({ gitignore: true })
.use(function (file) {
if (/\.js$/.test(file.path)) {
// custom event
this.emit('js', file);
}
return file;
});
glob.on('js', function (file) {
console.log('js file:', file.path);
});
glob.on('exclude', function (file) {
console.log('excluded:', i.excludes++);
});
glob.on('include', function (file) {
console.log('included:', i.includes++)
});
glob.on('end', function () {
console.log('total files:', this.files.length);
});
glob.readdirSync('**/*.js');
```
**stream**
```js
var glob = require('glob-fs')({ gitignore: true })
glob.readdirStream('**/*')
.on('data', function (file) {
console.log(file.path)
})
.on('error', console.error)
.on('end', function () {
console.log('end');
});
```
## TODO
**middleware**
* [x] middleware
* [x] middleware handler
* [ ] externalize middleware to modules (started, [prs welcome!](#contributing))
**events**
* [x] events
**tests**
* [x] unit tests (need to be moved)
**iterators**
* [x] sync iterator
* [x] async iterator
* [x] stream iterator
* [x] promise iterator
**read methods**
* [x] glob.readdir (async)
* [x] glob.readdirSync
* [x] glob.readdirStream
* [x] glob.readdirPromise
**patterns**
* [ ] Multiple pattern support. will need to change pattern handling, middleware handling. this is POC currently
* [ ] Negation patterns (might not do this, since it can be handled in middleware)
* [ ] matching method, memoized/cached/bound to a glob pattern or patterns, so it can be reused without having to recompile the regex.
**other**
* [ ] clean up `./lib`
* [ ](https://github.com/isaacs/node-glob/)[] comparison
## Related projects
* [braces](https://github.com/jonschlinkert/braces): Fastest brace expansion for node.js, with the most complete support for the Bash 4.3 braces… [more](https://github.com/jonschlinkert/braces)
* [fill-range](https://github.com/jonschlinkert/fill-range): Fill in a range of numbers or letters, optionally passing an increment or multiplier to… [more](https://github.com/jonschlinkert/fill-range)
* [is-glob](https://github.com/jonschlinkert/is-glob): Returns `true` if the given string looks like a glob pattern.
* [micromatch](https://github.com/jonschlinkert/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. Just… [more](https://github.com/jonschlinkert/micromatch)
## Running tests
Install dev dependencies:
```sh
$ npm i -d && npm test
```
## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/glob-fs/issues/new)
## Author

@@ -231,2 +503,2 @@

_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on July 07, 2015._
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on July 09, 2015._