UNPKG

tvl

Version:

A 316B implementation of Three Valued Logic in Javascript

1 lines 782 B
"use strict";var tvl={convert:function(a){if(!0===a)return 1;if(!1===a)return-1;if(void 0===a)return 0;throw new Error("Please pass a valid truth value")},revert:function(a){if(1===a)return!0;if(-1===a)return!1;if(0!==a)throw new Error("Please pass a valid number")}},min=function(c,a){return c>a?a:c},max=function(c,a){return c>a?c:a};tvl.not=function(a){return tvl.revert(-tvl.convert(a))},tvl.and=function(a,b){return tvl.revert(min(tvl.convert(a),tvl.convert(b)))},tvl.or=function(a,b){return tvl.revert(max(tvl.convert(a),tvl.convert(b)))},tvl.xor=function(a,b){return tvl.and(tvl.or(a,b),tvl.not(tvl.and(a,b)))},tvl.imp=function(a,b){return tvl.or(tvl.not(a),b)},tvl.bi=function(a,b){return tvl.and(tvl.imp(a,b),tvl.imp(b,a))},"undefined"!=typeof module&&(module.exports=tvl);