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

Function setHashString

utils/HashString.js:39–66  ·  view source on GitHub ↗
(fileMap)

Source from the content-addressed store, hash-verified

37}
38
39export const setHashString = (fileMap) => {
40 const multiFile = Object.keys(fileMap).length > 1
41 const code = fileMap['index.js']
42
43 const options = {
44 ...getHashString(),
45 code,
46 }
47
48 // If there's no code in the editor, delete the code param
49 if (!code) {
50 delete options.code
51 }
52
53 // If we have multiple files, use the `files` param instead of `code`
54 if (multiFile) {
55 delete options.code
56
57 const files = Object.keys(fileMap).map(filename => [filename, fileMap[filename]])
58 options.files = JSON.stringify(files)
59 }
60
61 try {
62 history.replaceState({}, "", `${buildHashString(options)}`)
63 } catch (e) {
64 // Browser doesn't support pushState
65 }
66}

Callers

nothing calls this directly

Calls 2

getHashStringFunction · 0.85
buildHashStringFunction · 0.85

Tested by

no test coverage detected