Options
All
  • Public
  • Public/Protected
  • All
Menu

@thi.ng/dlogic

dlogic

npm versionnpm downloads Twitter Follow

This project is part of the @thi.ng/umbrella monorepo.

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

Installation

yarn add @thi.ng/dlogic
// ES module
<script type="module" src="https://unpkg.com/@thi.ng/dlogic?module" crossorigin></script>

// UMD
<script src="https://unpkg.com/@thi.ng/dlogic/lib/index.umd.js" crossorigin></script>

Package sizes (gzipped, pre-treeshake): ESM: 378 bytes / CJS: 478 bytes / UMD: 514 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

Karsten Schmidt

License

© 2017 - 2020 Karsten Schmidt // Apache Software License 2.0

Generated using TypeDoc