Roll own Object.fromEntries; fix #919

This commit is contained in:
jascha ehrenreich 2020-02-29 08:19:43 +01:00 committed by GitHub
parent afedff6649
commit b164243235
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 1 deletions

View File

@ -1,3 +1,17 @@
export const entries = (params) => {
if (typeof Object.fromEntries === 'function') {
return Object.fromEntries(params)
}
const obj = {}
params.forEach(([key, val]) => {
obj[key] = val
})
return obj
}
export const getPathInfo = (path) => {
const url = new URL(path, 'http://localhost')
@ -9,6 +23,6 @@ export const getPathInfo = (path) => {
return {
path: withoutTrailingSlash,
query: search,
queryParams: Object.fromEntries(searchParams.entries())
queryParams: entries(searchParams.entries())
}
}