2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-14 18:42:33 +03:00

URL params serializer; (#4734)

* Refactored BuildURL helper to use URLSearchParams serializer;

* Updated typings;
Added TS test;
This commit is contained in:
Dmitriy Mozgovoy
2022-05-25 09:16:38 +03:00
committed by GitHub
parent 467025bdb7
commit 934f390cc3
7 changed files with 84 additions and 87 deletions
@@ -1,36 +1,5 @@
'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];
});
}
var AxiosURLSearchParams = require('../../../helpers/AxiosURLSearchParams');
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;
})();
module.exports = typeof URLSearchParams !== 'undefined' ? URLSearchParams : AxiosURLSearchParams;