UNPKG

4.55 kBMarkdownView Raw
1[Boolean] data type has two possible truth values to represent logic.<br>
2📦 [Node.js](https://www.npmjs.com/package/extra-boolean),
3🌐 [Web](https://www.npmjs.com/package/extra-boolean.web),
4📜 [Files](https://unpkg.com/extra-boolean/),
5📰 [Docs](https://nodef.github.io/extra-boolean/).
6📘 [Wiki](https://github.com/nodef/extra-boolean/wiki/).
7
8Here is my implementation of digital logic gates in software. That includes
9the basic gates [not], [and], [or], [xor]; their complements [nand], [nor],
10[xnor]; and 2 propositional logic (taught in discrete mathematics) gates
11[imply], [eq]; and their complements [nimply], [neq]. There is also a
12multiplexer, called [select], and a `true` counter, called [count]. [count]
13can help you make custom gates, such as an *alternate* concept of **xnor**
14which returns `true` only if all inputs are the same (standard [xnor] returns
15`true` if even inputs are `true`). All of them can handle upto 8 inputs.
16
17[parse] is influenced by ["boolean"] package, and is quite good at translating
18`string` to `boolean`. It can also handle double negatives, eg. `not inactive`.
19You know the [and] of 2-inputs, but what of 1-input? What of 0? And what of
20the other gates? I answer them here.
21
22This package is available in *Node.js* and *Web* formats. The web format
23is exposed as `extra_boolean` standalone variable and can be loaded from
24[jsDelivr CDN].
25
26> Stability: [Experimental](https://www.youtube.com/watch?v=L1j93RnIxEo).
27
28[jsDelivr CDN]: https://cdn.jsdelivr.net/npm/extra-boolean.web/index.js
29
30<br>
31
32```javascript
33const boolean = require('extra-boolean');
34// import * as boolean from "extra-boolean";
35// import * as boolean from "https://unpkg.com/extra-boolean@1.8.0/index.mjs"; (deno)
36
37boolean.parse('1');
38boolean.parse('not off');
39boolean.parse('truthy');
40// true
41
42boolean.parse('not true');
43boolean.parse('inactive');
44boolean.parse('disabled');
45// false
46
47boolean.imply(true, false);
48// false
49
50boolean.eq(false, false);
51// true
52
53boolean.xor(true, true, true);
54// true
55
56boolean.select(1, true, false, true);
57// false ^
58
59boolean.count(true, false, true);
60// 2 ^ ^
61```
62
63<br>
64<br>
65
66
67## Index
68
69| Property | Description |
70| ---- | ---- |
71| [is] | Check if value is boolean. |
72| [parse] | Convert string to boolean. |
73| [not] | Check if value is false. |
74| [imply] | Check if antecedent ⇒ consequent (a ⇒ b). |
75| [nimply] | Check if antecedent ⇏ consequent (a ⇏ b). |
76| [eq] | Check if antecedent ⇔ consequent (a ⇔ b). |
77| [neq] | Check if antecedent ⇎ consequent (a ⇎ b). |
78| [imp] | Check if antecedent ⇒ consequent (a ⇒ b). |
79| [eqv] | Check if antecedent ⇔ consequent (a ⇔ b). |
80| [and] | Check if all values are true. |
81| [nand] | Check if any value is false. |
82| [or] | Check if any value is true. |
83| [nor] | Check if all values are false. |
84| [xor] | Check if odd number of values are true. |
85| [xnor] | Check if even number of values are true. |
86| [count] | Count number of true values. |
87| [select] | Check if ith value is true. |
88
89<br>
90<br>
91
92[![](https://img.youtube.com/vi/6mMK6iSZsAs/maxresdefault.jpg)](https://www.youtube.com/watch?v=6mMK6iSZsAs)
93
94[![](https://coveralls.io/repos/github/nodef/extra-boolean/badge.svg?branch=master)](https://coveralls.io/github/nodef/extra-boolean?branch=master)
95
96[Boolean]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean
97["boolean"]: https://www.npmjs.com/package/boolean
98[not]: https://nodef.github.io/extra-boolean/modules.html#not
99[and]: https://nodef.github.io/extra-boolean/modules.html#and
100[or]: https://nodef.github.io/extra-boolean/modules.html#or
101[xor]: https://nodef.github.io/extra-boolean/modules.html#xor
102[nand]: https://nodef.github.io/extra-boolean/modules.html#nand
103[nor]: https://nodef.github.io/extra-boolean/modules.html#nor
104[xnor]: https://nodef.github.io/extra-boolean/modules.html#xnor
105[imply]: https://nodef.github.io/extra-boolean/modules.html#imply
106[eq]: https://nodef.github.io/extra-boolean/modules.html#eq
107[nimply]: https://nodef.github.io/extra-boolean/modules.html#nimply
108[neq]: https://nodef.github.io/extra-boolean/modules.html#neq
109[select]: https://nodef.github.io/extra-boolean/modules.html#select
110[count]: https://nodef.github.io/extra-boolean/modules.html#count
111[parse]: https://nodef.github.io/extra-boolean/modules.html#parse
112[is]: https://nodef.github.io/extra-boolean/modules.html#is
113[imp]: https://nodef.github.io/extra-boolean/modules.html#imp
114[eqv]: https://nodef.github.io/extra-boolean/modules.html#eqv