Created
March 20, 2018 06:30
-
-
Save deguchi/8d7ca27fa740d202e0b2c8697b44dce7 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
const buildQueryString = (params) => { | |
let parts = []; | |
let add = (key, value) => { | |
parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(value)); | |
} | |
for (let key in params) { | |
let param = params[key]; | |
if (Array.isArray(param)) { | |
param.map((value) => { | |
add(key, value); | |
}); | |
} | |
else { | |
add(key, param); | |
} | |
} | |
return '?' + parts.join('&').replace(/%20/g, '+'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment