browser-ex-storage
v0.0.6
Published
抹平各个环境`storage api`的差异,目前支持 chrome 插件环境和浏览器环境,提供 `promise api`
Downloads
5
Maintainers
Readme
browser-ex-storage
抹平各个环境storage api
的差异,目前支持 chrome 插件环境和浏览器环境,提供 promise api
useage
npm i browser-ex-storage
import browserExStorage from 'browser-ex-storage'
export const storage = env ==='browser'?browserExStorage('browser'):browserExStorage('chrome-ex')
await storage.get('key')
await storage.get(['key','key2'])
await storage.set({
a:1,
b:[1]
})
// total types
interface S {
get<T extends string>(key: T): Promise<{
[key in T]: any;
}>;
get<T extends string[]>(keys: T): Promise<{
[key in T[number]]: any;
}>;
set: (obj: {
[key: string]: any;
}) => Promise<undefined>;
remove: (key: string) => Promise<undefined>;
clear: () => Promise<undefined>;
}
type EnvType = 'chrome-ex' | 'browser';
declare const browserExStorage: (type: EnvType) => S;
export default browserExStorage;