swc/crates/swc_bundler/tests/.cache/deno/445f0f6ca18de28c77eaa54e49643160d671395e.ts
2021-11-09 20:42:49 +09:00

22 lines
530 B
TypeScript

// Loaded from https://deno.land/x/cliffy@v0.18.0/flags/types/boolean.ts
import type { ITypeHandler, ITypeInfo } from "../types.ts";
/** Boolean type handler. Excepts `true`, `false`, `1`, `0` */
export const boolean: ITypeHandler<boolean> = (
{ label, name, value, type }: ITypeInfo,
): boolean => {
if (~["1", "true"].indexOf(value)) {
return true;
}
if (~["0", "false"].indexOf(value)) {
return false;
}
throw new Error(
`${label} "${name}" must be of type "${type}", but got "${value}".`,
);
};