dist/functions.js
function cautiouslyApply(
item,
fns,
log = true,
keepOldValueOnFalseyReturn = false)
{
  if (fns && Array.isArray(fns)) {
    fns.forEach(fn => {
      try {
        let bindFunctor = Array.isArray(fn) && fn[1];
        let functor = bindFunctor ?
        fn[0].bind(item) :
        Array.isArray(fn) ? fn[0] : fn;

        if (keepOldValueOnFalseyReturn)
        item = functor(item) || item;else

        item = functor(item);
      }
      catch (error) {
        if (log) {
          console.error(error);
        }
      }
    });
  }

  return item;
}
function cautiouslyApply(
item,
fns,
log = true,
keepOldValueOnFalseyReturn = false)
{
  if (fns && Array.isArray(fns)) {
    fns.forEach(fn => {
      try {
        let bindFunctor = Array.isArray(fn) && fn[1];
        let functor = bindFunctor ?
        fn[0].bind(item) :
        Array.isArray(fn) ? fn[0] : fn;

        if (keepOldValueOnFalseyReturn)
        item = functor(item) || item;else

        item = functor(item);
      }
      catch (error) {
        if (log) {
          console.error(error);
        }
      }
    });
  }

  return item;
}
function cautiouslyApply ( item , fns , log = true , keepOldValueOnFalseyReturn = false ) { if ( fns && Array . isArray ( fns ) ) { fns . forEach ( fn => { try { let bindFunctor = Array . isArray ( fn ) && fn [ 1 ] ; let functor = bindFunctor ? fn [ 0 ] . bind ( item ) : Array . isArray ( fn ) ? fn [ 0 ] : fn ; if ( keepOldValueOnFalseyReturn ) item = functor ( item ) || item ; else item = functor ( item ) ; } catch ( error ) { if ( log ) { console . error ( error ) ; } } } ) ; } return item ; }
Given an item that needs to be modified or replaced, the function takes
an array of functions to run in order, each receiving the last state of the
item. If an exception occurs during function execution the value passed is
the value that is kept.

Optionally, when the function executes and returns the newly modified state
of the object in question, if that value is falsey it can be replaced with
the original value passed to the function instead. This is not true by
default

`fns` is an array of functions, but any of the functions in the list are
actually a tuple matching [Function, boolean] **and** the boolean value is
true then the function within will be bound to the item it is operating on
as the `this` context for its execution before processing the value. It will
still receive the item as the first parameter as well.

**NOTE: this will not work on big arrow functions**

@param {mixed} item any JavaScript value
@param {Array<Function>} fns an array of `Function` objects that are to be
executed with the supplied `item` as its input and the new value as its
output. An error or fals
@param {boolean} log true if any errors caused by function execution should
be logged
@param {boolean} keepOldValueOnFalseyReturn if true and the functor returns
a falsey value, the value passed to it as a parameter is used instead
@return {mixed} the new value to replace the one supplied as `item`
Given an item that needs to be modified or replaced the function takes an array of functions to run in order each receiving the last state of the item . If an exception occurs during function execution the value passed is the value that is kept .