Pyxis.js

Version: 1.0.0

Author: Ferenc Czigler

License: MIT

A TypeScript and JavaScript module implementing fundamental and extended logical operations based on JavaScript truthiness.

All functions accept unknown values and evaluate them using Boolean(...);.


Autotest

     


Table of Contents

  1. Overview
  2. How to import
  3. Truthiness Rules
  4. Function API
  5. Truth Tables
  6. Examples
  7. License

Overview

This module provides a suite of logical functions that operate on *truthiness* rather than strict booleans.

Every input is coerced using: boolean(x); which makes the library compatible with JavaScript idioms.

For instance:

Each logical function also includes an alias in uppercase for semantic clarity.


How to import

// import the defaultExport object
import defaultExport from "./pyxis.js";
globalThis.pyxis = defaultExport;

// import with default with name
import { default as pyxis } from "./pyxis.js";
globalThis.pyxis = pyxis;

// import all into a new celestra object
import * as pyxis from "./pyxis.js";
globalThis.pyxis = pyxis;

// import some functions
import { or, XOR } from "./pyxis.mjs";
globalThis.or = or;
globalThis.XOR = XOR;

// dynamic import
const pyxis = await import("./pyxis.js");
globalThis.pyxis = pyxis;

Truthiness Rules

A value is truthy if Boolean(value) === true.

Examples:

TruthyFalsy
"text"""
1, -1, any non-zero number0, -0
1n, -1n, any non-zero bigint0n
{}, []null
function () {}undefined
Symbol();NaN

Function API

Each function is documented below with examples.


not(x); / NOT(x);

Returns the negation of x based on truthiness.

not(x: unknown): boolean

Examples

not(true);          // false
not(0);             // true
not("hello");       // false

and(x, y); / AND(x, y);

Logical AND — true if both x and y are truthy.

and(x: unknown, y: unknown): boolean

Examples

and(true, 1);       // true
and(true, 0);       // false

or(x, y); and OR(x, y);

Logical OR — true if either x or y is truthy.

or(x: unknown, y: unknown): boolean

Examples

or(0, "yes");        // true
or(null, undefined); // false

xor(x, y); and XOR(x, y);

Exclusive OR — true if exactly one of x and y is truthy.

xor(x: unknown, y: unknown): boolean

Examples

xor(true, false);   // true
xor(1, "x");        // false

nand(x, y); and NAND(x, y);

Negated AND — false only if both are truthy.

nand(x: unknown, y: unknown): boolean

Examples

nand(true, true);   // false
nand(true, 0);      // true

nor(x, y); and NOR(x, y);

Negated OR — true only if neither x nor y is truthy.

nor(x: unknown, y: unknown): boolean

Examples

nor(0, null);       // true
nor(0, "a");        // false

xnor(x, y); and XNOR(x, y);

Exclusive NOR — true if x and y have the same truthiness.

xnor(x: unknown, y: unknown): boolean

Examples

xnor(true, 1);      // true
xnor(false, "");    // true
xnor(1, 0);         // false

equals(x, y); and EQUALS(x, y);

Returns true if both values evaluate to the same boolean.

Equivalent to:

Boolean(x) === Boolean(y)
equals(x: unknown, y: unknown): boolean

implies(x, y); and IMPLIES(x, y);

Logical implication:

x -> y is false only when x is truthy and y is falsy.

implies(x: unknown, y: unknown): boolean

nandImplies(x, y); and NAND_IMPLIES(x, y);

True when x is truthy and y is falsy.

Equivalent to:

x ∧ ¬y
nandImplies(x: unknown, y: unknown): boolean

norImplies(x, y); and NOR_IMPLIES(x, y);

True when x is truthy OR y is falsy.

norImplies(x: unknown, y: unknown): boolean

converseImplies(x, y); and CONVERSE_IMPLIES(x, y);

Reverse implication: y -> x

False only when y is truthy and x is falsy.

converseImplies(x: unknown, y: unknown): boolean

converseNandImplies(x, y); and CONVERSE_NAND_IMPLIES(x, y);

True when y is truthy and x is falsy.

converseNandImplies(x: unknown, y: unknown): boolean

converseNorImplies(x, y); and CONVERSE_NOR_IMPLIES(x, y);

True when y is truthy OR x is falsy.

converseNorImplies(x: unknown, y: unknown): boolean

Truth Tables

Truth tables assume strict booleans (true and false) even though the functions accept any values.

Core Operators

x y AND OR XOR NANDNOR XNOR and EQUALS
F F F F F T T T
F T F T T T F F
T F F T T T F F
T T T T F F F T

Implications

x y implies (->) nandImplies (x ∧ ¬y) norImplies (x ∨ ¬y)
F F T F T
F T T F F
T F F T T
T T T F T
x y converseImplies converseNandImplies (y ∧ ¬x) converseNorImplies (y ∨ ¬x)
F F T F T
F T F T T
T F T F F
T T T F T

Examples

import { xor, implies, nor } from "./pyxis.js";

xor(1, "a"); // false (both truthy)

implies(true, 0); // false

nor(null, undefined); // true

License

https://opensource.org/licenses/MIT

MIT License

SPDX short identifier: MIT

Copyright (c) 2025 Ferenc Czigler

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


© Copyright 2025 Ferenc Czigler https://github.com/Serrin