mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-30 10:58:23 -05:00
22 lines
694 B
JavaScript
22 lines
694 B
JavaScript
/* Turn an object into an url param string
|
|
* urlParams({a: 1, b: 2, c: 3})
|
|
* // a=1&b=2&c=3
|
|
*/
|
|
module.exports = function urlParams (values) {
|
|
return Object
|
|
.keys(values)
|
|
.map(function (key) {
|
|
var value = typeof values[key] === 'undefined' ? '' : values[key];
|
|
function encodeKeyValuePair (value) {
|
|
return [key, value]
|
|
.map(encodeURIComponent)
|
|
.join('=');
|
|
}
|
|
if (Array.isArray(value)) {
|
|
return value.map(encodeKeyValuePair).join('&');
|
|
} else {
|
|
return encodeKeyValuePair(value);
|
|
}
|
|
})
|
|
.join('&');
|
|
};
|