index.js 789 B

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * @param {string} url
  3. * @returns {Object}
  4. */
  5. export function param2Obj (url) {
  6. const search = url.split('?')[1]
  7. if (!search) {
  8. return {}
  9. }
  10. return JSON.parse(
  11. '{"' +
  12. decodeURIComponent(search)
  13. .replace(/"/g, '\\"')
  14. .replace(/&/g, '","')
  15. .replace(/=/g, '":"')
  16. .replace(/\+/g, ' ') +
  17. '"}'
  18. )
  19. }
  20. export function deepClone (source) {
  21. if (!source && typeof source !== 'object') {
  22. throw new Error('error arguments', 'deepClone')
  23. }
  24. const targetObj = source.constructor === Array ? [] : {}
  25. Object.keys(source).forEach(keys => {
  26. if (source[keys] && typeof source[keys] === 'object') {
  27. targetObj[keys] = deepClone(source[keys])
  28. } else {
  29. targetObj[keys] = source[keys]
  30. }
  31. })
  32. return targetObj
  33. }