UNPKG

3.27 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5function is(v) {
6 return typeof v === "boolean";
7}
8
9function imply(a, b) {
10 return !a || b;
11}
12
13function nimply(a, b) {
14 return !imply(a, b);
15}
16
17const RNUM = /^[-+]?\d+$/;
18const RTRU = /\b(?:t|y|1)\b|\b(?:\+|ay|go|on|up)|(?:tru|acc|asc|day|for|hot|inc|joy|new|pos|top|win|yes|dawn|full|safe|grow|high|just|real|some|know|live|love|open|pure|shin|warm|wis[de]|activ|admit|advan|agree|begin|brigh|build|creat|early|enter|float|f(?:i|ou)nd|grant|light|north|prett|prese|publi|start|succe|victr)/gi;
19const RFAL = /\b(?:f|n|0)\b|(?:fal|off|dim|end|low|old|back|cold|cool|dark|dead|decr|desc|dirt|down|dull|dusk|exit|late|sink|ugly|absen|botto|close|finis|night|priva|south|wrong)/gi;
20const RNEG = /\b(?:-|na|no|un|in|aft|bad|dis|lie|non|ben[dt]|den[iy]|empt|fail|fake|hate|los[es]|stop|decli|defea|destr|never|negat|refus|rejec|forget|shr[iu]nk|against|is.?nt|can.?(?:no)?t)|(?:hind)/gi;
21function parse(s) {
22 if (RNUM.test(s))
23 return parseInt(s, 10) > 0;
24 var t = s.search(RTRU) >= 0;
25 var f = s.search(RFAL) >= 0;
26 var n = (s.match(RNEG) || []).length % 2 === 1;
27 return nimply(f, t) === n;
28}
29
30function not(a) {
31 return !a;
32}
33
34function eq(a, b) {
35 return a === b;
36}
37
38function neq(a, b) {
39 return !eq(a, b);
40}
41
42function imp(a, b) {
43 return imply(a, b);
44}
45
46function eqv(a, b) {
47 return eq(a, b);
48}
49
50function and(a = true, b = true, c = true, d = true, e = true, f = true, g = true, h = true) {
51 return a && b && c && d && e && f && g && h;
52}
53
54function nand(a = true, b = true, c = true, d = true, e = true, f = true, g = true, h = true) {
55 return !and(a, b, c, d, e, f, g, h);
56}
57
58function or(a = false, b = false, c = false, d = false, e = false, f = false, g = false, h = false) {
59 return a || b || c || d || e || f || g || h;
60}
61
62function nor(a = false, b = false, c = false, d = false, e = false, f = false, g = false, h = false) {
63 return !or(a, b, c, d, e, f, g, h);
64}
65
66function xor(a = false, b = false, c = false, d = false, e = false, f = false, g = false, h = false) {
67 return a !== b !== c !== d !== e !== f !== g !== h;
68}
69
70function xnor(a = false, b = false, c = false, d = false, e = false, f = false, g = false, h = false) {
71 return !xor(a, b, c, d, e, f, g, h);
72}
73
74function count(a = false, b = false, c = false, d = false, e = false, f = false, g = false, h = false) {
75 return (a ? 1 : 0) + (b ? 1 : 0) + (c ? 1 : 0) + (d ? 1 : 0) +
76 (e ? 1 : 0) + (f ? 1 : 0) + (g ? 1 : 0) + (h ? 1 : 0);
77}
78
79function select(i, a = false, b = false, c = false, d = false, e = false, f = false, g = false, h = false) {
80 switch (i) {
81 case 0: return a;
82 case 1: return b;
83 case 2: return c;
84 case 3: return d;
85 case 4: return e;
86 case 5: return f;
87 case 6: return g;
88 case 7: return h;
89 default: return false;
90 }
91}
92
93exports.and = and;
94exports.count = count;
95exports.eq = eq;
96exports.eqv = eqv;
97exports.imp = imp;
98exports.imply = imply;
99exports.is = is;
100exports.nand = nand;
101exports.neq = neq;
102exports.nimply = nimply;
103exports.nor = nor;
104exports.not = not;
105exports.or = or;
106exports.parse = parse;
107exports.select = select;
108exports.xnor = xnor;
109exports.xor = xor;