()
| 220 | * working with no record at all, which is the same state a first visit is in. |
| 221 | */ |
| 222 | export function browserStore(): KeyValueStore { |
| 223 | try { |
| 224 | const probe = globalThis.localStorage; |
| 225 | if (probe !== undefined && probe !== null) { |
| 226 | return probe; |
| 227 | } |
| 228 | } catch { |
| 229 | // falls through to the forgetful store |
| 230 | } |
| 231 | const memory = new Map<string, string>(); |
| 232 | return { |
| 233 | getItem: (key) => memory.get(key) ?? null, |
| 234 | setItem: (key, value) => { |
| 235 | memory.set(key, value); |
| 236 | }, |
| 237 | }; |
| 238 | } |
no test coverage detected