aboutsummaryrefslogtreecommitdiff
path: root/src/shared/Settings.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/Settings.ts')
-rw-r--r--src/shared/Settings.ts37
1 files changed, 5 insertions, 32 deletions
diff --git a/src/shared/Settings.ts b/src/shared/Settings.ts
index e2bb3f4..6250aae 100644
--- a/src/shared/Settings.ts
+++ b/src/shared/Settings.ts
@@ -1,12 +1,6 @@
-import * as PropertyDefs from './property-defs';
import Keymaps from './settings/Keymaps';
import Search from './settings/Search';
-
-export interface Properties {
- hintchars: string;
- smoothscroll: boolean;
- complete: string;
-}
+import Properties from './settings/Properties';
export default interface Settings {
keymaps: Keymaps;
@@ -15,27 +9,6 @@ export default interface Settings {
blacklist: string[];
}
-export const propertiesValueOf = (o: any): Properties => {
- let defNames = new Set(PropertyDefs.defs.map(def => def.name));
- let unknownName = Object.keys(o).find(name => !defNames.has(name));
- if (unknownName) {
- throw new TypeError(`Unknown property name: "${unknownName}"`);
- }
-
- for (let def of PropertyDefs.defs) {
- if (!Object.prototype.hasOwnProperty.call(o, def.name)) {
- continue;
- }
- if (typeof o[def.name] !== def.type) {
- throw new TypeError(`property "${def.name}" is not ${def.type}`);
- }
- }
- return {
- ...PropertyDefs.defaultValues,
- ...o,
- };
-};
-
export const blacklistValueOf = (o: any): string[] => {
if (!Array.isArray(o)) {
throw new TypeError(`"blacklist" is not an array of string`);
@@ -59,7 +32,7 @@ export const valueOf = (o: any): Settings => {
settings.search = Search.fromJSON(o.search);
break;
case 'properties':
- settings.properties = propertiesValueOf(o.properties);
+ settings.properties = Properties.fromJSON(o.properties);
break;
case 'blacklist':
settings.blacklist = blacklistValueOf(o.blacklist);
@@ -75,7 +48,7 @@ export const toJSON = (settings: Settings): any => {
return {
keymaps: settings.keymaps.toJSON(),
search: settings.search.toJSON(),
- properties: settings.properties,
+ properties: settings.properties.toJSON(),
blacklist: settings.blacklist,
};
};
@@ -156,10 +129,10 @@ export const DefaultSetting: Settings = {
'wikipedia': 'https://en.wikipedia.org/w/index.php?search={}'
}
}),
- properties: {
+ properties: Properties.fromJSON({
hintchars: 'abcdefghijklmnopqrstuvwxyz',
smoothscroll: false,
complete: 'sbh'
- },
+ }),
blacklist: []
};