MCPcopy Create free account
hub / github.com/boringstack-xyz/boringstack / toFloat

Function toFloat

apps/api/src/config/env/validate.ts:79–99  ·  view source on GitHub ↗
(
  raw: string | undefined,
  fallback: number,
  name?: string
)

Source from the content-addressed store, hash-verified

77): boolean => (raw === undefined ? defaultValue : toBool(raw, name));
78
79export 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
101export const nonEmpty = (raw: string | undefined, fallback: string): string => {
102 if (raw === undefined || raw === "") {

Callers 2

validate.test.tsFile · 0.90
readSentryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected