-
Notifications
You must be signed in to change notification settings - Fork 3
/
helper.js
32 lines (29 loc) · 962 Bytes
/
helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* Convert an object of queries into a concatenated string of URL parameters.
* @param {Object|String} queries
* @param {String} defaultQueries
* @returns {String} URL parameters
*/
function getUrlParameters (queries, defaultQueries) {
let _queries = '';
if (defaultQueries) {
_queries += defaultQueries + '&';
}
if (queries && typeof queries === 'string') {
_queries += queries;
} else if (queries && typeof queries === "object") {
const _queriesEntries = Object.keys(queries);
const _totalQueries = _queriesEntries.length;
for (let i = 0; i < _totalQueries; i++) {
_queries += `${_queriesEntries[i]}=${encodeURIComponent(queries[_queriesEntries[i]])}`
if (i + 1 !== _totalQueries) {
_queries += '&'
}
}
}
return _queries ? '?' + _queries : '';
}
module.exports = {
getUrlParameters,
isFnStream: o => o instanceof Function
}