diff --git a/src/preferences/Preference.ts b/src/preferences/Preference.ts new file mode 100644 index 0000000..fcaba33 --- /dev/null +++ b/src/preferences/Preference.ts @@ -0,0 +1,22 @@ +export class Preference { + private key: string; + private description: string; + private value?: T; + private defaultValue?: T; + + constructor(key: string, description: string, defaultValue?: T) { + this.key = key; + this.description = description; + this.defaultValue = defaultValue; + this.value = this.load(); + } + + private load() { + const value = localStorage.getItem(this.key); + + if (value) { + return JSON.parse(value); + } + return this.defaultValue; + } +} \ No newline at end of file diff --git a/src/preferences/index.ts b/src/preferences/index.ts new file mode 100644 index 0000000..e69de29