carvalholeo/generator-dh

View on GitHub
src/utils/before.js

Summary

Maintainability
A
0 mins
Test Coverage
/**
 * Install a before function; AOP.
 * @param {object} obj Commander instance to be used.
 * @param {string} method Name of the method to be apllied
 * @param {function} fn Callback to be called when function finish
 * @return {void}
 */

function before (obj, method, fn) {
  const old = obj[method]

  obj[method] = function () {
    fn.call(this)
    old.apply(this, arguments)
  }
}

module.exports = before