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方法名称均一致),同时支持泛型方法。
- Host: GitHub
- URL: https://github.com/caojianping/tsx-storage
- Owner: caojianping
- License: mit
- Created: 2019-09-03T10:05:20.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-30T06:47:29.000Z (about 2 years ago)
- Last Synced: 2024-10-30T18:05:40.757Z (6 months ago)
- Topics: jts-storage, localstorage, sessionstorage, typescript
- Language: TypeScript
- Homepage:
- Size: 5.86 KB
- Stars: 14
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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/falseconst 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