Nodejs String to Boolean Convert toBoolean()

Here you can find the source of toBoolean()

Method Source Code

String.prototype.toBoolean = function () {
    if (this && this.toLowerCase() === 'true') {
        return true;
    }//from w  w w. j  a v  a2  s . c o  m
    else {
        return false;
    }
};

Related

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