UNPKG

diginext-utils

Version:
38 lines 972 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toBool = toBool; const isNull_1 = require("./isNull"); const toFloat_1 = require("./toFloat"); /** * Converts a value to a boolean. * Recognizes string representations like "true", "false", "0", "1". * * @param value - The value to convert * @returns The boolean representation * * @example * ```ts * toBool('true'); // true * toBool('false'); // false * toBool('1'); // true * toBool('0'); // false * toBool(1); // true * toBool(0); // false * toBool(null); // false * toBool(''); // false * ``` */ function toBool(value) { if ((0, isNull_1.isNull)(value)) { return false; } const str = String(value).toLowerCase(); if (str === "false") { return false; } if ((0, toFloat_1.toFloat)(value) === 0) { return false; } return str === "true" || (0, toFloat_1.toFloat)(value) !== 0; } //# sourceMappingURL=toBool.js.map