1.0.3 • Published 2 years ago

@svackages/persistent-store v1.0.3

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

svackages logo

persistent typed store

This package allows you to persist your store through localstorage.

basic usage

Typescript

const myPersistentStore = persistentStore<SomeType>({
    key: 'fancyKey',
    initValue: null,
});

JavaScript

const myPersistentStore = persistentStore({
    key: 'fancyKey',
    initValue: null,
});

clear out localstorage

// in .svelte
$myPersistentStore = null; // undefined will work as well

// in .ts/.js
myPersistentStore.set(null); // undefined will work as well

optional params

you can hook into the read and write cycle to transform values.

readHook?: (storage?: string) => T,
writeHook?: (storeValue: T) => string