Skip to content

Commit

Permalink
fix negate patterns not working - fixes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jan 15, 2014
1 parent 2816b0b commit db4d797
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 16 deletions.
15 changes: 2 additions & 13 deletions index.js
@@ -1,7 +1,7 @@
'use strict';
var gutil = require('gulp-util');
var through = require('through');
var minimatch = require('minimatch');
var multimatch = require('multimatch');

module.exports = function (pattern) {
pattern = typeof pattern === 'string' ? [pattern] : pattern;
Expand All @@ -15,18 +15,7 @@ module.exports = function (pattern) {
return this.emit('error', new PluginError('gulp-filter', 'Streaming not supported'));
}

var match = false;

if (typeof pattern === 'function') {
match = pattern(file);
} else {
for (var i = 0; i < pattern.length; i++) {
if (minimatch(file.path, pattern[i])) {
match = true;
break;
}
}
}
var match = typeof pattern === 'function' ? pattern(file) : multimatch(file.path, pattern).length > 0;

if (match) {
return this.queue(file);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -32,7 +32,7 @@
"dependencies": {
"gulp-util": "~2.2.0",
"through": "~2.3.4",
"minimatch": "~0.2.14"
"multimatch": "~0.1.0"
},
"devDependencies": {
"mocha": "*"
Expand Down
3 changes: 1 addition & 2 deletions readme.md
Expand Up @@ -42,7 +42,7 @@ gulp.task('default', function () {

Type: `String`|`Array`|`Function`

Accepts a string/array with globbing patterns which are run through [minimatch](https://github.com/isaacs/minimatch).
Accepts a string/array with globbing patterns which are run through [multimatch](https://github.com/sindresorhus/multimatch).

If you supply a function you'll get a [vinyl file object](https://github.com/wearefractal/vinyl#file) as the first argument and you're expected to return true/false whether to include the file:

Expand All @@ -52,7 +52,6 @@ filter(function (file) {
});
```


### filter.end()

Resets the filter and brings back the previously filtered out files.
Expand Down

0 comments on commit db4d797

Please sign in to comment.