An open API service indexing awesome lists of open source software.

https://github.com/caojianping/tsx-storage

Web存储localStorage、sessionStorage的TypeScript封装,提供通用的API方法(同原有的js方法名称均一致),同时支持泛型方法。
https://github.com/caojianping/tsx-storage

jts-storage localstorage sessionstorage typescript

Last synced: 20 days ago
JSON representation

Web存储localStorage、sessionStorage的TypeScript封装,提供通用的API方法(同原有的js方法名称均一致),同时支持泛型方法。

Awesome Lists containing this project

README

        

# tsx-storage
localStorage、sessionStorage的TypeScript封装,提供通用的API方法,同时支持泛型方法。

## Installing
Using npm:
```bash
$ npm install tsx-storage
```

## Example
### LocalStorage 测试
```ts
import { LocalStorage } from 'tsx-storage';

// LocalStorage测试
const key1 = 'local_number';
const value1 = 666888;
LocalStorage.setItem(key1, value1); // 返回:true/false;
LocalStorage.getItem(key1); // 返回:666888/null;
LocalStorage.removeItem(key1); // 返回:true/false;

const key2 = 'local_string';
const value2 = 'hello world';
LocalStorage.setItem(key2, value2); // 返回:true/false;
LocalStorage.getItem(key2); // 返回:'hello world'/null;
LocalStorage.removeItem(key2); // 返回:true/false;

const key3 = 'local_boolean';
const value3 = true;
LocalStorage.setItem(key3, value3); // 返回:true/false;
LocalStorage.getItem(key3); // 返回:true/null;
LocalStorage.removeItem(key3); // 返回:true/false;
```

### SessionStorage 测试
```ts
import { SessionStorage } from 'tsx-storage';

// SessionStorage测试
const key1 = 'session_number';
const value1 = 666888;
SessionStorage.setItem(key1, value1); // 返回:true/false;
SessionStorage.getItem(key1); // 返回:666888/null;
SessionStorage.removeItem(key1); // 返回:true/false

const key2 = 'session_string';
const value2 = 'bala bala xiaomoxian';
SessionStorage.setItem(key2, value2); // 返回:true/false;
SessionStorage.getItem(key2); // 返回:'bala bala xiaomoxian'/null;
SessionStorage.removeItem(key2); // 返回:true/false;
```

## API
##### LocalStorage.setItem(key: string, value: T): boolean
##### LocalStorage.getItem(key: string): T | null
##### LocalStorage.removeItem(key: string): boolean
##### LocalStorage.clear(): void
##### SessionStorage.setItem(key: string, value: T): boolean
##### SessionStorage.getItem(key: string): T | null
##### SessionStorage.removeItem(key: string): boolean
##### SessionStorage.clear(): void