h5-localstore

1.0.0 • Public • Published

h5-localstore

  • H5本地存储增强
  • 支持对本地存储设置过期时间
  • 当浏览器无法使用本地存储是(无痕模式),会自动降级,将数据存入内存中

安装

npm i h5-store --save

使用

import store from "h5-store"
 
// 获取设置的本地数据
store.getItem("the-key")
 
// 设置本地存储 默认进程
store.getItem("the-key", "value")
 
// 设置本地存储 无过期
store.getItem("the-key", "value", -1)
 
// 设置本地存储 一天后过期
store.getItem("the-key", "value", 1)
 
// 设置本地存储 2200-10-1日过期
store.getItem("the-key", "value", "2200-10-1")
 
// 移除
store.removeItem("the-key")
 
// 更改默认的前置字符串 默认为 :
store.prepreposition = "$"
 

API

前缀 store.prepreposition

  • 为了和原生的本地存储区分,特地在所有通过此设置的数据,都加上前缀
  • 此前缀可以修改

保持 store.setItem(key:string, value: any [,expiration:string;data;number = 0])

  • key 本地存储的唯一key
  • value 存入的基础数据
  • expiration 什么时候过期 默认为0
    • -1 永久不过期 相当于 localStorage
    • 0 相当于sessionStorage
    • 大于0 几天后过期
    • 时间字符串 过期时间
    • 日期 过期时间

获取 store.getItem(key:string)

  • key 本地存储的唯一key

移除 store.removeItem(key:string)

  • key 本地存储的唯一key

Readme

Keywords

none

Package Sidebar

Install

npm i h5-localstore

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

7.69 kB

Total Files

4

Last publish

Collaborators

  • szpoppy