JSPM

@webext-core/storage

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 954
  • Score
    100M100P100Q106390F
  • License MIT

Local storage based wrapper around the Browser.storage APIs

Package Exports

  • @webext-core/storage

Readme

@webext-core/storage

A type-safe wrapper around the Browser.storage APIs, based off local storage.

pnpm i @webext-core/storage

Usage

If you don't use TypeScript, or don't want to type your store, you can use any of the named exports from the package.

import { localExtStorage, syncExtStorage, managedExtStorage } from '@webext-core/storage';

const value = await localExtStorage.getItem('some-key');

If you want to define types for your storage, you can use the defineExtensionStorage method:

// storage.ts
import Browser from 'webextension-polyfill';
import { defineExtensionStorage } from '@webext-core/storage';

export interface LocalExtStorageSchema {
  someKey: boolean;
  someOtherKey?: string;
}

export const localExtStorage = defineExtensionStorage<LocalExtStorageSchema>(Browser.storage.local);

Then use localExtStorage from your own module:

import { localExtStorage } from './storage';

// This works
const value: boolean | null = await localExtStorage.getItem('someKey');

// This results in a type error
localExtStorage.getItem('xyz');