diff options
Diffstat (limited to 'src/background/usecases/parsers.ts')
-rw-r--r-- | src/background/usecases/parsers.ts | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/src/background/usecases/parsers.ts b/src/background/usecases/parsers.ts index 99ff2eb..23a6193 100644 --- a/src/background/usecases/parsers.ts +++ b/src/background/usecases/parsers.ts @@ -1,36 +1,39 @@ -import Properties from '../../shared/settings/Properties'; +import Properties from "../../shared/settings/Properties"; const mustNumber = (v: any): number => { const num = Number(v); if (isNaN(num)) { - throw new Error('Not number: ' + v); + throw new Error("Not number: " + v); } return num; }; -const parseSetOption = ( - args: string, -): any[] => { - let [key, value]: any[] = args.split('='); +const parseSetOption = (args: string): any[] => { + let [key, value]: any[] = args.split("="); if (value === undefined) { - value = !key.startsWith('no'); + value = !key.startsWith("no"); key = value ? key : key.slice(2); } const def = Properties.def(key); if (!def) { - throw new Error('Unknown property: ' + key); + throw new Error("Unknown property: " + key); } - if (def.type === 'boolean' && typeof value !== 'boolean' || - def.type !== 'boolean' && typeof value === 'boolean') { - throw new Error('Invalid argument: ' + args); + if ( + (def.type === "boolean" && typeof value !== "boolean") || + (def.type !== "boolean" && typeof value === "boolean") + ) { + throw new Error("Invalid argument: " + args); } switch (def.type) { - case 'string': return [key, value]; - case 'number': return [key, mustNumber(value)]; - case 'boolean': return [key, value]; - default: - throw new Error('Unknown property type: ' + def.type); + case "string": + return [key, value]; + case "number": + return [key, mustNumber(value)]; + case "boolean": + return [key, value]; + default: + throw new Error("Unknown property type: " + def.type); } }; |