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

Function toInt

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

Source from the content-addressed store, hash-verified

6type EnvSource = Record<string, string | undefined>;
7
8export const toInt = (
9 raw: string | undefined,
10 fallback: number,
11 name?: string
12): number => {
13 if (raw === undefined || raw === "") {
14 return fallback;
15 }
16
17 const parsed = parseInt(raw, 10);
18
19 if (Number.isNaN(parsed)) {
20 const label = name ?? "<int>";
21
22 throw new Error(
23 `${label}: invalid integer "${raw}". Set a numeric value or unset the variable to use the default (${String(fallback)}).`
24 );
25 }
26
27 return parsed;
28};
29
30/*
31 * Strict boolean parser. Accepts a small set of canonical truthy/falsy

Callers 7

validate.test.tsFile · 0.90
readCoreFunction · 0.85
readDatabaseFunction · 0.85
readUrlsFunction · 0.85
readRateLimitFunction · 0.85
readEmailFunction · 0.85
readValkeyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected