Last active
August 17, 2016 12:31
-
-
Save alexsasharegan/b550437c9a79e6d9ec4443dea9da89fb to your computer and use it in GitHub Desktop.
Pass an object of key: value pairs to be uri encoded (does prepend the '?')
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
// es5 | |
function encodeQueryData(data) { | |
return '?' + Object.keys(data).map(function(key) { | |
return [key, data[key]].map(encodeURIComponent).join("="); | |
}).join("&"); | |
} | |
// es6 | |
const encodeQueryData = data => '?' + Object.keys(data).map(key => [key, data[key]].map(encodeURIComponent).join("=")).join('&'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment