Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(flags): print formatted error message for boolean and number vali…
…dation errors (#189)
- Loading branch information
Showing
4 changed files
with
25 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
import type { ITypeHandler, ITypeInfo } from "../types.ts"; | ||
import { InvalidTypeError } from "../_errors.ts"; | ||
|
||
/** Boolean type handler. Excepts `true`, `false`, `1`, `0` */ | ||
export const boolean: ITypeHandler<boolean> = ( | ||
{ label, name, value, type }: ITypeInfo, | ||
type: ITypeInfo, | ||
): boolean => { | ||
if (~["1", "true"].indexOf(value)) { | ||
if (~["1", "true"].indexOf(type.value)) { | ||
return true; | ||
} | ||
|
||
if (~["0", "false"].indexOf(value)) { | ||
if (~["0", "false"].indexOf(type.value)) { | ||
return false; | ||
} | ||
|
||
throw new Error( | ||
`${label} "${name}" must be of type "${type}", but got "${value}".`, | ||
); | ||
throw new InvalidTypeError(type); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,11 @@ | ||
import type { ITypeHandler, ITypeInfo } from "../types.ts"; | ||
import { InvalidTypeError } from "../_errors.ts"; | ||
|
||
/** Number type handler. Excepts any numeric value. */ | ||
export const number: ITypeHandler<number> = ( | ||
{ label, name, value, type }: ITypeInfo, | ||
): number => { | ||
if (isNaN(Number(value))) { | ||
throw new Error( | ||
`${label} "${name}" must be of type "${type}", but got "${value}".`, | ||
); | ||
export const number: ITypeHandler<number> = (type: ITypeInfo): number => { | ||
if (!isNaN(Number(type.value))) { | ||
return parseFloat(type.value); | ||
} | ||
|
||
return parseFloat(value); | ||
throw new InvalidTypeError(type); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// deno-lint-ignore no-unused-vars | ||
import { React } from "https://deno.land/x/pagic/mod.ts"; | ||
|
||
export default { | ||
|