Completed
Push — main ( cbb93c...4a83d6 )
by Alberto
26s queued 12s
created

LocalStorageAdapter.set   A

Complexity

Conditions 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
1
import StorageAdapterInterface from "./storage-adapter-interface";
2
3
/**
4
 * Local Storage adapter
5
 */
6
export default class LocalStorageAdapter implements StorageAdapterInterface {
7
    /**
8
     * {@inheritdoc}
9
     *
10
     * @todo JSON parse if value a re json stringified
11
     */
12
    get(key: string): Promise<any> {
13
        return Promise.resolve(localStorage.getItem(key));
14
    }
15
16
    /**
17
     * {@inheritdoc}
18
     *
19
     * @todo JSON stringify value that represents objects
20
     */
21
    set(key: string, value: any): Promise<any> {
22
        return Promise.resolve(localStorage.setItem(key, value));
23
    }
24
25
    /**
26
     * @inheritdoc
27
     */
28
    remove(key: string): Promise<any> {
29
        return Promise.resolve(localStorage.removeItem(key));
30
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35
    empty(): Promise<any>  {
36
        return Promise.resolve(localStorage.clear());
37
    }
38
}
39