Convert a string to a boolean - Node.js Data Type

Node.js examples for Data Type:Boolean

Description

Convert a string to a boolean

Demo Code

// Convert a string to a boolean
// (case-insensitive equality test against the string "true")
String.prototype.bool = function(defaultToTrue) {
    if (defaultToTrue && this == "") {
        return true;
    }/*from w  ww .j  av a 2s  . c o  m*/
    return (/  rue$/i).test(this);
};

Related Tutorials