Skip to content

Instantly share code, notes, and snippets.

@raphaelpor
Created December 5, 2016 20:37
Show Gist options
  • Save raphaelpor/d04dc1d10f89c3caf0ed90ab026293c0 to your computer and use it in GitHub Desktop.
Save raphaelpor/d04dc1d10f89c3caf0ed90ab026293c0 to your computer and use it in GitHub Desktop.
export default function transformParams(source) {
if (source) {
const params = Object.entries(source);
const paramsList = [];
params.forEach((item) => {
const key = encodeURIComponent(item[0]);
const value = encodeURIComponent(item[1]);
paramsList.push(`${key}=${value}`);
});
return paramsList.length ? `?${paramsList.join('&')}` : '';
}
return '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment