apple2js/js/prefs.ts
2021-12-21 12:35:26 -08:00

24 lines
591 B
TypeScript

const havePrefs = typeof window.localStorage !== 'undefined';
export default class Prefs {
havePrefs() {
return havePrefs;
}
readPref(name: string): string | null
readPref(name: string, defaultValue: string): string
readPref(name: string, defaultValue: string | null = null) {
if (havePrefs) {
return window.localStorage.getItem(name) ?? defaultValue;
}
return defaultValue;
}
writePref(name: string, value: string) {
if (havePrefs) {
window.localStorage.setItem(name, value);
}
}
}