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

Function toBool

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

Source from the content-addressed store, hash-verified

39const BOOL_FALSE_TOKENS = new Set(["false", "0", "no", "off", ""]);
40
41export const toBool = (raw: string | undefined, name?: string): boolean => {
42 if (raw === undefined) {
43 return false;
44 }
45
46 const normalized = raw.trim().toLowerCase();
47
48 if (BOOL_TRUE_TOKENS.has(normalized)) {
49 return true;
50 }
51
52 if (BOOL_FALSE_TOKENS.has(normalized)) {
53 return false;
54 }
55
56 const label = name ?? "<bool>";
57 const accepted = [...BOOL_TRUE_TOKENS, ...BOOL_FALSE_TOKENS]
58 .filter((token) => token !== "")
59 .join(", ");
60
61 throw new Error(
62 `${label}: invalid boolean "${raw}". Accepted (case-insensitive): ${accepted}.`
63 );
64};
65
66/**
67 * For booleans whose schema default is `true`. Calling `toBool` alone

Callers 8

validate.test.tsFile · 0.90
toBoolWithDefaultFunction · 0.85
readDatabaseFunction · 0.85
readAuthFunction · 0.85
readRateLimitFunction · 0.85
readAIFunction · 0.85
readMultiTenantFunction · 0.85
readBillingFunction · 0.85

Calls 1

hasMethod · 0.45

Tested by

no test coverage detected