UNPKG

@mirawision/chrome-api

Version:

A comprehensive TypeScript library for Chrome Extension API, providing type-safe wrappers and utilities for bookmarks, commands, context menus, cookies, downloads, storage, notifications, runtime, scripting, and side panel functionalities.

63 lines (62 loc) 2.5 kB
/// <reference types="chrome" /> interface ISyncStorage { [key: string]: any; } /** * A class that provides a type-safe wrapper around Chrome's sync storage API. * This class allows you to store and retrieve data that is synced across devices * where the user is signed into Chrome. It's useful for storing user preferences * and other small pieces of data that should persist across devices. */ declare class StorageSync { /** * Retrieves a value from sync storage by key. * @param key - The key to retrieve * @returns A promise that resolves to the stored value for the specified key * @throws {Error} If there's an error retrieving the data */ static get<T = any>(key: string): Promise<T>; /** * Retrieves all data from sync storage. * @returns A promise that resolves to all stored data * @throws {Error} If there's an error retrieving the data */ static getAll(): Promise<ISyncStorage>; /** * Stores a value in sync storage. * @param key - The key under which to store the value * @param value - The value to store * @returns A promise that resolves when the value is stored * @throws {Error} If there's an error storing the data */ static set(key: string, value: any): Promise<void>; /** * Stores multiple key-value pairs in sync storage. * @param data - An object containing the key-value pairs to store * @returns A promise that resolves when all values are stored * @throws {Error} If there's an error storing the data */ static setBulk(data: ISyncStorage): Promise<void>; /** * Removes a value from sync storage. * @param key - The key to remove * @returns A promise that resolves when the value is removed * @throws {Error} If there's an error removing the data */ static remove(key: string): Promise<void>; /** * Removes all data from sync storage. * @returns A promise that resolves when all data is cleared * @throws {Error} If there's an error clearing the data */ static clear(): Promise<void>; /** * Adds a listener for storage change events. * @param callback - Function called when storage data changes * @returns A function that removes the listener when called */ static addChangedListener(callback: (changes: { [key: string]: chrome.storage.StorageChange; }, areaName: string) => void): () => void; } export { StorageSync, ISyncStorage };