TypeScript icon, indicating that this package has built-in type declarations

    1.8.1 • Public • Published

    Boolean data type has two possible truth values to represent logic.
    📦 NPM, 😺 GitHub, 🏃 RunKit, 🌔 Minified, 📜 Files, 📰 JSDoc, 📘 Wiki.

    Here is my implementation of digital logic gates in software. That includes the basic gates not, and, or, xor; their complements nand, nor, xnor; and 2 propositional logic (taught in discrete mathematics) gates imply, eq; and their complements nimply, neq. There is also a multiplexer, called select, and a true counter, called count. count can help you make custom gates, such as an alternate concept of xnor which returns true only if all inputs are the same (standard xnor returns true if even inputs are true). All of them can handle upto 8 inputs.

    parse is influenced by "boolean" package, and is quite good at translating string to boolean. It can also handle double negatives, eg. not inactive. You know the and of 2-inputs, but what of 1-input? What of 0? And what of the other gates? I answer them here.

    Stability: Experimental.

    const boolean = require("extra-boolean");
    // import * as boolean from "extra-boolean";
    // import * as boolean from "https://unpkg.com/extra-boolean@1.8.0/index.mjs"; (deno)
    boolean.parse("not off");
    // true
    boolean.parse("not true");
    // false
    boolean.imply(true, false);
    // false
    boolean.eq(false, false);
    // true
    boolean.xor(true, true, true);
    // true
    boolean.select(1, true, false, true);
    // false                  ^
    boolean.count(true, false, true);
    // 2           ^            ^


    Name Action
    is Checks if value is boolean.
    parse Converts string to boolean.
    not Checks if value is false.
    and Checks if all values are true.
    or Checks if any value is true.
    xor Checks if odd no. of values are true.
    nand Checks if any value is false.
    nor Checks if all values are false.
    xnor Checks if even no. of values are true.
    eq Checks if antecedent ⇔ consequent (a ⇔ b).
    neq Checks if antecedent ⇎ consequent (a ⇎ b).
    imply Checks if antecedent ⇒ consequent (a ⇒ b).
    nimply Checks if antecedent ⇏ consequent (a ⇏ b).
    select Checks if ith value is true.
    count Counts no. of true values.


    npm i extra-boolean

    DownloadsWeekly Downloads






    Unpacked Size

    21.9 kB

    Total Files


    Last publish


    • wolfram77