A Svelte store that keep its value through pages and reloads
npm install @macfja/svelte-persistent-store
import { persist, localStorage } from "@macfja/svelte-persistent-store"
import { writable } from "svelte/store"
let name = persist(writable('John'), localStorage(), 'name')
$name = 'Jeanne Doe'
// if you reload the page the value of $name is 'Jeanne Doe'
There are 4 storages built-in:
localStorage()
, that usewindow.localStorage
to save valuessessionStorage()
, that usewindow.sessionStorage
to save valuescookieStorage()
, that usedocument.cookie
to save valuesindexedDBStorage()
, that usewindow.indexedDB
to save values
You can add more storages, you just need to implement the interface StorageInterface
Documentation and examples car be generated with npm run doc
, next open docs/index.html
with your favorite web browser.
(Hint: If you don't want to generate the docs, a part of the example and documentation are available here)
Contributions are welcome. Please open up an issue or create PR if you would like to help out.
Read more in the Contributing file
The MIT License (MIT). Please see License File for more information.