Created
May 20, 2022 11:25
-
-
Save woss/afbc7293cc2a6632db585e388ff64583 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { filter, isEmpty, split, startsWith } from 'ramda'; | |
/** | |
* Parse the hash string and return the the value for the given name | |
* @param fullHash - The value of `$page.url.hash` | |
* @param hashName - Name of the hash which comes in `nam=value` format | |
* @returns decoded value via `decodeURIComponent` | |
*/ | |
export function getHashValue(fullHash: string, hashName: string): string { | |
console.log('getHashValue', { hashName, fullHash }); | |
if (isEmpty(fullHash)) return ''; | |
const parts = split('&')(fullHash.substring(1)); | |
const foundValue = filter((p) => startsWith(hashName, p), parts); | |
if (isEmpty(foundValue)) { | |
const message = `${hashName} hash name cannot be found`; | |
console.error(message); | |
return ''; | |
} else { | |
const foundParts = split('=')(foundValue[0]); | |
return decodeURIComponent(foundParts[1]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script context="module"> | |
export const prerender = true; | |
</script> | |
<script script lang="ts"> | |
/** | |
* Websocket server address without the client path. | |
*/ | |
let ws: string = 'ws://127.0.0.1:8088'; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment