@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.
29 lines • 1.06 kB
JavaScript
;
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