Skip to content

Commit

Permalink
perf[utils]: add param2Obj function
Browse files Browse the repository at this point in the history
  • Loading branch information
PanJiaChen committed Apr 19, 2019
1 parent b6147d3 commit 5dd62ef
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, ' ') +
'"}'
)
}

0 comments on commit 5dd62ef

Please sign in to comment.