From a44ab8fbeead5a7b6eda93a9bc4b54978ff1ae91 Mon Sep 17 00:00:00 2001 From: Sriram Hariharan Date: Wed, 1 May 2024 23:28:02 -0500 Subject: [PATCH] added the ability to remove keys from a store --- package.json | 2 +- src/storage/createStore.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 4e1c8cb..7dafb80 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chrome-extension-toolkit", - "version": "0.0.81", + "version": "0.0.82", "description": "A template for creating npm packages using TypeScript and VSCode", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/storage/createStore.ts b/src/storage/createStore.ts index a76f706..2f280d9 100644 --- a/src/storage/createStore.ts +++ b/src/storage/createStore.ts @@ -72,6 +72,12 @@ export type Store = { */ set(values: Partial>): Promise; + /** + * Removes a specific key from the store. + * @param key the key to remove from the store + */ + remove(key: K): Promise; + /** * Returns a promise that resolves to the entire contents of the store. */ @@ -237,6 +243,15 @@ function createStore( }); }; + store.remove = async (key: string) => { + if (!hasInitialized) { + await store.initialize(); + } + + const actualKey = `${storeId}:${key}`; + await chrome.storage[area].remove(actualKey); + }; + store.all = async () => { if (!hasInitialized) { await store.initialize();