-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7290c07
commit eb6c586
Showing
10 changed files
with
153 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,111 @@ | ||
function encode(val: string) { | ||
return encodeURIComponent(val). | ||
replace(/%3A/gi, ':'). | ||
replace(/%24/g, '$'). | ||
replace(/%2C/gi, ','). | ||
replace(/%20/g, '+'). | ||
replace(/%5B/gi, '['). | ||
replace(/%5D/gi, ']'); | ||
} | ||
|
||
var toString = Object.prototype.toString; | ||
|
||
function forEach(obj: any, fn: any) { | ||
// Don't bother if no value provided | ||
if (obj === null || typeof obj === 'undefined') { | ||
return; | ||
} | ||
|
||
// Force an array if not already something iterable | ||
if (typeof obj !== 'object') { | ||
/*eslint no-param-reassign:0*/ | ||
obj = [obj]; | ||
} | ||
|
||
if (isArray(obj)) { | ||
// Iterate over array values | ||
for (var i = 0, l = obj.length; i < l; i++) { | ||
fn.call(null, obj[i], i, obj); | ||
} | ||
} else { | ||
// Iterate over object keys | ||
for (var key in obj) { | ||
if (Object.prototype.hasOwnProperty.call(obj, key)) { | ||
fn.call(null, obj[key], key, obj); | ||
} | ||
} | ||
} | ||
} | ||
|
||
function isURLSearchParams(val: any) { | ||
return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams; | ||
} | ||
|
||
function isArray(val: any) { | ||
return toString.call(val) === '[object Array]'; | ||
} | ||
|
||
function isDate(val: any) { | ||
return toString.call(val) === '[object Date]'; | ||
} | ||
|
||
function isObject(val: any) { | ||
return val !== null && typeof val === 'object'; | ||
} | ||
|
||
/** | ||
* Build a URL by appending params to the end | ||
* | ||
* @param {string} url The base of the url (e.g., http://www.google.com) | ||
* @param {object} [params] The params to be appended | ||
* @returns {string} The formatted url | ||
*/ | ||
export function buildURL(url: string, params?: any, paramsSerializer?: any) { | ||
/*eslint no-param-reassign:0*/ | ||
if (!params) { | ||
return url; | ||
} | ||
|
||
var serializedParams; | ||
if (paramsSerializer) { | ||
serializedParams = paramsSerializer(params); | ||
} else if (isURLSearchParams(params)) { | ||
serializedParams = params.toString(); | ||
} else { | ||
var parts : string[] = []; | ||
|
||
forEach(params, function serialize(val: any, key: any) { | ||
if (val === null || typeof val === 'undefined') { | ||
return; | ||
} | ||
|
||
if (isArray(val)) { | ||
key = key + '[]'; | ||
} else { | ||
val = [val]; | ||
} | ||
|
||
forEach(val, function parseValue(v: any) { | ||
if (isDate(v)) { | ||
v = v.toISOString(); | ||
} else if (isObject(v)) { | ||
v = JSON.stringify(v); | ||
} | ||
parts.push(encode(key) + '=' + encode(v)); | ||
}); | ||
}); | ||
|
||
serializedParams = parts.join('&'); | ||
} | ||
|
||
if (serializedParams) { | ||
var hashmarkIndex = url.indexOf('#'); | ||
if (hashmarkIndex !== -1) { | ||
url = url.slice(0, hashmarkIndex); | ||
} | ||
|
||
url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams; | ||
} | ||
|
||
return url; | ||
}; |
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
Empty file.
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