Open emadalam opened 7 years ago
function toQueryString(obj) {
return _.map(obj, (v, k) => {
if (_.isArray(v)) {
return _.map(v, (av) =>${k}[]=${av}).join('&');
} else { return
${encodeURIComponent(k)}=${encodeURIComponent(v)}`;
}
}).join('&');
}
function toUrl(url = '', params = { } ) {
let q = toQueryString(params);
let urlBuffer = url;
if (q) {
urlBuffer += '?' + q;
}
return urlBuffer;
}
This felt like an easy fix to get rid of reg-exp, if am wrong care to specify why the reg-exp needed in the first place?
From one of the PRs https://github.com/emadalam/atvjs/pull/12
path-to-regexp
Handy code snippet