lgates
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

Logic Gates as Functions & Expressions

Logic Gates (AND, BUFFER, NAND, NOR, NOT, OR, XNOR, XOR) made available as simple functions and Expressions (Cool feature of this package).

Gates also support both Boolean and number values, here's an example:

import lg from "lgates";

lg.gate.and(true, 1, false);
// Gates will always return a number

It is also possible to import every expression or gate individually:

import {and, singleCase} from "lgates";

// Gate Examples
and(true, 0) // 0

// Expression Examples
singleCase("AB+!B", {a:1, b:0}).res // 1

Install

$ npm install lgates
$ pnpm install lgates
$ yarn add lgates

Usage

import lg from "lgates";

// Gates
const and = lg.gate.and(true, 1);
const buffer = lg.gate.buffer(true);
const nand = lg.gate.nand(true, 1);
const nor = lg.gate.nor(true, 1);
const not = lg.gate.not(true);
const or = lg.gate.or(true, 1);
const xnor = lg.gate.xnor(true, 1);
const xor = lg.gate.xor(true, 1);

Expressions

import lg from "lgates";

// Allowed operators: +, *, !
// Brackets are allowed ()[]{}

const pattern = "AB+!B";
const x = lg.exp.singleCase(pattern, {a: 1});
// Non specified variables are 0 by default
const y = lg.exp.everyCase(pattern);

console.log(x.res); // 1
console.log(x.exp); // (1*0)+1

// calculates every possible case with provided pattern
console.log(y.res); // number[]
console.log(y.exp); // string[]
console.log(y.data); // data[] => {variables + res}[]

Package Sidebar

Install

npm i lgates

Weekly Downloads

16

Version

1.2.0

License

GPL-3.0

Unpacked Size

59 kB

Total Files

9

Last publish

Collaborators

  • shini161