Nefarious Plastic Mannequins

    extra-boolean.web
    TypeScript icon, indicating that this package has built-in type declarations

    1.10.12 • Public • Published

    A collection of common boolean functions.
    📦 Node.js, 🌐 Web, 📜 Files, 📰 Docs. 📘 Wiki.

    Boolean data type has two possible truth values to represent logic. 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.

    This package is available in Node.js and Web formats. The web format is exposed as extra_boolean standalone variable and can be loaded from jsDelivr CDN.

    Stability: Experimental.


    const boolean = require('extra-boolean');
    // import * as boolean from "extra-boolean";
    // import * as boolean from "https://unpkg.com/extra-boolean/index.mjs"; (deno)
    
    boolean.parse('1');
    boolean.parse('not off');
    boolean.parse('truthy');
    // → true
    
    boolean.parse('not true');
    boolean.parse('inactive');
    boolean.parse('disabled');
    // → 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         ^            ^


    Index

    Property Description
    is Check if a value is boolean.
    parse Convert a string to boolean.
    not Check if a boolean is false.
    imply Check if antecedent ⇒ consequent.
    nimply Check if antecedent ⇏ consequent.
    eq Check if antecedent ⇔ consequent.
    neq Check if antecedent ⇎ consequent.
    and Check if all booleans are true.
    nand Check if any boolean is false.
    or Check if any boolean is true.
    nor Check if all booleans are false.
    xor Check if odd number of booleans are true.
    xnor Check if even number of booleans are true.
    count Count number of true booleans.
    select Check if iᵗʰ boolean is true.


    References




    DOI Coverage Status Test Coverage Maintainability

    Install

    npm i extra-boolean.web

    DownloadsWeekly Downloads

    51

    Version

    1.10.12

    License

    MIT

    Unpacked Size

    17.7 kB

    Total Files

    6

    Last publish

    Collaborators

    • wolfram77