UNPKG

@compute.ts/boolean

Version:

Provide boolean operators for the computeTS package

385 lines (236 loc) 11.5 kB
![](https://colibri-engine.com/assets/img/compute.png) ![](https://img.shields.io/npm/types/@compute.ts/boolean) ![](https://img.shields.io/npm/v/@compute.ts/boolean) ![](https://img.shields.io/npm/l/@compute.ts/boolean) ![](https://img.shields.io/badge/coverage-98,22%25-4cc41f.svg) ![](https://img.shields.io/badge/files-5-orange) ![](https://img.shields.io/badge/lines-252-orange) ![](https://img.shields.io/badge/made%20in-France-blue) ## Presentation The engine is based on incremental computation algorithms. When a calculation is submitted to the engine, all the computed values are memorized. So, if you change some variable and query an evaluation, the engine is able to compute the result very fast because it recomputes only what has changed. [compute.ts](https://www.npmjs.com/package/compute.ts) ## Libraries The project provides several libraries that each comes with dozens of operators. Please note the cross-compatibility of the libraries. - [@compute.ts/number](https://www.npmjs.com/package/@compute.ts/number) - [@compute.ts/string](https://www.npmjs.com/package/@compute.ts/string) - [@compute.ts/date](https://www.npmjs.com/package/@compute.ts/date) - [@compute.ts/dictionary](https://www.npmjs.com/package/@compute.ts/dictionary) - [@compute.ts/function](https://www.npmjs.com/package/@compute.ts/function) - [@compute.ts/array](https://www.npmjs.com/package/@compute.ts/array) - [@compute.ts/math](https://www.npmjs.com/package/@compute.ts/math) - [@compute.ts/structural](https://www.npmjs.com/package/@compute.ts/structural) ## Imports ### Typescript ```typescript import {/* required operators */} from '@compute.ts/boolean'; ``` ### Javascript ```javascript const {/* required operators */} = require('@compute.ts/boolean'); ``` ## Operators ### boolean <code>boolean(value) ➜ x<sub>boolean</sub></code> <code>boolean() ➜ x<sub>boolean</sub></code> The **boolean** operator allows you to create a boolean expression which evals to the given value. If no value is provided the expression is a variable of the model ```typescript import {boolean} from "@compute.ts/boolean"; const x0 = boolean(true); x0.affect(false); const x1 = boolean(); x1.affect(false); ``` * * * ### True <code>True() ➜ x<sub>boolean</sub></code> The **True** operator allows to create a boolean expression which evals to true ```typescript import {True} from "@compute.ts/boolean"; const x = True; x.affect(false); ``` * * * ### False <code>False() ➜ x<sub>boolean</sub></code> The **False** operator allows to create a boolean expression which evals to false ```typescript import {False} from "@compute.ts/boolean"; const x = False; x.affect(true); ``` * * * ### isTrue <code>isTrue(x<sub>boolean</sub>) ➜ y<sub>boolean</sub></code> <code>x<sub>boolean</sub>.isTrue() ➜ y<sub>boolean</sub></code> The **isTrue** operator allows to create a boolean expression which evals to `true` if the given boolean expression evals to true ```typescript import {boolean, isTrue} from "@compute.ts/boolean"; const x = boolean(); const y = isTrue(x) | x.isTrue(); const value = y.eval(); ``` * * * ### isFalse <code>isFalse(x<sub>boolean</sub>) ➜ y<sub>boolean</sub></code> <code>x<sub>boolean</sub>.isFalse() ➜ y<sub>boolean</sub></code> The **isFalse** operator allows to create a boolean expression which evals to `true` if the given boolean expression evals to `false` ```typescript import {boolean, isFalse} from "@compute.ts/boolean"; const x = boolean(); const y = isFalse(x) | x.isFalse(); const value = y.eval(); ``` * * * ### not <code>not(x<sub>boolean</sub>) ➜ y<sub>boolean</sub></code> <code>x<sub>boolean</sub>.not() ➜ y<sub>boolean</sub></code> The **not** operator allows to create a boolean expression which evals to `true` if the given boolean expression evals to false ```typescript import {boolean, not} from "@compute.ts/boolean"; const x = boolean(); const y = not(x) | x.not(); const value = y.eval(); ``` * * * ### implies <code>implies(x<sub>boolean</sub>, y<sub>boolean</sub>) ➜ z<sub>boolean</sub></code> <code>x<sub>boolean</sub>.implies(y<sub>boolean</sub>) ➜ z<sub>boolean</sub></code> The **implies** operator allows to create a boolean expression which evals to `true` if the given boolean expressions match the implies truth table ```typescript import {boolean, implies} from "@compute.ts/boolean"; const x = boolean(); const y = boolean(); const z = implies(x, y) | x.implies(y); const value = z.eval(); ``` * * * ### equals <code>equals(x<sub>boolean</sub>, y<sub>boolean</sub>) ➜ z<sub>boolean</sub></code> <code>x<sub>boolean</sub>.equals(y<sub>boolean</sub>) ➜ z<sub>boolean</sub></code> The **equals** operator allows you to create a boolean expression which evals to `true` if the given expressions evals to the same boolean value ```typescript import {boolean, equals} from "@compute.ts/boolean"; const x = boolean(); const y = boolean(); const z = equals(x, y) | x.equals(y); const value = z.eval(); ``` * * * ### and <code>and(x<sup>0</sup><sub>boolean</sub>, x<sup>1</sup><sub>boolean</sub>, ..., x<sup>n</sup><sub>boolean</sub>) ➜ y<sub>boolean</sub></code> <code>x<sub>boolean</sub>.and(x<sup>0</sup><sub>boolean</sub>, x<sup>1</sup><sub>boolean</sub>, ..., x<sup>n</sup><sub>boolean</sub>) ➜ y<sub>boolean</sub></code> The **and** operator allows to create a boolean expression which evals to `true` if the given boolean expressions match the AND truth table ```typescript import {boolean, and} from "@compute.ts/boolean"; const x0 = boolean(); const x1 = boolean(); // ... const xn = boolean(); const y = and(x0, x1, ..., xn) | x0.and(x1, ..., xn); const value = y.eval(); ``` * * * ### or <code>or(x<sup>0</sup><sub>boolean</sub>, x<sup>1</sup><sub>boolean</sub>, ..., x<sup>n</sup><sub>boolean</sub>) ➜ y<sub>boolean</sub></code> <code>x<sub>boolean</sub>.or(x<sup>0</sup><sub>boolean</sub>, x<sup>1</sup><sub>boolean</sub>, ..., x<sup>n</sup><sub>boolean</sub>) ➜ y<sub>boolean</sub></code> The **or** operator allows to create a boolean expression which evals to `true` if the given boolean expressions match the OR truth table ```typescript import {boolean, or} from "@compute.ts/boolean"; const x0 = boolean(); const x1 = boolean(); // ... const xn = boolean(); const y = or(x0, x1, ..., xn) | x0.or(x1, ..., xn); const value = y.eval(); ``` * * * ### xand <code>or(x<sup>0</sup><sub>boolean</sub>, x<sup>1</sup><sub>boolean</sub>, ..., x<sup>n</sup><sub>boolean</sub>) ➜ y<sub>boolean</sub></code> <code>x<sub>boolean</sub>.or(x<sup>0</sup><sub>boolean</sub>, x<sup>1</sup><sub>boolean</sub>, ..., x<sup>n</sup><sub>boolean</sub>) ➜ y<sub>boolean</sub></code> The xand operator allows to create a boolean expression which evals to `true` if the given boolean expressions match the XAND truth table ```typescript import {boolean, xand} from "@compute.ts/boolean"; const x0 = boolean(); const x1 = boolean(); // ... const xn = boolean(); const y = xand(x0, x1, ..., xn) | x0.xand(x1, ..., xn); const value = y.eval(); ``` * * * ### xor <code>xor(x<sup>0</sup><sub>boolean</sub>, x<sup>1</sup><sub>boolean</sub>, ..., x<sup>n</sup><sub>boolean</sub>) ➜ y<sub>boolean</sub></code> <code>x<sub>boolean</sub>.xor(x<sup>0</sup><sub>boolean</sub>, x<sup>1</sup><sub>boolean</sub>, ..., x<sup>n</sup><sub>boolean</sub>) ➜ y<sub>boolean</sub></code> The **xor** operator allows to create a boolean expression which evals to `true` if the given boolean expressions match the XOR truth table ```typescript import {boolean, xor} from "@compute.ts/boolean"; const x0 = boolean(); const x1 = boolean(); // ... const xn = boolean(); const y = xor(x0, x1, ..., xn) | x0.xor(x1, ..., xn); const value = y.eval(); ``` * * * ### nand <code>nand(x<sup>0</sup><sub>boolean</sub>, x<sup>1</sup><sub>boolean</sub>, ..., x<sup>n</sup><sub>boolean</sub>) ➜ y<sub>boolean</sub></code> <code>x<sub>boolean</sub>.nand(x<sup>0</sup><sub>boolean</sub>, x<sup>1</sup><sub>boolean</sub>, ..., x<sup>n</sup><sub>boolean</sub>) ➜ y<sub>boolean</sub></code> The **nand** operator allows to create a boolean expression which evals to `true` if the given boolean expressions match the NAND truth table ```typescript import {boolean, nand} from "@compute.ts/boolean"; const x0 = boolean(); const x1 = boolean(); // ... const xn = boolean(); const y = nand(x0, x1, ..., xn) | x0.nand(x1, ..., xn); const value = y.eval(); ``` * * * ### nor <code>nor(x<sup>0</sup><sub>boolean</sub>, x<sup>1</sup><sub>boolean</sub>, ..., x<sup>n</sup><sub>boolean</sub>) ➜ y<sub>boolean</sub></code> <code>x<sub>boolean</sub>.nor(x<sup>0</sup><sub>boolean</sub>, x<sup>1</sup><sub>boolean</sub>, ..., x<sup>n</sup><sub>boolean</sub>) ➜ y<sub>boolean</sub></code> The **nor** operator allows to create a boolean expression which evals to `true` if the given boolean expressions match the NOR truth table ```typescript import {boolean, nor} from "@compute.ts/boolean"; const x0 = boolean(); const x1 = boolean(); // ... const xn = boolean(); const y = nor(x0, x1, ..., xn) | x0.nor(x1, ..., xn); const value = y.eval(); ``` * * * ### xnand <code>xnand(x<sup>0</sup><sub>boolean</sub>, x<sup>1</sup><sub>boolean</sub>, ..., x<sup>n</sup><sub>boolean</sub>) ➜ y<sub>boolean</sub></code> <code>x<sub>boolean</sub>.xnand(x<sup>0</sup><sub>boolean</sub>, x<sup>1</sup><sub>boolean</sub>, ..., x<sup>n</sup><sub>boolean</sub>) ➜ y<sub>boolean</sub></code> The **xnand** operator allows to create a boolean expression which evals to `true` if the given boolean expressions match the XNAND truth table ```typescript import {boolean, xnand} from "@compute.ts/boolean"; const x0 = boolean(); const x1 = boolean(); // ... const xn = boolean(); const y = xnand(x0, x1, ..., xn) `|` x0.xnand(x1, ..., xn); const value = y.eval(); ``` * * * ### xnor <code>xnor(x<sup>0</sup><sub>boolean</sub>, x<sup>1</sup><sub>boolean</sub>, ..., x<sup>n</sup><sub>boolean</sub>) ➜ y<sub>boolean</sub></code> <code>x<sub>boolean</sub>.xnor(x<sup>0</sup><sub>boolean</sub>, x<sup>1</sup><sub>boolean</sub>, ..., x<sup>n</sup><sub>boolean</sub>) ➜ y<sub>boolean</sub></code> The **xnor** operator allows to create a boolean expression which evals to `true` if the given boolean expressions match the XNOR truth table ```typescript import {boolean, xnor} from "@compute.ts/boolean"; const x0 = boolean(); const x1 = boolean(); // ... const xn = boolean(); const y = xnor(x0, x1, ..., xn) | x0.xnor(x1, ..., xn); const value = y.eval(); ``` ## About the author I am a software developer with 4 years of project specializing in the development of web solutions. Digital Nomad, I work while traveling. After 3 years into the french industry, I've started to work as a freelance software architect or fullstack developer. Based on state-of-the-art web technologies, I offer you to architect & develop the best version of your project. My experience in the web app development assure you to build a nice looking, performant and stable product. Minimalist, I like to travel, to meet people, learn new things and handmade stuff. Scuba & sky diving licenced. I like also hamburgers, Kinder chocolate and crepes. Karate black belt. https://berthellemy.com/ * * * ![](https://colibri-engine.com/assets/img/brand/logo_animated.gif)