url query formatting fix, removed trailing ?

This commit is contained in:
mrfry 2021-02-15 10:06:29 +01:00
parent a9c8bf9a90
commit 98b17e5b22
2 changed files with 11 additions and 10 deletions

View file

@ -22,16 +22,17 @@ interface URLFormatOptions {
}
function formatUrl(options: URLFormatOptions): string {
console.log(options.pathname, options.query)
const queryString = options.query
? '?' +
Object.keys(options.query)
.map((key) => {
return `${key}=${encodeURIComponent(options.query[key])}`
})
.join('&')
: ''
const path = options.pathname || ''
if (!options.query || Object.keys(options.query).length === 0) {
return path
}
const queryString =
'?' +
Object.keys(options.query)
.map((key) => {
return `${key}=${encodeURIComponent(options.query[key])}`
})
.join('&')
return path + queryString
}