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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user