Skip to content

Commit

Permalink
feat: Add nullable string extension
Browse files Browse the repository at this point in the history
  • Loading branch information
enrique-lozano committed Jul 25, 2024
1 parent 3d9bb60 commit b36fd40
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/core/extensions/string.extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,20 @@ extension StringExtension on String {
return '${this[0].toUpperCase()}${substring(1).toLowerCase()}';
}
}

extension NullableStringExtensions<E> on String? {
/// Returns `true` if this string is `null` or empty.
bool get isNullOrEmpty {
return this?.isEmpty ?? true;
}

/// Returns `true` if this string is not `null` and not empty.
bool get isNotNullNorEmpty {
return this?.isNotEmpty ?? false;
}

/// Returns the string if it is not `null` and not empty, otherwise returns `null`.
String? get notEmptyString {
return this.isNotNullNorEmpty ? this : null;
}
}

0 comments on commit b36fd40

Please sign in to comment.