toBoolValue function
Converts data
to bool
or throws FormatException if cannot convert.
Implementation
bool toBoolValue(Object? data) {
if (data == null) throw const NullValueException();
if (data is bool) {
return data;
} else if (data is num) {
return data.round() != 0;
} else if (data is BigInt) {
return data.toInt() != 0;
} else if (data is String) {
switch (data) {
case '':
case 'false':
case '0':
return false;
case 'true':
case '1':
return true;
}
}
throw ConversionException(target: bool, data: data);
}