Last active
July 12, 2020 20:50
-
-
Save anton-karlovskiy/3c75950643a7d03b4e7170cc870e2154 to your computer and use it in GitHub Desktop.
How to create the query parameter string by combining a JS object
This file contains 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
// RE: https://github.com/sindresorhus/query-string | |
// RE: https://bundlephobia.com/[email protected] | |
// RE: https://github.com/unshiftio/querystringify | |
// RE: https://github.com/Gozala/querystring | |
const serializeToQueryParams = (queryObject, prefix = '') => { | |
const queryString = []; | |
for (const key in queryObject) | |
if (queryObject.hasOwnProperty(key)) { | |
queryString.push(encodeURIComponent(key) + '=' + encodeURIComponent(queryObject[key])); | |
} | |
return `${prefix}?${queryString.join('&')}`; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment