(key, defaultValue = null)
| 12 | * @returns {*} 存储的值或默认值 |
| 13 | */ |
| 14 | export function getStorage(key, defaultValue = null) { |
| 15 | try { |
| 16 | const item = localStorage.getItem(key); |
| 17 | return item !== null ? item : defaultValue; |
| 18 | } catch (error) { |
| 19 | console.error(`Failed to read from storage (${key}):`, error); |
| 20 | return defaultValue; |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * 从 localStorage 读取 JSON 数据 |
no outgoing calls
no test coverage detected