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

src/services/adapters/local-storage-adapter.ts   A

Complexity

Total Complexity 4
Complexity/F 1

Size

Lines of Code 39
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 15
mnd 0
bc 0
fnc 4
dl 0
loc 39
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A LocalStorageAdapter.empty 0 6 1
A LocalStorageAdapter.get 0 7 1
A LocalStorageAdapter.remove 0 6 1
A LocalStorageAdapter.set 0 8 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