Last active
November 11, 2018 05:08
-
-
Save pirey/0928925174e51853dfd1418a54f15486 to your computer and use it in GitHub Desktop.
[DEPRECATED] use this instead https://github.com/sindresorhus/query-string
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
/* | |
* convert ojbect into query params format | |
* used for request with content-type application/x-www-form-urlencoded | |
* | |
* e.g | |
* { param: "someVal", param2: "otherVal" } | |
* | |
* is converted into | |
* | |
* param1=someVal¶m2=otherVal | |
*/ | |
function buildQuery (params) { | |
const notNull = x => x !== null | |
const esc = encodeURIComponent | |
const queryString = Object.keys(params).map((k) => | |
params[k] !== null || params[k] !== undefined ? esc(k) + '=' + esc(params[k]) : null | |
).filter(notNull) | |
return queryString.length >= 1 | |
? queryString.join('&') | |
: '' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment