( raw: string | undefined, opts: FloatFlagOptions, )
| 46 | * input. Accepts integers and decimals. |
| 47 | */ |
| 48 | export function parseNumericFlag( |
| 49 | raw: string | undefined, |
| 50 | opts: FloatFlagOptions, |
| 51 | ): number | undefined { |
| 52 | if (raw === undefined) return undefined; |
| 53 | if (!NUMERIC_RE.test(raw)) { |
| 54 | errorBox(`Invalid ${opts.flag}`, `Got "${raw}". Must be a number${rangeSuffix(opts)}.`); |
| 55 | process.exit(1); |
| 56 | } |
| 57 | const n = Number.parseFloat(raw); |
| 58 | if (!Number.isFinite(n)) { |
| 59 | errorBox(`Invalid ${opts.flag}`, `Got "${raw}". Must be a finite number.`); |
| 60 | process.exit(1); |
| 61 | } |
| 62 | enforceRange(opts.flag, raw, n, opts); |
| 63 | return n; |
| 64 | } |
| 65 | |
| 66 | function enforceRange( |
| 67 | flag: string, |
no test coverage detected