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.

26 lines 970 B
/** * 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 */ export default 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