Created
February 5, 2021 04:21
-
-
Save rbk/0a2c7ede3489fed60a1be1e3bfef3af8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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