Skip to content

抹平各个环境`storage api`的差异,目前支持 chrome 插件环境和浏览器环境

Notifications You must be signed in to change notification settings

facexl/browser-ex-storage

Repository files navigation

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;

About

抹平各个环境`storage api`的差异,目前支持 chrome 插件环境和浏览器环境

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published