npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-custom-filter

v0.4.4

Published

A gulp plugin to filter files by customized filters

Downloads

2,059

Readme

gulp-custom-filter

Build Status Coverage Status Code Climate David DM

A gulp plugin to filter files by customized filters.

Install

$ npm install --save-dev gulp-custom-filter

Usage

var filter = require('gulp-custom-filter');
var gulp = require('gulp');
var less = require('gulp-less');

function myFilter(file) {
	return file.basename.startsWith('my_');
}

gulp.task('less', function() {
	return gulp.src('./less/**/*.less')
		.pipe(filter(myFilter))
		.pipe(less())
		.pipe(gulp.dest('./css')
});

This is equivalent to:

var filter = require('gulp-custom-filter');
var gulp = require('gulp');
var less = require('gulp-less');

gulp.task('less', function() {
	return gulp.src('./less/**/my_*.less')
		.pipe(less())
		.pipe(gulp.dest('./css')
});

You may set any predicate function to a vinyl file.

Basic filters

filter.not(fn)

Nagates filter conditions

var not = filter.not;

gulp.src('./less/**/*.less')
	.pipe(filter(not(myFilter)) // will pass files which not satisfy myFilter

This filter passes less files which its name does not start with 'my_'.

filter.and(fn1, fn2, ...)

Passes files which satisfy every filter conditions.

var and = filter.and;

gulp.src('./less/**/*.less')
	.pipe(filter(and(myFilter1, myFilter2)) // will pass files which satisfy myFilter1 and myFilter2

filter.or(fn1, fn2, ...)

Passes files which satisfy at least one of the filter conditions.

var or = filter.or;

gulp.src('./less/**/*.less')
	.pipe(filter(or(myFilter1, myFilter2)) // will pass files which satisfy myFilter1 or myFilter2

filter.all()

Passes every files. This is equivalent function() { return true; }

var all = filter.all;

gulp.src('./less/**/*.less')
	.pipe(filter(all())) // no file will be filtered out.

filter.none()

Passes no file. This is equivalent function() { return false; }

var none = filter.none;

gulp.src('./less/**/*.less')
	.pipe(filter(none())) // no file will be passed.

Filename pattern filters

filter.glob(pattern, options)

Glob pattern filter for file name. Just a wrapper of minimatch.

var glob = filter.glob;

gulp.src('./**/*.*')
	.pipe(filter(glob('./**/*.less'))).
  • pattern: a string or an array of glob pattern.
  • options: optional options.

filter.ignore(filename)

Ignore list filter.

var ignore = filter.ignore;

gulp.src('./**/*.*')
	.pipe(filter(ignore('.gitignore')))
  • filename: filename to ignore file.

Filter development guide

gulp-custom-filter accepts three type of predicate functions.

Simple boolean predicates: function(file, [encode]): boolean

A predicate must have one or two argument(s). It returns a boolean value true/false.

gulp.src('./**/*.*')
	.pipe(filter(function(file, encode) {
		return file.isBuffer();
	});

To fail the predicate, just throw an error.

gulp.src('./**/*.*')
	.pipe(filter(function(file, encode) {
		throw new Error('error');
	});

Asynchronous predicates: function(file, [encode], done: function(err, result)): void

A predicate must have three arguments. The third argument is a callback function to settle a result.

Call done with the second argument of true/false.

gulp.src('./**/*.*')
	.pipe(filter(function(file, encode, done) {
		setTimeout(function() {
			done(null, file.isBuffer()); // 1st argument must be falsy.
		}, 0);
	});

To fail the predicate, call done with the first argument of non-falsy value.

gulp.src('./**/*.*')
	.pipe(filter(function(file, encode, done) {
		setTimeout(function() {
			done(new Error('error'));
		}, 0);
	});

Promise predicates: function(file, done: function(err, result)): Promise.

A predicate must have one or two argument(s). It returns a fulfilling promise of boolean value true/false.

gulp.src('./**/*.*')
	.pipe(filter(function(file, encode) {
		return Promise.resolve(file.isBuffer());
	});

To fail the predicate, return a rejecting promise.

gulp.src('./**/*.*')
	.pipe(filter(function(file, encode) {
		return Promise.reject(new Error('error'));
	});

Release Notes

  • v0.4.4

    • Security updates (library dependency)
  • v0.4.3

    • Update library dependency
  • v0.3.0

    • Update library dependency
    • Update supporting version of Node.js
      • Now we support Node 6 or higher
  • v0.2.5

    • Update supporting version of Node.js
    • Fix assertion error message of or() filter

License