phillipbentonkelly
4/17/2017 - 2:53 PM

From http://stackoverflow.com/questions/263965/how-can-i-convert-a-string-to-boolean-in-javascript

stringToBoolean: function(string){
    if( typeof( string ) !== 'undefined' || string !== null ){
        if( parseInt( string ) !== NaN && Number.isInteger( string ) === true ) {
            if ( string === 0 || string === 1 ) {
                switch( string ){
                    case 1: return true;
                    case 0: return false;
                    default: return Boolean( string );
                }
            } else {
                console.warn( "Mixed request, value cannot be converted to Bool.", string );
            }
        } else {
            if( string === true || string === false ) {
                return string;
            } else {
                switch(string.toLowerCase().trim()){
                    case "true": case "yes": case "1": return true;
                    case "false": case "no": case "0": case null: return false;
                    default: return Boolean( string );
                }
            }
        }
    } else {
        console.warn( "Mixed request, value cannot be converted to Bool.", string );
    }
}