Fix settings parsing
This commit is contained in:
parent
a603c72055
commit
ff85797ffc
2 changed files with 21 additions and 11 deletions
|
@ -101,17 +101,23 @@ export const blacklistValueOf = (o: any): string[] => {
|
||||||
|
|
||||||
export const valueOf = (o: any): Settings => {
|
export const valueOf = (o: any): Settings => {
|
||||||
let settings = { ...DefaultSetting };
|
let settings = { ...DefaultSetting };
|
||||||
if (Object.prototype.hasOwnProperty.call(o, 'keymaps')) {
|
for (let key of Object.keys(o)) {
|
||||||
settings.keymaps = keymapsValueOf(o.keymaps);
|
switch (key) {
|
||||||
}
|
case 'keymaps':
|
||||||
if (Object.prototype.hasOwnProperty.call(o, 'search')) {
|
settings.keymaps = keymapsValueOf(o.keymaps);
|
||||||
settings.search = searchValueOf(o.search);
|
break;
|
||||||
}
|
case 'search':
|
||||||
if (Object.prototype.hasOwnProperty.call(o, 'properties')) {
|
settings.search = searchValueOf(o.search);
|
||||||
settings.properties = propertiesValueOf(o.properties);
|
break;
|
||||||
}
|
case 'properties':
|
||||||
if (Object.prototype.hasOwnProperty.call(o, 'blacklist')) {
|
settings.properties = propertiesValueOf(o.properties);
|
||||||
settings.blacklist = blacklistValueOf(o.blacklist);
|
break;
|
||||||
|
case 'blacklist':
|
||||||
|
settings.blacklist = blacklistValueOf(o.blacklist);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new TypeError('unknown setting: ' + key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return settings;
|
return settings;
|
||||||
};
|
};
|
||||||
|
|
|
@ -186,5 +186,9 @@ describe('Settings', () => {
|
||||||
expect(value.search.engines).to.be.an('object');
|
expect(value.search.engines).to.be.an('object');
|
||||||
expect(value.blacklist).to.be.empty;
|
expect(value.blacklist).to.be.empty;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throws a TypeError with an unknown field', () => {
|
||||||
|
expect(() => settings.valueOf({ name: 'alice' })).to.throw(TypeError)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue