Skip to content

Latest commit

 

History

History

dlogic

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

@thi.ng/dlogic

npm version npm downloads Mastodon Follow

Note

This is one of 192 standalone projects, maintained as part of the @thi.ng/umbrella monorepo and anti-framework.

🚀 Please help me to work full-time on these projects by sponsoring me on GitHub. Thank you! ❤️

About

Assorted digital logic gates and ops for boolean values to compose complex logic in a more functional manner, e.g. for DSL or simulation purposes. Truth tables and references are provided in the doc strings of each function.

Also see @thi.ng/binary for binary versions of most of the ops provided by this package.

Status

STABLE - used in production

Search or submit any issues for this package

Installation

yarn add @thi.ng/dlogic

ESM import:

import * as dl from "@thi.ng/dlogic";

Browser ESM import:

<script type="module" src="https://esm.run/@thi.ng/dlogic"></script>

JSDelivr documentation

For Node.js REPL:

const dl = await import("@thi.ng/dlogic");

Package sizes (brotli'd, pre-treeshake): ESM: 376 bytes

Dependencies

API

Generated API docs

import { nand } from "@thi.ng/dlogic";

// XOR construction only using NAND gates
const xor = (a: boolean, b: boolean) => {
    const ab = nand(a,b);
    return nand(nand(a, ab), nand(b, ab));
};

xor(false, false)
// false
xor(false, true)
// true
xor(true, false)
// true
xor(true, true)
// false

Authors

If this project contributes to an academic publication, please cite it as:

@misc{thing-dlogic,
  title = "@thi.ng/dlogic",
  author = "Karsten Schmidt",
  note = "https://thi.ng/dlogic",
  year = 2017
}

License

© 2017 - 2024 Karsten Schmidt // Apache License 2.0