mirror of
https://github.com/axios/axios.git
synced 2026-04-12 02:31:57 +08:00
* Adding HTTP status code for transformResponse * refs #1214 * Fix wrong argument for tranformResponse * Fix test wrong argument for tranformData * Add test case for transformData * Add test case for transformData (reference headers case) Co-authored-by: Jay <jasonsaayman@gmail.com>
24 lines
696 B
JavaScript
24 lines
696 B
JavaScript
'use strict';
|
|
|
|
var utils = require('./../utils');
|
|
var defaults = require('../defaults');
|
|
|
|
/**
|
|
* Transform the data for a request or a response
|
|
*
|
|
* @param {Object|String} data The data to be transformed
|
|
* @param {Array} headers The headers for the request or response
|
|
* @param {Number} status HTTP status code
|
|
* @param {Array|Function} fns A single function or Array of functions
|
|
* @returns {*} The resulting transformed data
|
|
*/
|
|
module.exports = function transformData(data, headers, status, fns) {
|
|
var context = this || defaults;
|
|
/*eslint no-param-reassign:0*/
|
|
utils.forEach(fns, function transform(fn) {
|
|
data = fn.call(context, data, headers, status);
|
|
});
|
|
|
|
return data;
|
|
};
|