Skip to content

Commit 3310ca3

Browse files
committed
improve readme
1 parent 4163b9a commit 3310ca3

File tree

1 file changed

+34
-36
lines changed

1 file changed

+34
-36
lines changed

readme.md

+34-36
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,41 @@ $ npm install --save-dev gulp-filter
1919
You may want to just filter the stream content:
2020

2121
```js
22-
var gulp = require('gulp');
23-
var jscs = require('gulp-jscs');
24-
var gulpFilter = require('gulp-filter');
22+
const gulp = require('gulp');
23+
const uglify = require('gulp-uglify');
24+
const filter = require('gulp-filter');
2525

26-
gulp.task('default', function () {
26+
gulp.task('default', () => {
2727
// create filter instance inside task function
28-
var filter = gulpFilter(['*', '!src/vendor']);
28+
const f = filter(['*', '!src/vendor']);
2929

3030
return gulp.src('src/*.js')
3131
// filter a subset of the files
32-
.pipe(filter)
32+
.pipe(f)
3333
// run them through a plugin
34-
.pipe(jscs())
34+
.pipe(uglify())
3535
.pipe(gulp.dest('dist'));
3636
});
3737
```
3838

3939
### Restoring filtered files
4040

4141
```js
42-
var gulp = require('gulp');
43-
var jscs = require('gulp-jscs');
44-
var gulpFilter = require('gulp-filter');
42+
const gulp = require('gulp');
43+
const uglify = require('gulp-uglify');
44+
const filter = require('gulp-filter');
4545

46-
gulp.task('default', function () {
46+
gulp.task('default', () => {
4747
// create filter instance inside task function
48-
var filter = gulpFilter(['*', '!src/vendor'], {restore: true});
48+
const f = filter(['*', '!src/vendor'], {restore: true});
4949

5050
return gulp.src('src/*.js')
5151
// filter a subset of the files
52-
.pipe(filter)
52+
.pipe(f)
5353
// run them through a plugin
54-
.pipe(jscs())
54+
.pipe(uglify())
5555
// bring back the previously filtered out files (optional)
56-
.pipe(filter.restore)
56+
.pipe(f.restore)
5757
.pipe(gulp.dest('dist'));
5858
});
5959
```
@@ -63,14 +63,14 @@ gulp.task('default', function () {
6363
By combining and restoring different filters you can process different sets of files with a single pipeline.
6464

6565
```js
66-
var gulp = require('gulp');
67-
var less = require('gulp-less');
68-
var concat = require('gulp-concat');
69-
var gulpFilter = require('gulp-filter');
66+
const gulp = require('gulp');
67+
const less = require('gulp-less');
68+
const concat = require('gulp-concat');
69+
const filter = require('gulp-filter');
7070

71-
gulp.task('default', function () {
72-
var jsFilter = gulpFilter('**/*.js', {restore: true});
73-
var lessFilter = gulpFilter('**/*.less', {restore: true});
71+
gulp.task('default', () => {
72+
const jsFilter = filter('**/*.js', {restore: true});
73+
const lessFilter = filter('**/*.less', {restore: true});
7474

7575
return gulp.src('assets/**')
7676
.pipe(jsFilter)
@@ -88,22 +88,22 @@ gulp.task('default', function () {
8888
You can restore filtered files in a different place and use it as a standalone source of files (ReadableStream). Setting the `passthrough` option to `false` allows you to do so.
8989

9090
```js
91-
var gulp = require('gulp');
92-
var jscs = require('gulp-jscs');
93-
var gulpFilter = require('gulp-filter');
91+
const gulp = require('gulp');
92+
const uglify = require('gulp-uglify');
93+
const filter = require('gulp-filter');
9494

95-
gulp.task('default', function () {
96-
var filter = gulpFilter(['*', '!src/vendor'], {restore: true, passthrough: false});
95+
gulp.task('default', () => {
96+
const f = filter(['*', '!src/vendor'], {restore: true, passthrough: false});
9797

98-
var stream = gulp.src('src/*.js')
98+
const stream = gulp.src('src/*.js')
9999
// filter a subset of the files
100-
.pipe(filter)
100+
.pipe(f)
101101
// run them through a plugin
102-
.pipe(jscs())
102+
.pipe(uglify())
103103
.pipe(gulp.dest('dist'));
104104

105105
// use filtered files as a gulp file source
106-
filter.restore.pipe(gulp.dest('vendor-dist'));
106+
f.restore.pipe(gulp.dest('vendor-dist'));
107107

108108
return stream;
109109
});
@@ -125,9 +125,7 @@ Accepts a string/array with globbing patterns which are run through [multimatch]
125125
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:
126126

127127
```js
128-
filter(function (file) {
129-
return /unicorns/.test(file.path);
130-
});
128+
filter(file => /unicorns/.test(file.path));
131129
```
132130

133131
#### options
@@ -140,14 +138,14 @@ Accepts [minimatch options](https://github.com/isaacs/minimatch#options).
140138

141139
#### options.restore
142140

143-
Type: `boolean`
141+
Type: `boolean`
144142
Default: `false`
145143

146144
Restore filtered files.
147145

148146
#### options.passthrough
149147

150-
Type: `boolean`
148+
Type: `boolean`
151149
Default: `true`
152150

153151
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.

0 commit comments

Comments
 (0)