From b86b4680b6c2a3f0cceefaaf7c2e35417ec555df Mon Sep 17 00:00:00 2001 From: Shin'ya UEOKA Date: Sat, 5 Oct 2019 06:39:20 +0000 Subject: Make Blacklist class --- src/shared/Settings.ts | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'src/shared/Settings.ts') diff --git a/src/shared/Settings.ts b/src/shared/Settings.ts index 6250aae..2767820 100644 --- a/src/shared/Settings.ts +++ b/src/shared/Settings.ts @@ -1,26 +1,15 @@ import Keymaps from './settings/Keymaps'; import Search from './settings/Search'; import Properties from './settings/Properties'; +import Blacklist from './settings/Blacklist'; export default interface Settings { keymaps: Keymaps; search: Search; properties: Properties; - blacklist: string[]; + blacklist: Blacklist; } -export const blacklistValueOf = (o: any): string[] => { - if (!Array.isArray(o)) { - throw new TypeError(`"blacklist" is not an array of string`); - } - for (let x of o) { - if (typeof x !== 'string') { - throw new TypeError(`"blacklist" is not an array of string`); - } - } - return o as string[]; -}; - export const valueOf = (o: any): Settings => { let settings = { ...DefaultSetting }; for (let key of Object.keys(o)) { @@ -35,7 +24,7 @@ export const valueOf = (o: any): Settings => { settings.properties = Properties.fromJSON(o.properties); break; case 'blacklist': - settings.blacklist = blacklistValueOf(o.blacklist); + settings.blacklist = Blacklist.fromJSON(o.blacklist); break; default: throw new TypeError('unknown setting: ' + key); @@ -49,7 +38,7 @@ export const toJSON = (settings: Settings): any => { keymaps: settings.keymaps.toJSON(), search: settings.search.toJSON(), properties: settings.properties.toJSON(), - blacklist: settings.blacklist, + blacklist: settings.blacklist.toJSON(), }; }; @@ -134,5 +123,5 @@ export const DefaultSetting: Settings = { smoothscroll: false, complete: 'sbh' }), - blacklist: [] + blacklist: Blacklist.fromJSON([]), }; -- cgit v1.2.3