axios
Version:
Promise based HTTP client for the browser and node.js
51 lines (41 loc) • 1.09 kB
JavaScript
;
var toFormData = require('./toFormData');
function encode(str) {
// Do not map `%00` back to a raw null byte: that reversed
// the safe percent-encoding from encodeURIComponent and enabled null byte injection.
var charMap = {
'!': '%21',
"'": '%27',
'(': '%28',
')': '%29',
'~': '%7E',
'%20': '+'
};
return encodeURIComponent(str).replace(
/[!'\(\)~]|%20/g,
function replacer(match) {
return charMap[match];
}
);
}
function AxiosURLSearchParams(params, options) {
this._pairs = [];
params && toFormData(params, this, options);
}
var prototype = AxiosURLSearchParams.prototype;
prototype.append = function append(name, value) {
this._pairs.push([name, value]);
};
prototype.toString = function toString(encoder) {
var _encode = encoder
? function(value) {
return encoder.call(this, value, encode);
}
: encode;
return this._pairs
.map(function each(pair) {
return _encode(pair[0]) + '=' + _encode(pair[1]);
}, '')
.join('&');
};
module.exports = AxiosURLSearchParams;