
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
svelte-hash
Advanced tools
Easy URL hash management for Svelte.
svelte-hash provides a simple way to manage URL hash/fragment in Svelte.
[!NOTE] This library is client-side only, meaning SvelteKit (SSR) is not supported.
# Bun
bun i -D svelte-hash
# NPM
npm i -D svelte-hash
# Yarn
yarn add -D svelte-hash
# PNPM
pnpm add -D svelte-hash
[!TIP] It's really suggested to have a look to these interactive examples to test the library and understand the functionality (there you can see hash/fragment updates in the URL).
First of all, create and export a new hash store instance:
// store.ts
import { createHashStore } from 'svelte-hash'
interface Hash {
foo: string
bar: string
}
export const hash = createHashStore<Hash>()
[!NOTE]
- Explicitly defining the type of the hash is optional, but extremely suggested as it provides type checking and autocompletion
- Currently only string values are supported: this might change in a future major release
- Only one hash store can be initialized in the same project: multiple hash stores initialization will throw an error
Then, you can use the hash store in your components:
<!-- App.svelte -->
<script>
import { hash } from './store.ts'
// Prevent pushing to browser history every change with a "proxy" variable
// Every hash key could also not exist, so we need to provide a default value
let valueProxy = hash.foo || ''
</script>
<!-- The form will update the hash value only when submitted -->
<!-- result (on submit) will be: <URL>#foo={valueProxy} -->
<form on:submit|preventDefault={() => hash.foo = valueProxy}>
<input type="text" bind:value={valueProxy} />
<button type="submit">Submit</button>
</form>
<p>
To delete a hash key from the URL, you can set it to a falsy value:
import { hash } from './store.ts'
hash.foo = null
// or
hash.foo = undefined
// or
hash.foo = ''
The reason I created this library was to accomplish a simple URL hash/fragment management for my Svelte music player, Musicale (you should really check it out!).
I originally created the implementation directly in that project, but then I decided to extract it and make it a standalone library for everyone to use.
On the browser, to access the URL fragment you use window.location.hash, so I decided to take that for the library name.
We :heart: contributions!
Feel free to open an issue or a pull request but follow Contributing Guidelines.
If you don't know where to start, check out the help wanted issues!
GPL-3.0 License here.
FAQs
Easy URL hash management for Svelte.
We found that svelte-hash demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.