promisen.js
function IF(condTask, trueTask, falseTask) {
    condTask = (condTask != null) ? promisen(condTask) : promisen();
    trueTask = (trueTask != null) ? promisen(trueTask) : promisen();
    falseTask = (falseTask != null) ? promisen(falseTask) : promisen();
    return conditional;

    function conditional(value) {
      var condFunc = condTask.bind(this, value);
      var trueFunc = trueTask.bind(this, value);
      var falseFunc = falseTask.bind(this, value);
      return condFunc().then(switching);

      function switching(condition) {
        return condition ? trueFunc() : falseFunc();
      }
    }
  }
function IF(condTask, trueTask, falseTask) {
    condTask = (condTask != null) ? promisen(condTask) : promisen();
    trueTask = (trueTask != null) ? promisen(trueTask) : promisen();
    falseTask = (falseTask != null) ? promisen(falseTask) : promisen();
    return conditional;

    function conditional(value) {
      var condFunc = condTask.bind(this, value);
      var trueFunc = trueTask.bind(this, value);
      var falseFunc = falseTask.bind(this, value);
      return condFunc().then(switching);

      function switching(condition) {
        return condition ? trueFunc() : falseFunc();
      }
    }
  }
function IF ( condTask , trueTask , falseTask ) { condTask = ( condTask != null ) ? promisen ( condTask ) : promisen ( ) ; trueTask = ( trueTask != null ) ? promisen ( trueTask ) : promisen ( ) ; falseTask = ( falseTask != null ) ? promisen ( falseTask ) : promisen ( ) ; return conditional ; function conditional ( value ) { var condFunc = condTask . bind ( this , value ) ; var trueFunc = trueTask . bind ( this , value ) ; var falseFunc = falseTask . bind ( this , value ) ; return condFunc ( ) . then ( switching ) ; function switching ( condition ) { return condition ? trueFunc ( ) : falseFunc ( ) ; } } }
creates a promise-returning function which runs a task assigned by a conditional task.

When null or undefined is given as a task, it will do nothing for value and just passes it.

@class promisen
@static
@function if
@param [condTask] {Boolean|Function|Promise|thenable|*|null} boolean or function returns boolean
@param [trueTask] {Function|Promise|thenable|*|null} task runs when true
@param [falseTask] {Function|Promise|thenable|*|null} task runs when false
@returns {Function} promise-returning function
@example
var promisen = require("promisen");

// generate a promise-returning function
var task = promisen.if(condTask, trueTask, falseTask);

// execute itl[pi?K  jk ln lml;/,   m /P/.[h
task().then(function(result) {...});

// execute it with target object which is passed to every tasks
task.call(target).then(function(result) {...});

// all three arguments are optional.
var runWhenTrueTask = promisen.if(null, trueTask);
Promise.resolve(value).then(runWhenTrueTask).then(function(result) {...});

// conditional task are also available in a waterfall of promisen tasks
var joined = promisen(task1, runWhenTrueTask, task2);
joined().then(function(result) {...});

// use uglify --compress (or UPPERCASE property name) for IE8
var task = promisen["if"](condTask, trueTask, falseTask);
var task = promisen.IF(condTask, trueTask, falseTask);
creates a promise - returning function which runs a task assigned by a conditional task .