JSFiddle - React, Tailwind, and code Playground

by JakobJingleheimer

HTML

<ol id="log"></ol>

CSS

.false {
    color: red;
}
.true {
    color: green;
}

JavaScript

function toBoolean(value) {
  if (value && value.length !== 0) {
    var v = ("" + value).toLowerCase();
    value = !(v == 'f' || v == '0' || v == 'false' || v == 'no' || v == 'n' || v == '[]');
  } else {
    value = false;
  }
  return value;
}

function shouldHide(tab) {
console.log(tab);
    var result = !toBoolean( tab ) || (typeof(tab.blurb) !== 'undefined' && !tab.blurb) || (typeof(tab.slides) !== 'undefined' && !tab.slides.length);
    return result;
}

var Log = document.getElementById('log');

function log(msg,classes) {
    Log.innerHTML += '<li class="'+classes+'">'+msg+'</li>';
}

var MyObj = {
    about: {
        blurb: '',
    },
    specialisations: {},
    gallery: {
        slides: [],
    },
    culture: {
        blurb: null
    },
};

var myObj1 = MyObj;
var result = shouldHide( myObj1.about ) + "";
log( 'myObj1.about: ' + JSON.stringify( myObj1.about ) , result );
    result = shouldHide( myObj1.specialisations ) + "";
log( 'myObj1.specialisations: ' + JSON.stringify( myObj1.specialisations ) , result );
    result = shouldHide( myObj1.gallery ) + "";
log( 'myObj1.gallery: ' + JSON.stringify( myObj1.gallery ) , result );
    result = shouldHide( myObj1.culture ) + "";
log( 'myObj1.culture: ' + JSON.stringify( myObj1.culture ) , result );

var myObj2 = MyObj;
    myObj2.about.blurb = 'oewhtoe';
    myObj2.specialisations = { foo: '' };
    myObj2.gallery.slides = [ 'a' , 'b' ];
    myObj2.culture.blurb = 'bondfob';

var result = shouldHide( myObj1.about ) + "";
log( 'myObj1.about: ' + JSON.stringify( myObj1.about ) , result );
    result = shouldHide( myObj1.specialisations ) + "";
log( 'myObj1.specialisations: ' + JSON.stringify( myObj1.specialisations ) , result );
    result = shouldHide( myObj1.gallery ) + "";
log( 'myObj1.gallery: ' + JSON.stringify( myObj1.gallery ) , result );
    result = shouldHide( myObj1.culture ) + "";
log( 'myObj1.culture: ' + JSON.stringify( myObj1.culture ) , result );