https://github.com/jill64/typed-storage
🗃️ Type-Safe Web Storage API Wrapper
https://github.com/jill64/typed-storage
library localstorage sessionstorage type-safe utility
Last synced: 29 days ago
JSON representation
🗃️ Type-Safe Web Storage API Wrapper
- Host: GitHub
- URL: https://github.com/jill64/typed-storage
- Owner: jill64
- License: mit
- Created: 2023-09-07T12:46:17.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-04T01:08:03.000Z (about 1 month ago)
- Last Synced: 2025-06-04T08:42:29.916Z (about 1 month ago)
- Topics: library, localstorage, sessionstorage, type-safe, utility
- Language: TypeScript
- Homepage: https://npmjs.com/package/@jill64/typed-storage
- Size: 944 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @jill64/typed-storage
🗃️ Type-Safe Web Storage API Wrapper
## Installation
```sh
npm i @jill64/typed-storage
```## Example
See [ts-serde](https://github.com/jill64/ts-serde#readme) for more information on type guard
```ts
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, []), {
// Optional
// Use sessionStorage
// sessionStorage?: boolean
})// string[]
const storedValue = store.get()store.set(value)
const unsubscriber = store.addListener((newValue) => {
// called when localStorage value changes
console.log(newValue)
})// unsubscribe
unsubscriber()
```## License
[MIT](LICENSE)