n0mbers/src/storage.ts

14 lines
383 B
TypeScript
Raw Normal View History

2022-02-22 22:52:50 +01:00
export function setItem(k: string, v: string): void {
return localStorage.setItem(k, v)
}
export function getItem(k: string): string | null
export function getItem(k: string, defaultValue: any): string
export function getItem(k: string, defaultValue?: any): string | null {
try {
return localStorage.getItem(k) ?? null
}
catch (e) {
return defaultValue ?? null
}
}