( raw: string | undefined, fallback: number, name?: string )
| 77 | ): boolean => (raw === undefined ? defaultValue : toBool(raw, name)); |
| 78 | |
| 79 | export const toFloat = ( |
| 80 | raw: string | undefined, |
| 81 | fallback: number, |
| 82 | name?: string |
| 83 | ): number => { |
| 84 | if (raw === undefined || raw === "") { |
| 85 | return fallback; |
| 86 | } |
| 87 | |
| 88 | const parsed = Number.parseFloat(raw); |
| 89 | |
| 90 | if (Number.isNaN(parsed)) { |
| 91 | const label = name ?? "<float>"; |
| 92 | |
| 93 | throw new Error( |
| 94 | `${label}: invalid number "${raw}". Set a numeric value or unset the variable to use the default (${String(fallback)}).` |
| 95 | ); |
| 96 | } |
| 97 | |
| 98 | return parsed; |
| 99 | }; |
| 100 | |
| 101 | export const nonEmpty = (raw: string | undefined, fallback: string): string => { |
| 102 | if (raw === undefined || raw === "") { |
no outgoing calls
no test coverage detected