UNPKG

booleanlab

Version:

A comprehensive TypeScript utility library for advanced boolean operations. Simplify your boolean logic with easy-to-use functions.

203 lines (143 loc) 4.36 kB
# 📘 booleanlab A comprehensive TypeScript utility library for advanced boolean operations. Simplify your boolean logic with easy-to-use functions. --- ## 📦 Installation Install `booleanlab` via npm or yarn: ```bash npm install booleanlab ``` ```bash yarn add booleanlab ``` --- ## 🚀 Usage Import the required functions into your TypeScript or JavaScript project: ```typescript import { trueValue, falseValue, isEqual, andOperation } from 'booleanlab'; console.log(trueValue()); // true console.log(falseValue()); // false console.log(isEqual(true, false)); // false console.log(andOperation(true, false)); // false ``` --- ## 🔧 API Reference ### 🟢 `trueValue()` Returns the boolean value `true`. ```typescript trueValue(); // true ``` ### 🔴 `falseValue()` Returns the boolean value `false`. ```typescript falseValue(); // false ``` ### 📊 `isEqual(a: boolean, b: boolean)` Returns `true` if both boolean values are equal, `false` otherwise. ```typescript isEqual(true, true); // true isEqual(true, false); // false ``` ### 🔄 `isNotEqual(a: boolean, b: boolean)` Returns `true` if both boolean values are not equal, `false` otherwise. ```typescript isNotEqual(true, false); // true isNotEqual(false, false); // false ``` ### 🔗 `andOperation(a: boolean, b: boolean)` Performs a logical AND operation on two boolean values. ```typescript andOperation(true, true); // true andOperation(true, false); // false ``` ### 🔘 `orOperation(a: boolean, b: boolean)` Performs a logical OR operation on two boolean values. ```typescript orOperation(true, false); // true orOperation(false, false); // false ``` ### ❌ `xorOperation(a: boolean, b: boolean)` Performs a logical XOR (exclusive OR) operation. ```typescript xorOperation(true, false); // true xorOperation(true, true); // false ``` ### 🔄 `negate(a: boolean)` Returns the negation (inverse) of a boolean value. ```typescript negate(true); // false negate(false); // true ``` ### ✅ `isTrue(a: boolean)` Checks if a value is exactly `true`. ```typescript isTrue(true); // true isTrue(false); // false ``` ### ❌ `isFalse(a: boolean)` Checks if a value is exactly `false`. ```typescript isFalse(false); // true isFalse(true); // false ``` ### 🔢 `toBinary(a: boolean)` Converts a boolean to a binary number (`1` for `true`, `0` for `false`). ```typescript toBinary(true); // 1 toBinary(false); // 0 ``` ### 🔁 `toBoolean(a: any)` Converts any value to a boolean (falsy values become `false`, truthy values become `true`). ```typescript toBoolean(1); // true toBoolean(0); // false toBoolean(null); // false ``` ### 🚫 `nandOperation(a: boolean, b: boolean)` Performs a logical NAND (NOT AND) operation. ```typescript nandOperation(true, true); // false nandOperation(false, true); // true ``` ### 🚫 `norOperation(a: boolean, b: boolean)` Performs a logical NOR (NOT OR) operation. ```typescript norOperation(false, false); // true norOperation(true, false); // false ``` ### 🔡 `toString(value: boolean)` Converts a boolean value to a string representation (`"True"` or `"False"`). ```typescript toString(true); // "True" toString(false); // "False" ``` ### ✅ `isTruthy(value: any)` Checks if a value is truthy (not `null`, `undefined`, `false`, `0`, `NaN`, or an empty string). ```typescript isTruthy(1); // true isTruthy(''); // false isTruthy(null); // false ``` ### ❌ `isFalsy(value: any)` Checks if a value is falsy (`null`, `undefined`, `false`, `0`, `NaN`, or an empty string). ```typescript isFalsy(0); // true isFalsy(true); // false ``` ### ➡️ `implication(a: boolean, b: boolean)` Returns the result of a logical Implication (A → B) operation. ```typescript implication(true, false); // false implication(false, true); // true ``` ### ↔️ `biConditional(a: boolean, b: boolean)` Returns the result of a logical Biconditional (A ↔ B) operation. ```typescript biConditional(true, true); // true biConditional(true, false); // false ``` --- ## 📄 License This project is licensed under the **ISC License**. --- ## 📢 Author Created by **jella_komal**.