Skip to main content
Version: v0.0.2

Function: getBoolean()

getBoolean(obj, key): boolean | undefined

Read a boolean property from an untrusted object, or undefined if absent/not a boolean.

A non-boolean (including a missing key, or the strings "true"/"false") yields undefined - the accessor never coerces, so a caller can distinguish "explicitly false" from "absent".

Parameters

obj

unknown

The source object (may be any unknown).

key

string

The property name to read.

Returns

boolean | undefined

The boolean value, or undefined when the key is missing or not a boolean.

Example

import { getBoolean } from "@cosyte/terminology";

getBoolean({ inactive: true }, "inactive"); // => true