(key, defaultValue = null)
| 28 | * @returns {*} 解析后的值或默认值 |
| 29 | */ |
| 30 | export function getStorageJSON(key, defaultValue = null) { |
| 31 | try { |
| 32 | const item = getStorage(key); |
| 33 | return item ? JSON.parse(item) : defaultValue; |
| 34 | } catch (error) { |
| 35 | console.error(`Failed to parse JSON from storage (${key}):`, error); |
| 36 | return defaultValue; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * 安全地向 localStorage 写入数据 |
nothing calls this directly
no test coverage detected