h5store数据存储组建(支持设置过期时间localStorage,sessionStorage)

197 阅读1分钟

这是带有过期时间的h5数据存储组件支持sessionStorage,localStorage

该存储组件可以用方便数据读取

PRs Welcome NPM version License MIT

Content

Installation

  • 1.Run npm i h5store --save
  • 2.import store from 'h5store'

Getting started

Add store to your js file.

import store from 'store'

sessionStorage use:

// save
store.sset('key', value);

// read
const value = store.sget('key');

// read set default value {}
const value = store.sget('key', {});

// delete 
store.sset('key', null);

// clear
store.sclear();

sessionStorage expiration time use:

// save set expiration time 1m
store.sset('key', value, 1000 * 60);

localStorage use:

// save
store.lset('key', value);

// read
const value = store.lget('key');

// read set default value {}
const value = store.lget('key', {});

// delete 
store.lset('key', null);

// clear
store.lclear();

localStorage expiration time use:

// save set expiration time 1m
store.lset('key', value, 1000 * 60);

API

Method Type Optional Description
sset(string, any, number) function true sessionStorage save
sget(string, any) function true sessionStorage read
sclear() function true sessionStorage clear
lset(string, any, number) function true localStorage save
lget(string, any) function true localStorage read
lclear() function true localStorage clear
clearAll() function true localStorage,sessionStorage clear

Contribution

Issues are welcome. Please add a screenshot of bug and code snippet. Quickest way to solve issue is to reproduce it on one of the examples.

Pull requests are welcome. If you want to change API or making something big better to create issue and discuss it first.


MIT Licensed