@jill64/typed-storage
🗃️ Type-Safe Web Storage API Wrapper
Installation
npm i @jill64/typed-storage
Example
See ts-serde for more information on type guard
import { typedStorage } from '@jill64/typed-storage'
import { json } from '@jill64/typed-storage/serde'
const key = 'localStorageKey'
const value = ['value1', 'value2', 'value3']
const guard = (x: unknown): x is string[] =>
Array.isArray(x) && x.every((y) => typeof y === 'string')
const store = typedStorage(key, json(guard, []), {
})
const storedValue = store.get()
store.set(value)
const unsubscriber = store.subscribe((newValue) => {
console.log(newValue)
})
unsubscriber()
License
MIT