perf[utils]: add param2Obj function

This commit is contained in:
Pan 2019-04-19 21:55:03 +08:00
parent b6147d33f3
commit 5dd62efed1
1 changed files with 20 additions and 0 deletions

View File

@ -88,3 +88,23 @@ export function formatTime(time, option) {
) )
} }
} }
/**
* @param {string} url
* @returns {Object}
*/
export function param2Obj(url) {
const search = url.split('?')[1]
if (!search) {
return {}
}
return JSON.parse(
'{"' +
decodeURIComponent(search)
.replace(/"/g, '\\"')
.replace(/&/g, '","')
.replace(/=/g, '":"')
.replace(/\+/g, ' ') +
'"}'
)
}