2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-24 14:04:14 +03:00
Files
axios/lib/platform/browser/classes/URLSearchParams.js
T
Dmitriy Mozgovoy bd391247b4 Added the ability for the url-encoded-form serializer to respect the formSerializer config; (#4721)
Added test for `formSerializer` config in context of `url-encoded-form` serializer;
2022-05-17 08:26:35 +02:00

37 lines
837 B
JavaScript

'use strict';
module.exports = typeof URLSearchParams !== 'undefined' ? URLSearchParams : (function defineURLSearchParams() {
function encode(str) {
var charMap = {
'!': '%21',
"'": '%27',
'(': '%28',
')': '%29',
'~': '%7E',
'%20': '+',
'%00': '\x00'
};
return encodeURIComponent(str).replace(/[!'\(\)~]|%20|%00/g, function replacer(match) {
return charMap[match];
});
}
function URLSearchParams() {
this.pairs = [];
}
var prototype = URLSearchParams.prototype;
prototype.append = function append(name, value) {
this.pairs.push([name, value]);
};
prototype.toString = function toString() {
return this.pairs.map(function each(pair) {
return pair[0] + '=' + encode(pair[1]);
}, '').join('&');
};
return URLSearchParams;
})();