A bunch of Svelte's writable store key-value wrappers around storages.
Currently supported storages:
localStorage
sessionStorage
Planning:
indexedDB
npm i -D svelte-storages
# or
yarn add -D svelte-storages
It's basically an object {}
stored in the storage.
// store.js
import { localStore } from 'svelte-storages'
export const dates = localStore('dates')
import { get } from 'svelte/store'
import { dates } from './store.js'
dates.set('key', 'value')
console.log(get(dates).key) // -> value
Or, inside the component
<script context="module">
import { dates } from './store.js'
</script>
<p>{$dates.key}</p>
localStore
- wrapper around localStorage, sessionStore
- wrapper around sessionStorage.
Parameters:
name
- Name for storing in storage.initial
- Initial object to put in storage. Default is {}
.