Skip to content

Instantly share code, notes, and snippets.

@phoenixenero
Last active December 21, 2015 06:19
Show Gist options
  • Save phoenixenero/eac745a07f358eabb213 to your computer and use it in GitHub Desktop.
Save phoenixenero/eac745a07f358eabb213 to your computer and use it in GitHub Desktop.
Creates a new anonymous function that when called, returns a new gulp-if pipe.
// This returns an anonymous function that returns a new gulp-if pipe
// https://github.com/OverZealous/lazypipe#using-with-more-complex-function-arguments-such-as-gulp-if
function lazygulpif( condition, pipeFunction, args ) {
args = ! args ? [] : args;
args = args.constructor === Array ? args : [ args ];
return function() {
return gulpif( condition, pipeFunction.apply( this, args ) );
};
}
// If else version
function lazygulpifelse( condition,
pipeFunction1,
pipeFunction2,
args1,
args2 ) {
args1 = ! args1 ? [] : args1;
args2 = ! args2 ? [] : args2;
args1 = args1.constructor === Array ? args1 : [ args1 ];
args2 = args2.constructor === Array ? args2 : [ args2 ];
return function() {
return gulpif( condition,
pipeFunction1.apply( this, args1 ),
pipeFunction2.apply( this, args2 ) );
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment