Socket
Socket
Sign inDemoInstall

gulp-filter

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-filter

Filter files in a vinyl stream


Version published
Weekly downloads
140K
increased by4.02%
Maintainers
1
Weekly downloads
 
Created

What is gulp-filter?

The gulp-filter package is a plugin for Gulp, a streaming build system. It allows you to filter files in a vinyl stream based on a given criteria, enabling you to include or exclude files from further processing in your Gulp tasks.

What are gulp-filter's main functionalities?

Filtering files by glob patterns

This feature allows you to filter files in a stream using glob patterns. In this example, only JavaScript files are passed through the filter and then written to the 'dist/js' directory.

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

const jsFilter = filter('**/*.js', { restore: true });

gulp.task('scripts', function() {
  return gulp.src('src/**/*')
    .pipe(jsFilter)
    .pipe(gulp.dest('dist/js'))
    .pipe(jsFilter.restore);
});

Restoring filtered files

This feature allows you to restore the filtered files back into the stream after processing. In this example, after processing JavaScript files, the rest of the files are written to the 'dist/others' directory.

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

const jsFilter = filter('**/*.js', { restore: true });

gulp.task('scripts', function() {
  return gulp.src('src/**/*')
    .pipe(jsFilter)
    .pipe(gulp.dest('dist/js'))
    .pipe(jsFilter.restore)
    .pipe(gulp.dest('dist/others'));
});

Filtering files by custom function

This feature allows you to filter files using a custom function. In this example, only JavaScript files containing the string 'use strict' are passed through the filter and then written to the 'dist/strict' directory.

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

const customFilter = filter(function(file) {
  return file.contents.toString().indexOf('use strict') !== -1;
});

gulp.task('strict', function() {
  return gulp.src('src/**/*.js')
    .pipe(customFilter)
    .pipe(gulp.dest('dist/strict'));
});

Other packages similar to gulp-filter

Keywords

FAQs

Package last updated on 21 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc