toNullableBool method

bool? toNullableBool()

Implementation

bool? toNullableBool() {
  if (isUndefinedOrNull) return null;
  if (isA<JSBoolean>()) return (this as JSBoolean).toDart;
  if (isA<JSNumber>()) return (this as JSNumber).toDartInt != 0;
  if (isA<JSString>()) return switch ((this as JSString).toDart.trim().toLowerCase()) {
    'true' || '1' => true,
    'false' || '0' => false,
    _ => null,
  };
  return null;
}