Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactored BuildURL helper to use URLSearchParams serializer; * Updated typings; Added TS test;
- Loading branch information
1 parent
467025b
commit 934f390
Showing
7 changed files
with
84 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
|
||
var toFormData = require('./toFormData'); | ||
|
||
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 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters