Skip to content

Instantly share code, notes, and snippets.

@woss
Created May 20, 2022 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woss/afbc7293cc2a6632db585e388ff64583 to your computer and use it in GitHub Desktop.
Save woss/afbc7293cc2a6632db585e388ff64583 to your computer and use it in GitHub Desktop.
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]);
}
}
<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