Skip to content

Instantly share code, notes, and snippets.

@rbk
Created February 5, 2021 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbk/0a2c7ede3489fed60a1be1e3bfef3af8 to your computer and use it in GitHub Desktop.
Save rbk/0a2c7ede3489fed60a1be1e3bfef3af8 to your computer and use it in GitHub Desktop.
/**
* Say you have this: {"key": "123", "limit": 20}
* But you need this: ?key=123&limit=20
* Use objectToParams...
*/
const objectToParams = (obj) => {
const params = Object.keys(obj).reduce((acc, key) => {
return `${acc}&${key}=${obj[key]}`;
}, '');
return params.replace(/&/, '?');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment