| Total Complexity | 4 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 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 | } |
||
| 39 |