Skip to main content

boolean

Accepts and returns booleans.
const boolean: Decoder<boolean>

Example

import { boolean } from 'decoders';

boolean.decode(true);    // ✓ true
boolean.decode(false);   // ✓ false
boolean.decode(1);       // ✗ Error: Must be boolean
boolean.decode('true');  // ✗ Error: Must be boolean

truthy

Accepts anything and will return its “truth” value. Will never reject.
const truthy: Decoder<boolean>

Example

import { truthy } from 'decoders';

truthy.decode(true);       // ✓ true
truthy.decode(false);      // ✓ false
truthy.decode(1);          // ✓ true
truthy.decode(0);          // ✓ false
truthy.decode('hello');    // ✓ true
truthy.decode('');         // ✓ false
truthy.decode(null);       // ✓ false
truthy.decode(undefined);  // ✓ false
truthy.decode([]);         // ✓ true

Build docs developers (and LLMs) love