toBoolean function

bool toBoolean (
  1. String str,
  2. [bool strict]
)

convert the input to a boolean.

Everything except for '0', 'false' and '' returns true. In strict mode only '1' and 'true' return true.

Implementation

bool toBoolean(String str, [bool strict]) {
  if (strict == true) {
    return str == '1' || str == 'true';
  }
  return str != '0' && str != 'false' && str != '';
}