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

1.0.3 • Public • Published

storage

Typescript support a storage lib which sessionStorage and localStorage with the same api and extend api

🦄 Usage

import storage from '@caoyugang/better-storage'

 storage.setItem('sessionStorage', key, value)

 storage.getItem('localStorage', key)

in vue3
setup () {
    const key = 'store'
    const onStore = () => {
      storage.setItem('sessionStorage', key, '123')
    }
    const onRemove = () => {
      storage.removeItem('localStorage', key)
    }
    return {
      onStore,
      onRemove
    }
  }

📦 Install

npm i @caoyugang/better-storage

or

yarn add @caoyugang/better-storage

🎁 api

type = 'sessionStorage' | 'localStorage'

getItem(type, key)
get storage with key, return value or undefined

setItem(type, key, value)
set storage with key and val

hasItem(type, key)
determine storage has the key

removeItem(type, key)
remove storage with key

clear(type)
clear all storages

getStorageLength(type)
get storage length

getStorageKey(type, index)
get storage key by index

getStorageKeyValue(type)
get all the storages about key and value

📄 License

MIT License © 2021-PRESENT caoyugang_1

Readme

Keywords

Package Sidebar

Install

npm i @caoyugang/better-storage

Weekly Downloads

5

Version

1.0.3

License

MIT

Unpacked Size

44.4 kB

Total Files

17

Last publish

Collaborators

  • caoyugang