Created
March 15, 2019 04:08
-
-
Save btoo/cb24c88ddf5eaf26b02453146c33d8f1 to your computer and use it in GitHub Desktop.
add query parameters to a url
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
| module.exports = (endpoint, query = {}) => { | |
| const queryEntries = Object.entries(query || {}).filter(([key, value]) => value || typeof value === 'boolean'); | |
| return queryEntries.length | |
| ? `${endpoint}?${queryEntries | |
| .map(pair => pair.map(encodeURIComponent).join('=')) | |
| .join('&')}` | |
| : endpoint; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment