diff options
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/Settings.ts | 9 | ||||
-rw-r--r-- | src/shared/operations.ts | 26 | ||||
-rw-r--r-- | src/shared/property-defs.ts | 6 |
3 files changed, 22 insertions, 19 deletions
diff --git a/src/shared/Settings.ts b/src/shared/Settings.ts index 2a392df..d338e2a 100644 --- a/src/shared/Settings.ts +++ b/src/shared/Settings.ts @@ -21,13 +21,6 @@ export default interface Settings { blacklist: string[]; } -const DefaultProperties: Properties = PropertyDefs.defs.reduce( - (o: {[name: string]: PropertyDefs.Type}, def) => { - o[def.name] = def.defaultValue; - return o; - }, {}) as Properties; - - export const keymapsValueOf = (o: any): Keymaps => { return Object.keys(o).reduce((keymaps: Keymaps, key: string): Keymaps => { let op = operations.valueOf(o[key]); @@ -82,7 +75,7 @@ export const propertiesValueOf = (o: any): Properties => { } } return { - ...DefaultProperties, + ...PropertyDefs.defaultValues, ...o, }; }; diff --git a/src/shared/operations.ts b/src/shared/operations.ts index 2df2e67..1ce5256 100644 --- a/src/shared/operations.ts +++ b/src/shared/operations.ts @@ -368,7 +368,9 @@ export type Operation = const assertOptionalBoolean = (obj: any, name: string) => { if (Object.prototype.hasOwnProperty.call(obj, name) && typeof obj[name] !== 'boolean') { - throw new TypeError(`Not a boolean parameter: '${name}'`); + throw new TypeError( + `Not a boolean parameter: '${name} (${typeof obj[name]})'`, + ); } }; @@ -376,7 +378,9 @@ const assertOptionalString = (obj: any, name: string, values?: string[]) => { if (Object.prototype.hasOwnProperty.call(obj, name)) { let value = obj[name]; if (typeof value !== 'string') { - throw new TypeError(`Not a string parameter: '${name}'`); + throw new TypeError( + `Not a string parameter: '${name}' (${typeof value})`, + ); } if (values && values.length && values.indexOf(value) === -1) { // eslint-disable-next-line max-len @@ -421,32 +425,32 @@ export const valueOf = (o: any): Operation => { assertOptionalBoolean(o, 'background'); return { type: FOLLOW_START, - newTab: Boolean(typeof o.newTab === undefined ? false : o.newTab), - background: Boolean(typeof o.background === undefined ? true : o.background), // eslint-disable-line max-len + newTab: Boolean(typeof o.newTab === 'undefined' ? false : o.newTab), + background: Boolean(typeof o.background === 'undefined' ? true : o.background), // eslint-disable-line max-len }; case PAGE_HOME: assertOptionalBoolean(o, 'newTab'); return { type: PAGE_HOME, - newTab: Boolean(typeof o.newTab === undefined ? false : o.newTab), + newTab: Boolean(typeof o.newTab === 'undefined' ? false : o.newTab), }; case TAB_CLOSE: assertOptionalString(o, 'select', ['left', 'right']); return { type: TAB_CLOSE, - select: (typeof o.select === undefined ? 'right' : o.select), + select: (typeof o.select === 'undefined' ? 'right' : o.select), }; case TAB_RELOAD: assertOptionalBoolean(o, 'cache'); return { type: TAB_RELOAD, - cache: Boolean(typeof o.cache === undefined ? false : o.cache), + cache: Boolean(typeof o.cache === 'undefined' ? false : o.cache), }; case URLS_PASTE: assertOptionalBoolean(o, 'newTab'); return { type: URLS_PASTE, - newTab: Boolean(typeof o.newTab === undefined ? false : o.newTab), + newTab: Boolean(typeof o.newTab === 'undefined' ? false : o.newTab), }; case INTERNAL_OPEN_URL: assertOptionalBoolean(o, 'newTab'); @@ -456,9 +460,9 @@ export const valueOf = (o: any): Operation => { return { type: INTERNAL_OPEN_URL, url: o.url, - newTab: Boolean(typeof o.newTab === undefined ? false : o.newTab), - newWindow: Boolean(typeof o.newWindow === undefined ? false : o.newWindow), // eslint-disable-line max-len - background: Boolean(typeof o.background === undefined ? true : o.background), // eslint-disable-line max-len + newTab: Boolean(typeof o.newTab === 'undefined' ? false : o.newTab), + newWindow: Boolean(typeof o.newWindow === 'undefined' ? false : o.newWindow), // eslint-disable-line max-len + background: Boolean(typeof o.background === 'undefined' ? true : o.background), // eslint-disable-line max-len }; case CANCEL: case ADDON_ENABLE: diff --git a/src/shared/property-defs.ts b/src/shared/property-defs.ts index 6315030..fec9f80 100644 --- a/src/shared/property-defs.ts +++ b/src/shared/property-defs.ts @@ -48,3 +48,9 @@ export const defs: Def[] = [ 'which are completed at the open page', 'sbh'), ]; + +export const defaultValues = { + hintchars: 'abcdefghijklmnopqrstuvwxyz', + smoothscroll: false, + complete: 'sbh', +}; |