mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
fmt, toPositiveInt
This commit is contained in:
@@ -30,13 +30,9 @@ export namespace Utils {
|
||||
regexes : {yesRegex: RegExp, noRegex: RegExp} = {yesRegex : /(yes|y|👍)/gi, noRegex : /(no|n|👎)/gi}
|
||||
): ArgType<boolean> {
|
||||
|
||||
if(arg.match(regexes.yesRegex)) {
|
||||
return Ok(true);
|
||||
}
|
||||
if(arg.match(regexes.noRegex)) {
|
||||
return Ok(false)
|
||||
}
|
||||
return Err(onFailure)
|
||||
if(arg.match(regexes.yesRegex)) return Ok(true);
|
||||
if(arg.match(regexes.noRegex)) return Ok(false);
|
||||
return Err(onFailure);
|
||||
}
|
||||
/**
|
||||
*
|
||||
@@ -48,6 +44,10 @@ export namespace Utils {
|
||||
return Ok(arg.split(sep));
|
||||
}
|
||||
|
||||
export function toPositiveInt(arg: string, onFailure: possibleOutput) : ArgType<number> {
|
||||
return Utils.parseInt(arg, onFailure).andThen( num => Ok(num > 0 ? num : Math.abs(num)))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user