
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
boolean-expression-solve
Advanced tools
A powerful JavaScript library for solving, simplifying, and analyzing Boolean expressions. Generate truth tables, minimize expressions using the Quine-McCluskey algorithm, and validate Boolean logic with ease.
npm install boolean-expression-solve
const { simplify, getTruthTable, getVariables, evaluate } = require('boolean-expression-solve');
// Simplify a Boolean expression
const simplified = simplify("A + A.B");
console.log(simplified); // Output: "A"
// Generate a truth table
const truthTable = getTruthTable("A + B", "string");
console.log(truthTable);
// Output:
// | A | B | A + B |
// |---|---|-------|
// | 0 | 0 | 0 |
// | 0 | 1 | 1 |
// | 1 | 0 | 1 |
// | 1 | 1 | 1 |
// Extract variables from expression
const variables = getVariables("(A + B').C");
console.log(variables); // Output: ['A', 'B', 'C']
// Evaluate expression with specific values
const result = evaluate("A + B", {A: 0, B: 1});
console.log(result); // Output: 1
simplify(expression)Simplifies a Boolean expression to its minimal form using the Quine-McCluskey algorithm.
Parameters:
expression (string): The Boolean expression to simplifyReturns:
string: The simplified Boolean expressionExample:
simplify("A + A.B"); // Returns: "A"
simplify("(A+B).(A+B')"); // Returns: "A"
simplify("A.A' + B"); // Returns: "B"
getTruthTable(expression, type)Generates a truth table for the given Boolean expression.
Parameters:
expression (string): The Boolean expressiontype (string, optional): Output format - "string" or "array" (default: "string")Returns:
string | Array: Formatted truth table string or array of objectsExample:
// String format
getTruthTable("A.B", "string");
// Returns formatted table string
// Array format
getTruthTable("A.B", "array");
// Returns: [
// { inputs: {A: 0, B: 0}, output: 0, expression: "A.B" },
// { inputs: {A: 0, B: 1}, output: 0, expression: "A.B" },
// { inputs: {A: 1, B: 0}, output: 0, expression: "A.B" },
// { inputs: {A: 1, B: 1}, output: 1, expression: "A.B" }
// ]
getVariables(expression)Extracts all unique variables from a Boolean expression.
Parameters:
expression (string): The Boolean expression to analyzeReturns:
Array<string>: Array of variable names sorted alphabeticallyExample:
getVariables("A + B.C + A'"); // Returns: ['A', 'B', 'C']
getVariables("(X+Y').Z"); // Returns: ['X', 'Y', 'Z']
evaluate(expression, values)Evaluates a Boolean expression for specific variable values.
Parameters:
expression (string): The Boolean expression to evaluatevalues (Object): Object with variable names as keys and their values (0 or 1)Returns:
number: The result of the expression (0 or 1)Example:
evaluate("A + B", {A: 0, B: 1}); // Returns: 1
evaluate("A.B", {A: 1, B: 0}); // Returns: 0
evaluate("A'", {A: 1}); // Returns: 0
isValidExpression(expression)Validates if a Boolean expression has correct syntax.
Parameters:
expression (string): The Boolean expression to validateReturns:
boolean: True if expression is valid, false otherwiseExample:
isValidExpression("A + B"); // Returns: true
isValidExpression("A + + B"); // Returns: false
A, B, C, ..., Za + b is treated as A + B. or implicit (e.g., AB = A.B)+' (postfix, e.g., A' means NOT A)10( and ) for grouping operations') - Highest precedence.)+) - Lowest precedence| Input Expression | Simplified Output | Description |
|---|---|---|
A + A | A | Idempotent law |
A.A' | 0 | Complement law |
A + A' | 1 | Complement law |
A + A.B | A | Absorption law |
A.(A + B) | A | Absorption law |
(A+B).(A+B') | A | Distribution |
A + 0 | A | Identity law |
A.1 | A | Identity law |
A + 1 | 1 | Domination law |
A.0 | 0 | Domination law |
Run the test suite to verify all functions work correctly:
npm test
The test suite includes:
The library uses the Quine-McCluskey algorithm for optimal Boolean expression minimization. It can handle:
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
git clone https://github.com/prabhasha2006/boolean-expression-solve.git
cd boolean-expression-solve
npm install
npm test
This project is licensed under the ISC License - see the LICENSE file for details.
Found a bug or have a feature request? Please create an issue on GitHub Issues.
K.Prabhasha
⭐ Star this repository if it helped you!
FAQs
Boolean expression solver, simplifier, truth-table generator
The npm package boolean-expression-solve receives a total of 2 weekly downloads. As such, boolean-expression-solve popularity was classified as not popular.
We found that boolean-expression-solve demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.