rangoo94/easen-tools

View on GitHub
packages/core/src/utils/mutateActionParams.js

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
/**
 * Prepare middleware to mutate action params.
 *
 * @param {function} fn
 * @returns {function(object): object}
 */
function mutateActionParams (fn) {
  // Validate mutating function
  if (typeof fn !== 'function') {
    throw new Error('You need to pass a function to mutate action params')
  }

  // Build wrapping function
  return actionContext => {
    actionContext.params = fn(actionContext.params)

    return actionContext
  }
}

module.exports = mutateActionParams