-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBrowserBacktraceStorage.ts
More file actions
63 lines (52 loc) · 1.55 KB
/
BrowserBacktraceStorage.ts
File metadata and controls
63 lines (52 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { BacktraceStorageModule } from '@backtrace/sdk-core';
export class BrowserBacktraceStorage implements BacktraceStorageModule {
constructor(private readonly _storage = window.localStorage) {}
public async set(key: string, value: string): Promise<boolean> {
return this.setSync(key, value);
}
public async remove(key: string): Promise<boolean> {
return this.removeSync(key);
}
public async get(key: string): Promise<string | undefined> {
return this.getSync(key);
}
public async has(key: string): Promise<boolean> {
return this.hasSync(key);
}
public setSync(key: string, value: string): boolean {
try {
this._storage.setItem(key, value);
return true;
} catch {
return false;
}
}
public removeSync(key: string): boolean {
try {
this._storage.removeItem(key);
return true;
} catch {
return false;
}
}
public getSync(key: string): string | undefined {
try {
return this._storage.getItem(key) ?? undefined;
} catch {
return undefined;
}
}
public hasSync(key: string): boolean {
return key in this._storage;
}
public async *keys(): AsyncGenerator<string> {
for (const key of Object.keys(this._storage)) {
yield key;
}
}
public *keysSync(): Generator<string> {
for (const key of Object.keys(this._storage)) {
yield key;
}
}
}