(store: KeyValueStore)
| 40 | |
| 41 | /** What this browser last said, or the default when it said nothing usable. */ |
| 42 | export function readReaderLevel(store: KeyValueStore): DepthLevel { |
| 43 | let raw: string | null; |
| 44 | try { |
| 45 | raw = store.getItem(READER_LEVEL_KEY); |
| 46 | } catch { |
| 47 | return READER_LEVEL_DEFAULT; |
| 48 | } |
| 49 | // An empty entry is not a zero. `Number('')` is 0, and a browser that |
| 50 | // wrote a blank would otherwise hand every reader the vibe coder's level |
| 51 | // and call it their choice. |
| 52 | if (raw === null || raw.trim().length === 0) { |
| 53 | return READER_LEVEL_DEFAULT; |
| 54 | } |
| 55 | const value = Number(raw); |
| 56 | if (!Number.isInteger(value) || value < 0 || value > MAX_DEPTH) { |
| 57 | return READER_LEVEL_DEFAULT; |
| 58 | } |
| 59 | return clampDepth(value); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Remember the level. A storage that refuses is not an error worth showing. |
no test coverage detected