Skip to content

Commit

Permalink
feat: add new utils
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelYuhe committed Dec 11, 2023
1 parent db0ad57 commit 847d199
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export function setStorage<V = any>(key: string, value: V) {
return new Promise((resolve, reject) => {
chrome.storage.local.set({ [key]: value }, () => {
if (chrome.runtime.lastError) {
reject(chrome.runtime.lastError);
} else {
resolve(true);
}
});
});
}

export function getStorage<V = any>(key: string): Promise<V | undefined> {
return new Promise((resolve, reject) => {
chrome.storage.local.get(key, (result) => {
if (chrome.runtime.lastError) {
reject(chrome.runtime.lastError);
} else {
resolve(result[key]);
}
});
});
}

0 comments on commit 847d199

Please sign in to comment.