mirror of
https://github.com/hanskokx/arcane_helper_utils.git
synced 2026-05-14 02:19:09 +02:00
v1.3.2
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
## 1.3.2
|
||||
|
||||
- Added `isEmptyOrNull` and `isNotEmptyOrNull` extensions for `List` and `String` objects. These extensions are identical to `isNullOrEmpty` and `isNotNullOrEmpty`, respectively.
|
||||
- Fixed a bug in the `DateTime` extension that caused incorrect results when comparing dates using `isToday`.
|
||||
|
||||
## 1.3.1
|
||||
|
||||
- Added the `isNullOrEmpty` and `isNotNullOrEmpty` extensions for `List` objects.
|
||||
|
||||
@@ -89,7 +89,8 @@ extension DaysInMonth on DateTime {
|
||||
/// An extension on `DateTime` to check if a date is today or if it is the same day as another date.
|
||||
extension IsToday on DateTime {
|
||||
/// Returns `true` if the current date is today.
|
||||
bool get isToday => DateTime.now().difference(this).inDays == 0;
|
||||
bool get isToday =>
|
||||
DateTime.now().startOfDay.difference(this.startOfDay).inMilliseconds == 0;
|
||||
|
||||
/// Returns `true` if the current date is the same day as [other].
|
||||
bool isSameDayAs(DateTime other) =>
|
||||
|
||||
@@ -52,7 +52,7 @@ extension Unique<E, Id> on List<E> {
|
||||
extension ListNullability on List? {
|
||||
/// Returns `true` if the list is either not null and not empty.
|
||||
///
|
||||
/// This is the inverse of [isNullOrEmpty].
|
||||
/// This is the inverse of [isNotEmptyOrNull].
|
||||
///
|
||||
/// Example usage:
|
||||
/// ```dart
|
||||
@@ -65,8 +65,29 @@ extension ListNullability on List? {
|
||||
/// list = null;
|
||||
/// print(list.isNotNullOrEmpty); // Output: false
|
||||
/// ```
|
||||
///
|
||||
/// This is identical to [isNotNullOrEmpty].
|
||||
bool get isNotNullOrEmpty => !isNullOrEmpty;
|
||||
|
||||
/// Returns `true` if the list is either not null and not empty.
|
||||
///
|
||||
/// This is the inverse of [isEmptyOrNull].
|
||||
///
|
||||
/// Example usage:
|
||||
/// ```dart
|
||||
/// List<int>? list = [1, 2, 3];
|
||||
/// print(list.isNotEmptyOrNull); // Output: true
|
||||
///
|
||||
/// list = [];
|
||||
/// print(list.isNotEmptyOrNull); // Output: false
|
||||
///
|
||||
/// list = null;
|
||||
/// print(list.isNotEmptyOrNull); // Output: false
|
||||
/// ```
|
||||
///
|
||||
/// This is identical to [isNotNullOrEmpty].
|
||||
bool get isNotEmptyOrNull => !isNullOrEmpty;
|
||||
|
||||
/// Returns `true` if the list is either null or empty.
|
||||
///
|
||||
/// Example usage:
|
||||
@@ -80,5 +101,24 @@ extension ListNullability on List? {
|
||||
/// list = [1, 2, 3];
|
||||
/// print(list.isNullOrEmpty); // Output: false
|
||||
/// ```
|
||||
///
|
||||
/// This is identical to [isEmptyOrNull].
|
||||
bool get isNullOrEmpty => this == null || this!.isEmpty;
|
||||
|
||||
/// Returns `true` if the list is either null or empty.
|
||||
///
|
||||
/// Example usage:
|
||||
/// ```dart
|
||||
/// List<int>? list = null;
|
||||
/// print(list.isEmptyOrNull); // Output: true
|
||||
///
|
||||
/// list = [];
|
||||
/// print(list.isEmptyOrNull); // Output: true
|
||||
///
|
||||
/// list = [1, 2, 3];
|
||||
/// print(list.isEmptyOrNull); // Output: false
|
||||
/// ```
|
||||
///
|
||||
/// This is identical to [isEmptyOrNull].
|
||||
bool get isEmptyOrNull => isNullOrEmpty;
|
||||
}
|
||||
|
||||
@@ -29,8 +29,26 @@ extension Nullability on String? {
|
||||
/// print("The string is not null and not empty");
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// This is identical to [isNotEmptyOrNull].
|
||||
bool get isNotNullOrEmpty => !isNullOrEmpty;
|
||||
|
||||
/// Returns `true` if the `String?` is neither `null` nor contains only whitespace.
|
||||
///
|
||||
/// This is useful for cases where you want to check if a nullable string has a valid
|
||||
/// non-empty, non-whitespace value.
|
||||
///
|
||||
/// Example usage:
|
||||
/// ```dart
|
||||
/// String? example = "Hello";
|
||||
/// if (example.isNotEmptyOrNull) {
|
||||
/// print("The string is not null and not empty");
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// This is identical to [isNotNullOrEmpty].
|
||||
bool get isNotEmptyOrNull => isNotNullOrEmpty;
|
||||
|
||||
/// Returns `true` if the `String?` is either `null` or contains only whitespace.
|
||||
///
|
||||
/// This is a handy utility to check if a nullable string is either not assigned
|
||||
@@ -43,7 +61,25 @@ extension Nullability on String? {
|
||||
/// print("The string is null or empty");
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// This is identical to [isEmptyOrNull].
|
||||
bool get isNullOrEmpty => this == null || (this ?? "").trim().isEmpty;
|
||||
|
||||
/// Returns `true` if the `String?` is either `null` or contains only whitespace.
|
||||
///
|
||||
/// This is a handy utility to check if a nullable string is either not assigned
|
||||
/// or effectively empty (including strings with only whitespace characters).
|
||||
///
|
||||
/// Example usage:
|
||||
/// ```dart
|
||||
/// String? example = null;
|
||||
/// if (example.isEmptyOrNull) {
|
||||
/// print("The string is null or empty");
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// This is identical to [isNullOrEmpty].
|
||||
bool get isEmptyOrNull => isNullOrEmpty;
|
||||
}
|
||||
|
||||
/// An extension on `String` to split the string into parts of a specified length.
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
name: arcane_helper_utils
|
||||
description: Provides a variety of helpful utilities and extensions for Flutter
|
||||
and Dart.
|
||||
version: 1.3.1
|
||||
version: 1.3.2
|
||||
repository: https://github.com/hanskokx/arcane_helper_utils
|
||||
issue_tracker: https://github.com/hanskokx/arcane_helper_utils/issues
|
||||
|
||||
|
||||
@@ -33,16 +33,19 @@ void main() {
|
||||
group("ListNullability", () {
|
||||
test("isNullOrEmpty returns true for null list", () {
|
||||
List<int>? list;
|
||||
expect(list.isEmptyOrNull, true);
|
||||
expect(list.isNullOrEmpty, true);
|
||||
});
|
||||
|
||||
test("isNullOrEmpty returns true for empty list", () {
|
||||
final List<int> list = [];
|
||||
expect(list.isEmptyOrNull, true);
|
||||
expect(list.isNullOrEmpty, true);
|
||||
});
|
||||
|
||||
test("isNullOrEmpty returns false for non-empty list", () {
|
||||
final list = [1, 2, 3];
|
||||
expect(list.isEmptyOrNull, false);
|
||||
expect(list.isNullOrEmpty, false);
|
||||
});
|
||||
|
||||
@@ -51,9 +54,13 @@ void main() {
|
||||
final emptyList = <int>[];
|
||||
final nonEmptyList = [1, 2, 3];
|
||||
|
||||
expect(nullList.isNotNullOrEmpty, false);
|
||||
expect(emptyList.isNotNullOrEmpty, false);
|
||||
expect(nonEmptyList.isNotNullOrEmpty, true);
|
||||
expect(nullList.isEmptyOrNull, !nullList.isNotEmptyOrNull);
|
||||
expect(emptyList.isEmptyOrNull, !emptyList.isNotEmptyOrNull);
|
||||
expect(nonEmptyList.isEmptyOrNull, !nonEmptyList.isNotEmptyOrNull);
|
||||
|
||||
expect(nullList.isNullOrEmpty, !nullList.isNotNullOrEmpty);
|
||||
expect(emptyList.isNullOrEmpty, !emptyList.isNotNullOrEmpty);
|
||||
expect(nonEmptyList.isNullOrEmpty, !nonEmptyList.isNotNullOrEmpty);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user