(key: string)
| 31 | } |
| 32 | }, |
| 33 | get(key: string): any { |
| 34 | const timeSignLen = timeSign.length; |
| 35 | let index = 0; |
| 36 | let time = 0; |
| 37 | let res; |
| 38 | try { |
| 39 | res = this.storage.getItem(key); |
| 40 | } catch { |
| 41 | console.error('get storage error: the key is', key); |
| 42 | } |
| 43 | if (res) { |
| 44 | index = res.indexOf(timeSign); |
| 45 | time = +res.slice(0, index); |
| 46 | if (time > new Date().getTime()) { |
| 47 | res = res.slice(index + timeSignLen); |
| 48 | try { |
| 49 | res = JSON.parse(res); |
| 50 | } catch { |
| 51 | // ignore |
| 52 | } |
| 53 | } else { |
| 54 | // timeout remove storage |
| 55 | res = null; |
| 56 | this.storage.removeItem(key); |
| 57 | } |
| 58 | return res; |
| 59 | } |
| 60 | |
| 61 | return res; |
| 62 | }, |
| 63 | remove(key: string, callback?: () => void): void { |
| 64 | this.storage.removeItem(key); |
| 65 | callback?.(); |
nothing calls this directly
no outgoing calls
no test coverage detected