test
Some checks failed
test / Run tests (push) Failing after 6s
build / Build (push) Failing after 9s
Some checks failed
test / Run tests (push) Failing after 6s
build / Build (push) Failing after 9s
This commit is contained in:
33
packages/chrome-extension-mock/storage.ts
Normal file
33
packages/chrome-extension-mock/storage.ts
Normal file
@ -0,0 +1,33 @@
|
||||
export default class Storage {
|
||||
sync = new CrhomeStorage();
|
||||
local = new CrhomeStorage();
|
||||
session = new CrhomeStorage();
|
||||
}
|
||||
|
||||
export class CrhomeStorage {
|
||||
data: any = {};
|
||||
|
||||
get(key: string, callback: (data: any) => void) {
|
||||
if (key === null) {
|
||||
callback(this.data);
|
||||
return;
|
||||
}
|
||||
callback({ [key]: this.data[key] });
|
||||
}
|
||||
|
||||
set(data: any, callback: () => void) {
|
||||
this.data = Object.assign(this.data, data);
|
||||
callback();
|
||||
}
|
||||
|
||||
remove(keys: string | string[], callback: () => void) {
|
||||
if (typeof keys === "string") {
|
||||
delete this.data[keys];
|
||||
} else {
|
||||
keys.forEach((key) => {
|
||||
delete this.data[key];
|
||||
});
|
||||
}
|
||||
callback();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user