1.0.0 • Published 2 years ago

nv-bool-true-false-undef v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

nv-bool-true-false-undef

  • nv-bool-true-false-undef
  • simple util of some bool operation about true /false/ undefined

install

  • npm install nv-bool-true-false-undef

usage

   const {calc,trans} = require("nv-bool-true-false-undef")

   #unary:
       
       not(undefined) === undefined
       not(true)      === false
       not(false)     === true

   #binop:

      ##and

         * | T | F | U
        ---------------
         T | T | F | U
        ---------------
         F | F | F | F
        ---------------
         U | U | F | U
        ---------------


      ##or
       

         + | T | F | U
        ---------------
         T | T | T | T
        ---------------
         F | T | F | U
        ---------------
         U | T | U | U
        ---------------

example

calc

un/binop

    > calc._not1(undefined)
    undefined
    > calc._and2(undefined,true)
    undefined
    > calc._and2(undefined,false)
    false
    > calc._or2(undefined,true)
    true
    > calc._or2(undefined,false)
    undefined
    >

prefix-op

calc.or(true,undefined,false) true calc.or(false,undefined,false) undefined

trans

    > trans.translate(1)
    true
    > trans.translate('t')
    true
    > trans.translate('true')
    true
    > trans.translate('tru')
    true
    > trans.translate('y')
    true
    > trans.translate('yes')
    true
    > trans.translate('是')
    true
    > trans.translate('真')
    true

API

calc

binop

    const _not1 = (o,empty=undefined)   =>(o===empty)?o:!o;
    const _and2 = (l,r,empty=undefined) => {
    const _or2 = (l,r,empty=undefined) => {

prefix-op

     const not = (ary,empty=undefined) => _not1(ary[0]);
     const and = (ary,empty=undefined) => {
     const or = (ary,empty=undefined) => {

trans

    const is_true_lower_str = (o) =>(
    const is_true_str = (o) => is_true_lower_str(o.toLowerCase());
    const is_true_val = (o) => (o===true || o===1);
    const is_true = (o)=> is_true_val(o) || is_true_str(o);
    const is_false_lower_str = (o) => (
    const is_false_val = (o) => (o===false || o===0);
    const is_false = (o)=> is_false_val(o) || is_false_str(o);
    const is_undef_lower_str = (o) => (
    const is_undef_val = (o) => (o===undefined || o===-1);
    const is_undef = (o)=> is_false_val(o) || is_false_str(o);
    const translate = (o) => {

LICENSE

  • ISC