2016-07-14 22:48:56 +00:00
|
|
|
|
|
|
|
export function getJoiner (url) {
|
|
|
|
url = url || '';
|
|
|
|
return url.indexOf('?') === -1 ? '?' : '&';
|
2016-07-20 23:16:28 +00:00
|
|
|
}
|
2016-07-14 22:48:56 +00:00
|
|
|
|
|
|
|
export function joinURL (url, qs) {
|
|
|
|
if (!qs) { return url; }
|
|
|
|
url = url || '';
|
|
|
|
return url + getJoiner(url) + qs;
|
2016-07-20 23:16:28 +00:00
|
|
|
}
|
2016-07-14 22:48:56 +00:00
|
|
|
|
|
|
|
export function build (param) {
|
|
|
|
// Skip non-name ones
|
|
|
|
if (!param.name) { return ''; }
|
|
|
|
|
|
|
|
if (param.value) {
|
|
|
|
return encodeURIComponent(param.name) + '=' + encodeURIComponent(param.value);
|
|
|
|
} else {
|
|
|
|
return encodeURIComponent(param.name);
|
|
|
|
}
|
2016-07-20 23:16:28 +00:00
|
|
|
}
|
2016-07-14 22:48:56 +00:00
|
|
|
|
2016-07-19 04:01:31 +00:00
|
|
|
export function buildFromParams (parameters) {
|
2016-07-20 23:16:28 +00:00
|
|
|
let items = [];
|
2016-07-19 04:01:31 +00:00
|
|
|
for (var i = 0; i < parameters.length; i++) {
|
2016-07-20 23:16:28 +00:00
|
|
|
let built = build(parameters[i]);
|
|
|
|
|
|
|
|
if (!built) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
items.push(built);
|
2016-07-14 22:48:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return items.join('&');
|
2016-07-20 23:16:28 +00:00
|
|
|
}
|