MCPcopy Index your code
hub / github.com/OneNoteDev/WebClipper / LocalStorage

Class LocalStorage

src/scripts/storage/localStorage.ts:3–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1import {Storage} from "./storage";
2
3export class LocalStorage implements Storage {
4 public getValue(key: string): string {
5 let result: string;
6 if (window.localStorage) {
7 result = window.localStorage.getItem(key);
8 if (!result) {
9 // Somehow we stored an invalid value. Destroy it!
10 this.removeKey(key);
11 }
12 }
13 return result;
14 }
15
16 public getValues(keys: string[]): {} {
17 let values = {};
18 if (window.localStorage && keys) {
19 for (let i = 0; i < keys.length; i++) {
20 let result = window.localStorage.getItem(keys[i]);
21 if (!result) {
22 // Somehow we stored an invalid value. Destroy it!
23 this.removeKey(keys[i]);
24 } else {
25 values[keys[i]] = result;
26 }
27 }
28 }
29 return values;
30 }
31
32 public setValue(key: string, value: string): void {
33 if (window.localStorage) {
34 if (!value) {
35 window.localStorage.removeItem(key);
36 } else {
37 window.localStorage.setItem(key, value);
38 }
39 }
40 }
41
42 public removeKey(key: string): boolean {
43 if (window.localStorage) {
44 window.localStorage.removeItem(key);
45 }
46
47 return true;
48 }
49}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected