// 字符串转params对象
export const strToParams = (str: string) => {
  if (str[0] === '?') {
    str = str.substr(1)
  }

  const result: { [key: string]: string } = {}
  const splitRG = /([^=&]+)(?:=([^&]*))?&?/

  let rgRet
  while ((rgRet = str.match(splitRG))) {
    result[rgRet[1]] = rgRet[2] === undefined ? '' : rgRet[2]
    str = str.substr(rgRet[0].length)
  }

  return result
}
