0.0.5 • Published 1 year ago

@bizk/store v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@bizk/store

NPM version NPM downloads

一个简单的,用于处理本地信息存储的 Storage 库,默认存储方式为localStorage。目前处理新的设计中,该文档为旧的使用方式。

详细文档

安装方式

推荐使用pnpm作为包管理工具。当然也可使用npm或者yarn

pnpm add @bizk/store

初始化

在项目根下,创建store.ts文件,然后复制下面代码到文件中,之后就可以在项目中其它地方使用啦。

// 旧的使用方式,新的模式还处理设计中
import { LegacyStore as Store } from '@bizk/store';

const store = new Store({ mode: 'local', crypto: true });

// Test 请在项目中删除
store.set('store-test', 'test');

// 配置其它具有意义的Storage方法,请替换成自己业务中的实际方法
export const getToken = () => store.get('token');
export const setToken = () => store.set('token', 'token - user token');

export default store;

API

参数说明类型默认值
mode存储方式'local'|'session''local'
crypto是否加密booleanfalse
expire过期时间,小于 0 为永不过期number0

实例方法

参数说明类型
get获取给定名称的存储值(name: string) => any
set设置一个存储值(name:string, data:any) => any
setAll批量设置多个存储值(data:Record<string, any>) => any
del删除一项或多项数据(name: string | string[]) => any
clear清除所用存储值() => any
0.0.4-alpha.0

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago