nw-storage
TypeScript icon, indicating that this package has built-in type declarations

1.0.24 • Public • Published

本地存储

使用浏览器APIlocalStorage实现,仅限浏览器端使用

安装

npm i nw-storage

API

setStorage 设置缓存

  • 类型定义
/**
 * @param   {string}  key     [key]
 * @param   {any}     value   [value]
 * @param   {number}  expire  [expire 过期时间,如: 24 * 60 * 60 = 1天]
 * @return  {void}            [return]
 */
declare const setStorage: (key: string, value: any, expire?: number) => void;
  • 使用,过期时间格式,参考上类型定义中说明
import { setStorage } from 'nw-storage'

setStorage('name', 1) // NAME => 1

getStorage 获取缓存

  • 使用, 如果缓存设置了有效期,失效则返回null
import { getStorage } from 'nw-storage'

getStorage('name') // 1

removeStorage 移除缓存

  • 使用
import { removeStorage } from 'nw-storage'

removeStorage('name') // null

setStorageNameSpace 设置缓存命名空间

  • 使用
import { setStorageNameSpace } from 'nw-storage'

setStorageNameSpace('nw') // NW-NAME => 1

Package Sidebar

Install

npm i nw-storage

Weekly Downloads

25

Version

1.0.24

License

MIT

Unpacked Size

6.2 kB

Total Files

10

Last publish

Collaborators

  • wvlvik