()
| 9 | */ |
| 10 | |
| 11 | const createLocalStorage = () => { |
| 12 | const store = {}; |
| 13 | |
| 14 | // $FlowFixMe https://github.com/facebook/flow/issues/285 |
| 15 | Object.defineProperties(store, { |
| 16 | getItem: { |
| 17 | get: () => (key: string) => store[key] || null, |
| 18 | }, |
| 19 | setItem: { |
| 20 | get: () => (key: string, value: string) => { |
| 21 | store[key] = value; |
| 22 | }, |
| 23 | }, |
| 24 | removeItem: { |
| 25 | get: () => (key: string) => { |
| 26 | delete store[key]; |
| 27 | }, |
| 28 | }, |
| 29 | clear: { |
| 30 | get: () => () => { |
| 31 | Object.keys(store).forEach((key: string) => { |
| 32 | store.removeItem(key); |
| 33 | }); |
| 34 | }, |
| 35 | }, |
| 36 | }); |
| 37 | |
| 38 | return store; |
| 39 | }; |
| 40 | |
| 41 | window.localStorage = createLocalStorage(); |
no outgoing calls
no test coverage detected
searching dependent graphs…