Skip to content

Commit

Permalink
added the ability to remove keys from a store
Browse files Browse the repository at this point in the history
  • Loading branch information
sghsri committed May 2, 2024
1 parent 35a6524 commit a44ab8f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
15 changes: 15 additions & 0 deletions src/storage/createStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ export type Store<T = {}> = {
*/
set(values: Partial<Serializable<T>>): Promise<void>;

/**
* Removes a specific key from the store.
* @param key the key to remove from the store
*/
remove<K extends keyof T>(key: K): Promise<void>;

/**
* Returns a promise that resolves to the entire contents of the store.
*/
Expand Down Expand Up @@ -237,6 +243,15 @@ function createStore<T>(
});
};

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();
Expand Down

1 comment on commit a44ab8f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines Statements Branches Functions
Coverage: 8%
8.38% (27/322) 12.79% (11/86) 8.64% (7/81)

Please sign in to comment.