getHashParameters.js 719 B

12345678910111213141516171819202122
  1. function getHash () {
  2. let url = window.location.href
  3. let index = url ? url.indexOf("#") : -1
  4. return 0 <= index ? url.substring(index + 1) : ""
  5. }
  6. export default function getHashParameters (hash, value) {
  7. let type = typeof value
  8. let hashParameters = getHash().split("&").reduce(function(hashObject, hash) {
  9. hash = hash.split("=")
  10. hashObject[decodeURIComponent(hash[0])] = decodeURIComponent(hash[1])
  11. return hashObject
  12. }, {})
  13. if ("boolean" === type && "undefined" !== typeof hashParameters[hash]) {
  14. type = hashParameters[hash]
  15. if ("true" === type || "1" === type)
  16. return !0
  17. if ("false" === type || "0" === type)
  18. return !1
  19. }
  20. return hashParameters[hash] || value
  21. }