Nodejs String to Boolean Convert toBool()

Here you can find the source of toBool()

Method Source Code

/**/*from w  w w. java  2  s. c  o m*/
 *
 *   converts String to Boolean value
 *
 *   @return {Boolean}
 *
 */
String.prototype.toBool = function() {
   switch(this.toLowerCase()) {
      case 'true': case 'yes': case '1': return true;
      case 'false': case 'no': case '0': case null: return false;
      default: return Boolean(this);
   }
};

Related

  1. toBool()
    String.prototype.toBool = function() {
        return (/^true$/i).test(this);
    };
    
  2. toBool()
    String.prototype.toBool = function()
      return this.toLowerCase() === 'true';
    };
    
  3. toBoolOrString()
    String.prototype.toBoolOrString = function () {
      return this === 'true' ? true : this === 'false' ? false : this.toString();
    };
    
  4. toBoolean()
    String.prototype.toBoolean = function () {
      return this == 'true';
    };
    String.prototype.isBoolean = function () {
      return this === 'true' || this === 'false';
    };
    
  5. toBoolean()
    String.prototype.toBoolean = function(){
      return Boolean(+this) || this.isYes();
    };
    
  6. toBoolean()
    String.prototype.toBoolean = function () {
        return (/^true$/i).test(this);
    };