Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dlurak/svocal
Localstorage With The Power Of Svele Stores
https://github.com/dlurak/svocal
localstorage svelte sveltekit
Last synced: about 1 month ago
JSON representation
Localstorage With The Power Of Svele Stores
- Host: GitHub
- URL: https://github.com/dlurak/svocal
- Owner: Dlurak
- License: mpl-2.0
- Created: 2024-01-26T17:43:52.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-04-10T10:49:09.000Z (10 months ago)
- Last Synced: 2024-04-24T09:19:50.544Z (10 months ago)
- Topics: localstorage, svelte, sveltekit
- Language: TypeScript
- Homepage: https://dlurak.github.io/svocal/
- Size: 96.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Svocal
Svocal combines the power of Svelte stores with localstorage.
## Installation
```bash
npm i svocal
``````bash
yarn add svocal
``````bash
pnpm add svocal
``````bash
bun add svocal
```## Usage
Import `localstorage`:
```ts
import { localstorage } from 'svocal';
```Then you can start using the localstorage:
```ts
const store = = localstorage('demo', 1)
const store2 = = localstorage('demo', 1)
````store` and `store2` both use the localstorage key `demo` so when you set store store2 will also update.
```ts
store.set(42);
store2.subscribe(console.log);
```Will console.log 42
This even works with different tabs, so svocal can be used to sync state between tabs and windows!