UNPKG

296 BJavaScriptView Raw
1export default function getUrlParams(href = window.location.search) {
2 return (encodeURI(href).match(/([\w_-]+)=([^&]+)/gi) || [])
3 .map(item => {
4 const arr = item.split("=");
5 return { [arr[0]]: decodeURI(arr[1]) };
6 })
7 .reduce((prev, cur) => ({ ...prev, ...cur }), {});
8}