MCPcopy Create free account
hub / github.com/dabbott/javascript-playgrounds / getHashString

Function getHashString

utils/HashString.js:3–29  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1// http://stackoverflow.com/a/979995
2// Modified to use hash
3export const getHashString = () => {
4 var params = {}
5 var hash = window.location.hash.substring(1)
6
7 if (hash.length === 0) {
8 return params
9 }
10
11 var vars = hash.split("&")
12
13 for (var i = 0; i < vars.length; i++) {
14 var pair = vars[i].split("=")
15 // If first entry with this name
16 if (typeof params[pair[0]] === "undefined") {
17 params[pair[0]] = decodeURIComponent(pair[1])
18 // If second entry with this name
19 } else if (typeof params[pair[0]] === "string") {
20 var arr = [params[pair[0]], decodeURIComponent(pair[1])]
21 params[pair[0]] = arr
22 // If third or later entry with this name
23 } else {
24 params[pair[0]].push(decodeURIComponent(pair[1]))
25 }
26 }
27
28 return params
29}
30
31const buildHashString = (pairs = {}) => {
32 const hs = []

Callers 3

index.jsFile · 0.90
player.jsFile · 0.90
setHashStringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected