mirror of
https://github.com/tenrok/axios.git
synced 2026-06-02 16:04:10 +03:00
c05ad48952
Added `toURLEncodedForm` helper; Added automatic payload serialization to `application/x-www-form-urlencoded` to have parity with `multipart/form-data`; Added test of handling `application/x-www-form-urlencoded` body by express.js; Updated README.md; Added missed param in JSDoc; Fixed hrefs in README.md; Co-authored-by: Jay <jasonsaayman@gmail.com>
39 lines
893 B
JavaScript
39 lines
893 B
JavaScript
'use strict';
|
|
|
|
module.exports = (function getURLSearchParams(nativeURLSearchParams) {
|
|
if (typeof nativeURLSearchParams === 'function') return nativeURLSearchParams;
|
|
|
|
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;
|
|
})(URLSearchParams);
|