MCPcopy Create free account
hub / github.com/code-pushup/cli / coerceBooleanValue

Function coerceBooleanValue

packages/utils/src/lib/env.ts:24–50  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

22}
23
24export function coerceBooleanValue(value: unknown): boolean | undefined {
25 if (typeof value === 'boolean') {
26 return value;
27 }
28
29 if (typeof value === 'string') {
30 const booleanValuePairs = [
31 ['true', 'false'],
32 ['on', 'off'],
33 ['yes', 'no'],
34 ];
35 const lowerCaseValue = value.toLowerCase();
36 // eslint-disable-next-line functional/no-loop-statements
37 for (const [trueValue, falseValue] of booleanValuePairs) {
38 if (lowerCaseValue === trueValue || lowerCaseValue === falseValue) {
39 return lowerCaseValue === trueValue;
40 }
41 }
42
43 const intValue = Number.parseInt(value, 10);
44 if (!Number.isNaN(intValue)) {
45 return intValue !== 0;
46 }
47 }
48
49 return undefined;
50}
51
52type RUNNER_ARGS_ENV_VAR =
53 | 'CP_PERSIST_OUTPUT_DIR'

Callers 4

setVerboseMiddlewareFunction · 0.90
env.unit.test.tsFile · 0.85
isEnvVarEnabledFunction · 0.85
runnerArgsFromEnvFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected