mirror of
https://github.com/whscullin/apple2js.git
synced 2024-01-12 14:14:38 +00:00
24 lines
591 B
TypeScript
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);
|
|
}
|
|
}
|
|
}
|