@tiny-libs/storage
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@tiny-libs/storage

Tiny serializable web storage library. Support localStorage and sessionStorage.

Features

  • Automatic serialization and deserialization
  • Type-safe

Install

npm i @tiny-libs/storage

Usage

localStorage

import { useLocalStorage } from '@tiny-libs/storage'

const storage = useLocalStorage('key', {})

storage.set({ hello: 'hi', greeting: 'hello' })

const obj = storage.get()

console.log(obj.greeting) // 'hello'

sessionStorage

import { useSessionStorage } from '@tiny-libs/storage'

const storage = useSessionStorage('key', 1)

console.log(storage.get()) // 1

storage.set(2)
storage.set(null) // clear storage

console.log(storage.get()) // 1

License

MIT copyright © 2024-present alex wei

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @tiny-libs/storage

      Weekly Downloads

      0

      Version

      1.0.0

      License

      MIT

      Unpacked Size

      6.69 kB

      Total Files

      6

      Last publish

      Collaborators

      • alex.wei