unpkg/server/middleware/utils/createSearch.js

18 lines
388 B
JavaScript
Raw Normal View History

2017-09-02 05:43:56 +00:00
function createSearch(query) {
const params = []
Object.keys(query).forEach(function (param) {
if (query[param] === '') {
params.push(param) // Omit the trailing "=" from param=
} else {
params.push(`${param}=${encodeURIComponent(query[param])}`)
}
})
const search = params.join('&')
return search ? `?${search}` : ''
}
module.exports = createSearch