From 8b9842e6642d21dabb3753266292cf34da840199 Mon Sep 17 00:00:00 2001 From: Hans Kokx Date: Wed, 6 Nov 2024 12:44:17 +0100 Subject: [PATCH] v1.2.4 - Made `String` manipulation utilities available for nullable objects Signed-off-by: Hans Kokx --- CHANGELOG.md | 4 ++++ lib/arcane_helper_utils.dart | 3 +-- lib/src/extensions/string.dart | 12 +++++++----- pubspec.yaml | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bff1d5..8b88761 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.2.4 + +- Made `String` manipulation utilities available for nullable objects + ## 1.2.3 - Adjusted `capitalize` extension to convert remaining letters to lowercase diff --git a/lib/arcane_helper_utils.dart b/lib/arcane_helper_utils.dart index 1ff61cc..19110ad 100644 --- a/lib/arcane_helper_utils.dart +++ b/lib/arcane_helper_utils.dart @@ -2,8 +2,7 @@ library arcane_helper_utils; export "package:arcane_helper_utils/src/extensions/date_time.dart"; export "package:arcane_helper_utils/src/extensions/list.dart"; -export "package:arcane_helper_utils/src/extensions/string.dart" - show Nullability, Split, TextManipulation, CommonString; +export "package:arcane_helper_utils/src/extensions/string.dart"; export "package:arcane_helper_utils/src/extensions/string_jwt.dart"; export "package:arcane_helper_utils/src/utils/json_converter.dart"; export "package:arcane_helper_utils/src/utils/ticker.dart"; diff --git a/lib/src/extensions/string.dart b/lib/src/extensions/string.dart index b345b49..8f2f142 100644 --- a/lib/src/extensions/string.dart +++ b/lib/src/extensions/string.dart @@ -76,7 +76,7 @@ extension Split on String { } /// An extension on `String` to perform text manipulation tasks. -extension TextManipulation on String { +extension TextManipulation on String? { /// Capitalizes the first letter of the string. /// /// This method returns a new string where the first character is converted @@ -88,8 +88,8 @@ extension TextManipulation on String { /// String capitalized = text.capitalize; // "Hello" /// ``` String get capitalize { - if (isEmpty) return ""; - return "${this[0].toUpperCase()}${substring(1).toLowerCase()}"; + if (isNullOrEmpty) return ""; + return "${this![0].toUpperCase()}${this!.substring(1).toLowerCase()}"; } /// Capitalizes the first letter of each word in the string. @@ -103,7 +103,8 @@ extension TextManipulation on String { /// String capitalizedWords = text.capitalizeWords; // "Hello World" /// ``` String get capitalizeWords { - final strings = split(" "); + if (isNullOrEmpty) return ""; + final strings = this!.split(" "); return strings.map((s) => s.capitalize).join(" "); } @@ -120,7 +121,8 @@ extension TextManipulation on String { /// String spaced = text.spacePascalCase; // "Arcane Helper Utils" /// ``` String get spacePascalCase { - final List strings = split( + if (isNullOrEmpty) return ""; + final List strings = this!.split( "", ); String output = ""; diff --git a/pubspec.yaml b/pubspec.yaml index 09ff0cd..246f2e6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: arcane_helper_utils description: Provides a variety of helpful utilities and extensions for Flutter and Dart. -version: 1.2.3 +version: 1.2.4 repository: https://github.com/hanskokx/arcane_helper_utils issue_tracker: https://github.com/hanskokx/arcane_helper_utils/issues