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(...);.
not(x); and NOT(x);and(x, y); and AND(x, y);or(x, y); and OR(x, y);xor(x, y); and XOR(x, y);nand(x, y); and NAND(x, y);nor(x, y); and NOR(x, y);xnor(x, y); and XNOR(x, y);equals(x, y); and EQUALS(x, y);implies(x, y); and IMPLIES(x, y);nandImplies(x, y); and NAND_IMPLIES(x, y);norImplies(x, y); and NOR_IMPLIES(x, y);converseImplies(x, y); and CONVERSE_IMPLIES(x, y);converseNandImplies(x, y); and CONVERSE_NAND_IMPLIES(x, y);converseNorImplies(x, y); and CONVERSE_NOR_IMPLIES(x, y);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:
and("hello", 1); -> trueor(0, null); -> falsexor(undefined, "nonempty"); -> trueEach logical function also includes an alias in uppercase for semantic clarity.
// 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;
A value is truthy if Boolean(value) === true.
Examples:
| Truthy | Falsy |
"text" | "" |
1, -1, any non-zero number | 0, -0 |
1n, -1n, any non-zero bigint | 0n |
{}, [] | null |
function () {} | undefined |
Symbol(); | NaN |
Each function is documented below with examples.
not(x); / NOT(x);Returns the negation of x based on truthiness.
not(x: unknown): boolean
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
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
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
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
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
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
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 ∧ ¬ynandImplies(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 assume strict booleans (true and false) even though the functions accept any values.
| x | y | AND | OR | XOR | NAND | NOR | 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 |
| 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 |
import { xor, implies, nor } from "./pyxis.js";
xor(1, "a"); // false (both truthy)
implies(true, 0); // false
nor(null, undefined); // true
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