mirror of
https://github.com/swc-project/swc.git
synced 2024-12-23 05:32:09 +03:00
18 lines
463 B
TypeScript
18 lines
463 B
TypeScript
// Loaded from https://deno.land/x/cliffy@v0.18.0/flags/types/number.ts
|
|
|
|
|
|
import type { ITypeHandler, ITypeInfo } from "../types.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}".`,
|
|
);
|
|
}
|
|
|
|
return parseFloat(value);
|
|
};
|