utils.js 501 B

12345678910111213141516171819202122232425
  1. /**
  2. * @param {string} url
  3. * @returns {Object}
  4. */
  5. function param2Obj(url) {
  6. const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ')
  7. if (!search) {
  8. return {}
  9. }
  10. const obj = {}
  11. const searchArr = search.split('&')
  12. searchArr.forEach(v => {
  13. const index = v.indexOf('=')
  14. if (index !== -1) {
  15. const name = v.substring(0, index)
  16. const val = v.substring(index + 1, v.length)
  17. obj[name] = val
  18. }
  19. })
  20. return obj
  21. }
  22. module.exports = {
  23. param2Obj
  24. }