search engine validation
This commit is contained in:
parent
27aa739caf
commit
c382715405
2 changed files with 85 additions and 0 deletions
|
@ -23,11 +23,39 @@ const validateKeymaps = (keymaps) => {
|
|||
}
|
||||
};
|
||||
|
||||
const validateSearch = (search) => {
|
||||
let engines = search.engines;
|
||||
for (let key of Object.keys(engines)) {
|
||||
if (/\s/.test(key)) {
|
||||
throw new Error(
|
||||
`While space in search engine name is not allowed: "${key}"`
|
||||
);
|
||||
}
|
||||
let url = engines[key];
|
||||
if (!url.match(/{}/)) {
|
||||
throw new Error(`No {}-placeholders in URL of "${key}"`);
|
||||
}
|
||||
if (url.match(/{}/g).length > 1) {
|
||||
throw new Error(`Multiple {}-placeholders in URL of "${key}"`);
|
||||
}
|
||||
}
|
||||
|
||||
if (!search.default) {
|
||||
throw new Error(`Default engine is not set`);
|
||||
}
|
||||
if (!Object.keys(engines).includes(search.default)) {
|
||||
throw new Error(`Default engine "${search.default}" not found`);
|
||||
}
|
||||
};
|
||||
|
||||
const validate = (settings) => {
|
||||
validateInvalidTopKeys(settings);
|
||||
if (settings.keymaps) {
|
||||
validateKeymaps(settings.keymaps);
|
||||
}
|
||||
if (settings.search) {
|
||||
validateSearch(settings.search);
|
||||
}
|
||||
};
|
||||
|
||||
export { validate };
|
||||
|
|
Reference in a new issue