1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-21 02:33:46 +00:00
Files
browser/src/services/memoryStorage.service.ts
Thomas Rittson 44bf90cf6a Update storageService implementations (#1033)
* Add htmlStorageService.has

* Add memoryStorageService.has
2021-06-16 07:34:54 +10:00

31 lines
806 B
TypeScript

import { StorageService } from 'jslib-common/abstractions/storage.service';
export class MemoryStorageService implements StorageService {
private store = new Map<string, any>();
get<T>(key: string): Promise<T> {
if (this.store.has(key)) {
const obj = this.store.get(key);
return Promise.resolve(obj as T);
}
return Promise.resolve(null);
}
async has(key: string): Promise<boolean> {
return this.get(key) != null;
}
save(key: string, obj: any): Promise<any> {
if (obj == null) {
return this.remove(key);
}
this.store.set(key, obj);
return Promise.resolve();
}
remove(key: string): Promise<any> {
this.store.delete(key);
return Promise.resolve();
}
}