Skip to content

Commit 835efdf

Browse files
committed
ES2015ify and require Node.js 4
1 parent f148c7b commit 835efdf

File tree

6 files changed

+121
-116
lines changed

6 files changed

+121
-116
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
* text=auto
2+
*.js text eol=lf

.travis.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
sudo: false
22
language: node_js
33
node_js:
4-
- '5'
4+
- '6'
55
- '4'
6-
- '0.12'
7-
- '0.10'

index.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
'use strict';
2-
var path = require('path');
3-
var gutil = require('gulp-util');
4-
var multimatch = require('multimatch');
5-
var streamfilter = require('streamfilter');
2+
const path = require('path');
3+
const gutil = require('gulp-util');
4+
const multimatch = require('multimatch');
5+
const streamfilter = require('streamfilter');
66

7-
module.exports = function (pattern, options) {
7+
module.exports = (pattern, options) => {
88
pattern = typeof pattern === 'string' ? [pattern] : pattern;
99
options = options || {};
1010

1111
if (!Array.isArray(pattern) && typeof pattern !== 'function') {
1212
throw new gutil.PluginError('gulp-filter', '`pattern` should be a string, array, or function');
1313
}
1414

15-
return streamfilter(function (file, enc, cb) {
16-
var match;
15+
return streamfilter((file, enc, cb) => {
16+
let match;
17+
1718
if (typeof pattern === 'function') {
1819
match = pattern(file);
1920
} else {
20-
var relPath = path.relative(file.cwd, file.path);
21-
// if the path leaves the current working directory, then we need to
21+
let relPath = path.relative(file.cwd, file.path);
22+
23+
// If the path leaves the current working directory, then we need to
2224
// resolve the absolute path so that the path can be properly matched
2325
// by minimatch (via multimatch)
2426
if (relPath.indexOf('../') === 0) {
2527
relPath = path.resolve(relPath);
2628
}
29+
2730
match = multimatch(relPath, pattern, options).length > 0;
2831
}
2932

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "gulp-filter",
33
"version": "4.0.0",
4-
"description": "Filter files in a vinyl stream",
4+
"description": "Filter files in a Vinyl stream",
55
"license": "MIT",
66
"repository": "sindresorhus/gulp-filter",
77
"author": {
@@ -10,7 +10,7 @@
1010
"url": "sindresorhus.com"
1111
},
1212
"engines": {
13-
"node": ">=0.10.0"
13+
"node": ">=4"
1414
},
1515
"scripts": {
1616
"test": "xo && mocha"
@@ -37,5 +37,8 @@
3737
"devDependencies": {
3838
"mocha": "*",
3939
"xo": "*"
40+
},
41+
"xo": {
42+
"esnext": true
4043
}
4144
}

readme.md

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# gulp-filter [![Build Status](https://travis-ci.org/sindresorhus/gulp-filter.svg?branch=master)](https://travis-ci.org/sindresorhus/gulp-filter)
22

3-
> Filter files in a [vinyl](https://github.com/wearefractal/vinyl) stream
3+
> Filter files in a [Vinyl](https://github.com/gulpjs/vinyl) stream
44
5-
Enables you to work on a subset of the original files by filtering them using globbing. When you're done and want all the original files back you just use the `restore` stream.
5+
Enables you to work on a subset of the original files by filtering them using glob patterns. When you're done and want all the original files back you just use the `restore` stream.
66

77

88
## Install
@@ -24,13 +24,13 @@ const uglify = require('gulp-uglify');
2424
const filter = require('gulp-filter');
2525

2626
gulp.task('default', () => {
27-
// create filter instance inside task function
27+
// Create filter instance inside task function
2828
const f = filter(['**', '!*src/vendor']);
2929

3030
return gulp.src('src/**/*.js')
31-
// filter a subset of the files
31+
// Filter a subset of the files
3232
.pipe(f)
33-
// run them through a plugin
33+
// Run them through a plugin
3434
.pipe(uglify())
3535
.pipe(gulp.dest('dist'));
3636
});
@@ -44,15 +44,15 @@ const uglify = require('gulp-uglify');
4444
const filter = require('gulp-filter');
4545

4646
gulp.task('default', () => {
47-
// create filter instance inside task function
47+
// Create filter instance inside task function
4848
const f = filter(['**', '!*src/vendor'], {restore: true});
4949

5050
return gulp.src('src/**/*.js')
51-
// filter a subset of the files
51+
// Filter a subset of the files
5252
.pipe(f)
53-
// run them through a plugin
53+
// Run them through a plugin
5454
.pipe(uglify())
55-
// bring back the previously filtered out files (optional)
55+
// Bring back the previously filtered out files (optional)
5656
.pipe(f.restore)
5757
.pipe(gulp.dest('dist'));
5858
});
@@ -96,13 +96,13 @@ gulp.task('default', () => {
9696
const f = filter(['**', '!*src/vendor'], {restore: true, passthrough: false});
9797

9898
const stream = gulp.src('src/**/*.js')
99-
// filter a subset of the files
99+
// Filter a subset of the files
100100
.pipe(f)
101-
// run them through a plugin
101+
// Run them through a plugin
102102
.pipe(uglify())
103103
.pipe(gulp.dest('dist'));
104104

105-
// use filtered files as a gulp file source
105+
// Use filtered files as a gulp file source
106106
f.restore.pipe(gulp.dest('vendor-dist'));
107107

108108
return stream;
@@ -114,43 +114,43 @@ gulp.task('default', () => {
114114

115115
### filter(pattern, [options])
116116

117-
Returns a [transform stream](http://nodejs.org/api/stream.html#stream_class_stream_transform) with a [.restore](#optionsrestore) object.
117+
Returns a [transform stream](http://nodejs.org/api/stream.html#stream_class_stream_transform) with a [.restore](#optionsrestore) property.
118118

119119
#### pattern
120120

121-
Type: `string`, `array`, `function`
121+
Type: `string` `Array` `Function`
122122

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

125-
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:
125+
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 a boolean of whether to include the file:
126126

127127
```js
128128
filter(file => /unicorns/.test(file.path));
129129
```
130130

131131
#### options
132132

133-
Type: `object`
133+
Type: `Object`
134134

135135
Accepts [minimatch options](https://github.com/isaacs/minimatch#options).
136136

137-
*Note:* Set `dot: true` if you need to match files prefixed with a dot (eg. `.gitignore`).
137+
*Note:* Set `dot: true` if you need to match files prefixed with a dot (e.g. `.gitignore`).
138138

139-
#### options.restore
139+
##### restore
140140

141141
Type: `boolean`<br>
142142
Default: `false`
143143

144144
Restore filtered files.
145145

146-
#### options.passthrough
146+
##### passthrough
147147

148148
Type: `boolean`<br>
149149
Default: `true`
150150

151-
When set to `true` filtered files are restored with a PassThrough stream, otherwise, when set to `false`, filtered files are restored as a Readable stream.
151+
When set to `true`, filtered files are restored with a `PassThrough` stream, otherwise, when set to `false`, filtered files are restored as a `ReadableStream`.
152152

153-
When the stream is Readable it ends by itself, but when PassThrough, you are responsible of ending the stream.
153+
When the stream is a `ReadableStream`, it ends by itself, but when it's `PassThrough`, you are responsible of ending the stream.
154154

155155

156156
## License

0 commit comments

Comments
 (0)