From 9c0fffe1acd86bd752356f9a8d66429214a77ff3 Mon Sep 17 00:00:00 2001 From: jacoobes Date: Wed, 26 Jan 2022 21:51:45 -0600 Subject: [PATCH] docs for parseBool --- src/handler/utils/preprocessors/args.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/handler/utils/preprocessors/args.ts b/src/handler/utils/preprocessors/args.ts index 2629a4b..29987d1 100644 --- a/src/handler/utils/preprocessors/args.ts +++ b/src/handler/utils/preprocessors/args.ts @@ -17,12 +17,19 @@ export namespace Utils { const val = Number.parseInt(arg); return val === NaN ? Err(onFailure) : Ok(val); } - + /** + * + * @param {string} arg + * @param {possibleOutput} onFailure + * @param { {yesRegex: RegExp, noRegex: RegExp} } regexes + * @returns { ArgType } attemps to parse `args` as a boolean + */ export function parseBool( arg: string, onFailure: possibleOutput = `Cannot parse ${arg} as a boolean`, regexes : {yesRegex: RegExp, noRegex: RegExp} = {yesRegex : /(yes|y|👍)/gi, noRegex : /(no|n|👎)/gi} ): ArgType { + if(arg.match(regexes.yesRegex)) { return Ok(true); }