( key: string, defaultValue: T, storage = localStorage )
| 25 | } |
| 26 | |
| 27 | export function get<T>( |
| 28 | key: string, |
| 29 | defaultValue: T, |
| 30 | storage = localStorage |
| 31 | ): T { |
| 32 | const value = storage.getItem(keyBuilder(key)); |
| 33 | if (!value) { |
| 34 | return defaultValue; |
| 35 | } |
| 36 | |
| 37 | try { |
| 38 | return JSON.parse(value); |
| 39 | } catch (e) { |
| 40 | return defaultValue; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | export function set<T>(key: string, value: T, storage = localStorage) { |
| 45 | storage.setItem(keyBuilder(key), JSON.stringify(value)); |
no test coverage detected