UNPKG

@azizbecha/strkit

Version:

strkit is a utility library offering a collection of essential string functions including validation, case conversion, truncation, and more. Ideal for both JavaScript and TypeScript developers to simplify string operations in their applications.

39 lines 1.52 kB
(function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = isBoolean; /** * Checks if a value is a valid boolean or a string representation of a boolean. * * The function recognizes the following boolean representations: * - `true`, `false` (boolean values) * - `"true"`, `"false"` (string values) * - `"yes"`, `"no"` (string values) * - `1`, `0` (numeric values) * * @param value - The value to check. * @returns A boolean indicating whether the value is a valid boolean or a recognized string representation of a boolean. * * @example * isBoolean(true); // Output: true * isBoolean("true"); // Output: true * isBoolean("yes"); // Output: true * isBoolean(1); // Output: true * isBoolean("no"); // Output: true * isBoolean("random"); // Output: false */ function isBoolean(value) { const truthyValues = ['true', 'yes', '1', 1, true]; const falsyValues = ['false', 'no', '0', 0, false]; return truthyValues.includes(value) || falsyValues.includes(value); } }); //# sourceMappingURL=isBoolean.js.map