README
Svelte Persistent store
A Svelte store that keep its value through pages and reloads
Installation
npm install @macfja/svelte-persistent-store
Usage
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'
Storages
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
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)
Contributing
Contributions are welcome. Please open up an issue or create PR if you would like to help out.
Read more in the Contributing file
License
The MIT License (MIT). Please see License File for more information.