transformData.js 639 B

12345678910111213141516171819202122
  1. 'use strict';
  2. var utils = require('./../utils');
  3. var defaults = require('./../defaults');
  4. /**
  5. * Transform the data for a request or a response
  6. *
  7. * @param {Object|String} data The data to be transformed
  8. * @param {Array} headers The headers for the request or response
  9. * @param {Array|Function} fns A single function or Array of functions
  10. * @returns {*} The resulting transformed data
  11. */
  12. module.exports = function transformData(data, headers, fns) {
  13. var context = this || defaults;
  14. /*eslint no-param-reassign:0*/
  15. utils.forEach(fns, function transform(fn) {
  16. data = fn.call(context, data, headers);
  17. });
  18. return data;
  19. };