Execute passed argument if it is a function.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
LICENSE
package.json
readme.js
test.js
yarn.lock

readme.js

/**
 * execute-if-function
 * --------------
 *
 * Execute passed argument if it is a function.
 *
 * `npm install execute-if-function`
 *  or
 * `yarn add execute-if-function`
 *
 * Example:
 * executeIfFunction(someFunction); // will execute function and return result
 * executeIfFunction(someNonFunction); // will just return back someNonFunction
 *
 */

/**
 * @param {*} fn
 * @returns {*}
 */
var executeIfFunction = function executeIfFunction(fn) {
  return typeof fn === 'function' ? fn() : fn;
};

module.exports = executeIfFunction;