Skip to content

@pcvl/schema / coerceToBoolean

Function: coerceToBoolean() ​

ts
function coerceToBoolean(value): unknown;

Defined in: coercions.ts:60

The conversion pvl.boolean().coerce() applies before its own check: string, number and bigint inputs become their Boolean() form. This is JavaScript truthiness, so every non-empty string is true — including 'false'.

Parameters ​

value ​

unknown

Returns ​

unknown

Example ​

ts
import { coerceToBoolean } from '@pcvl/schema';

coerceToBoolean(1); // true
coerceToBoolean(''); // false
coerceToBoolean('false'); // true — a non-empty string is truthy