1.2.0 • Published 11 months ago

lgates v1.2.0

Weekly downloads
-
License
GPL-3.0
Repository
github
Last release
11 months ago

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}[]
1.2.0

11 months ago

1.1.9

11 months ago

1.1.8

11 months ago

1.1.7

11 months ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago