赋动字节工具类
npm install @foundbyte/utilutil> TODO: util library by Foundbyte
```
yarn add @foundbyte/util
// or
npm install @foundbyte/util
`ts
import { StorageService } from '@foundbyte/util';
enum EStorage {
Role = 'role',
User = 'user',
}
const storage = new StorageService
rootKey: 'foundbyte',
});
storage.set(EStorage.Role, 'admin');
storage.get(EStorage.Role); // 'admin'
storage.set(EStorage.User, {
name: 'landSnow',
email: '2728997@qq.com',
});
storage.get(EStorage.User);
storage.remove(EStorage.User);
storage.get(EStorage.User); // undefined
`
`ts`
class StorageService
constructor(options: IStorageOptions) {}
}
`ts`
interface IStorageOptions {
/* 唯一key /
rootKey: string;
/* 存储的类型 /
type?: 'local' | 'session';
}
表中的类型 T 为初始化实例传入 StorageService 的泛型类型,建议统一使用枚举(enum)类型
| 方法 | 返回值 | 说明 |
| ------------------------- | ------ | -------------- |
| get(key: T) | any | 获取存储的数据 |set(key: T, value: any)
| | - | 存储数据 |remove(key: T)
| | - | 删除单条数据 |clear()
| | - | 清空存储的数据 |
``
import { clipboard } from '@foundbyte/util';
`@foundbyte/util
clipboard.copy();`
```
clipboard.paste().then(text => {
console.log(text);
});