All Projects → sindresorhus → Gulp Filter

sindresorhus / Gulp Filter

Licence: mit
Filter files in a `vinyl` stream

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Gulp Filter

booleval
Header-only C++17 library for evaluating logical expressions.
Stars: ✭ 54 (-82.47%)
Mutual labels:  filter
Graphql To Mongodb
Allows for generic run-time generation of filter types for existing graphql types and parsing client requests to mongodb find queries
Stars: ✭ 261 (-15.26%)
Mutual labels:  filter
Angular Filter
Bunch of useful filters for AngularJS (with no external dependencies!)
Stars: ✭ 2,962 (+861.69%)
Mutual labels:  filter
jog
Command line tool to view structured(JSON) log like 'tail -f', with filtering by log level and time range
Stars: ✭ 16 (-94.81%)
Mutual labels:  filter
GPUImage FilterVideo
录制美颜视频
Stars: ✭ 12 (-96.1%)
Mutual labels:  filter
Gridjs
Advanced table plugin
Stars: ✭ 3,231 (+949.03%)
Mutual labels:  filter
VBA-Arrays
😎 Array functions that are similar JavaScript functions. Example: Push, Pop, Shift, Unshift, Sort, length, toString.
Stars: ✭ 48 (-84.42%)
Mutual labels:  filter
Kalmanjs
Javascript based Kalman filter for 1D data
Stars: ✭ 298 (-3.25%)
Mutual labels:  filter
Jschema
A simple, easy to use data modeling framework for JavaScript
Stars: ✭ 261 (-15.26%)
Mutual labels:  filter
Gulp Template
Render/precompile Lodash templates
Stars: ✭ 276 (-10.39%)
Mutual labels:  gulp-plugin
FilterDrawer
Android plug-and-play filter that slides
Stars: ✭ 17 (-94.48%)
Mutual labels:  filter
gulp-markdown-to-json
Parse Markdown and YAML → compile Markdown to HTML → wrap it all up in JSON
Stars: ✭ 76 (-75.32%)
Mutual labels:  gulp-plugin
Gulp Inline Css
Inline linked css in an html file. Useful for emails.
Stars: ✭ 264 (-14.29%)
Mutual labels:  gulp-plugin
filter
⏳ Provide filtering, sanitizing, and conversion of Golang data. 提供对Golang数据的过滤,净化,转换。
Stars: ✭ 53 (-82.79%)
Mutual labels:  filter
Panflute
An Pythonic alternative to John MacFarlane's pandocfilters, with extra helper functions
Stars: ✭ 286 (-7.14%)
Mutual labels:  filter
pikaso
Seamless and headless HTML5 Canvas library
Stars: ✭ 23 (-92.53%)
Mutual labels:  filter
Gulp Zip
ZIP compress files
Stars: ✭ 262 (-14.94%)
Mutual labels:  gulp-plugin
React Search Input
🔍 Simple react.js component for a search input, providing a filter function.
Stars: ✭ 300 (-2.6%)
Mutual labels:  filter
Sensitive
敏感词查找,验证,过滤和替换 🤓 FindAll, Validate, Filter and Replace words.
Stars: ✭ 292 (-5.19%)
Mutual labels:  filter
Hypermark
Markdown for Humans.
Stars: ✭ 266 (-13.64%)
Mutual labels:  filter

gulp-filter

Filter files in a vinyl stream

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.

Install

$ npm install --save-dev gulp-filter

Usage

Filter only

You may want to just filter the stream content:

const gulp = require('gulp');
const uglify = require('gulp-uglify');
const filter = require('gulp-filter');

exports.default = () => {
	// Create filter instance inside task function
	const f = filter(['**', '!*src/vendor']);

	return gulp.src('src/**/*.js')
		// Filter a subset of the files
		.pipe(f)
		// Run them through a plugin
		.pipe(uglify())
		.pipe(gulp.dest('dist'));
};

Restoring filtered files

const gulp = require('gulp');
const uglify = require('gulp-uglify');
const filter = require('gulp-filter');

exports.default = () => {
	// Create filter instance inside task function
	const f = filter(['**', '!*src/vendor'], {restore: true});

	return gulp.src('src/**/*.js')
		// Filter a subset of the files
		.pipe(f)
		// Run them through a plugin
		.pipe(uglify())
		// Bring back the previously filtered out files (optional)
		.pipe(f.restore)
		.pipe(gulp.dest('dist'));
};

Multiple filters

By combining and restoring different filters you can process different sets of files with a single pipeline.

const gulp = require('gulp');
const less = require('gulp-less');
const concat = require('gulp-concat');
const filter = require('gulp-filter');

exports.default = () => {
	const jsFilter = filter('**/*.js', {restore: true});
	const lessFilter = filter('**/*.less', {restore: true});

	return gulp.src('assets/**')
		.pipe(jsFilter)
		.pipe(concat('bundle.js'))
		.pipe(jsFilter.restore)
		.pipe(lessFilter)
		.pipe(less())
		.pipe(lessFilter.restore)
		.pipe(gulp.dest('out/'));
};

Restore as a file source

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.

const gulp = require('gulp');
const uglify = require('gulp-uglify');
const filter = require('gulp-filter');

exports.default = () => {
	const f = filter(['**', '!*src/vendor'], {restore: true, passthrough: false});

	const stream = gulp.src('src/**/*.js')
		// Filter a subset of the files
		.pipe(f)
		// Run them through a plugin
		.pipe(uglify())
		.pipe(gulp.dest('dist'));

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

	return stream;
};

API

filter(pattern, options?)

Returns a transform stream with a .restore property.

pattern

Type: string | string[] | Function

Accepts a string/array with globbing patterns which are run through multimatch.

If you supply a function, you'll get a vinyl file object as the first argument and you're expected to return a boolean of whether to include the file:

filter(file => /unicorns/.test(file.path));

options

Type: object

Accepts minimatch options.

Note: Set dot: true if you need to match files prefixed with a dot, for example, .gitignore.

restore

Type: boolean
Default: false

Restore filtered files.

passthrough

Type: boolean
Default: true

When set to true, filtered files are restored with a stream.PassThrough, otherwise, when set to false, filtered files are restored as a stram.Readable.

When the stream is a stream.Readable, it ends by itself, but when it's stream.PassThrough, you are responsible of ending the stream.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].