- Null `String`s being manipulated should return `null` instead of an empty `String`

Signed-off-by: Hans Kokx <hans.kokx@hackberry.se>
This commit is contained in:
Hans Kokx
2024-11-06 12:46:18 +01:00
parent 8b9842e664
commit 92f475a8c7
3 changed files with 11 additions and 7 deletions
+4
View File
@@ -1,3 +1,7 @@
## 1.2.5
- Null `String`s being manipulated should return `null` instead of an empty `String`
## 1.2.4 ## 1.2.4
- Made `String` manipulation utilities available for nullable objects - Made `String` manipulation utilities available for nullable objects
+6 -6
View File
@@ -87,8 +87,8 @@ extension TextManipulation on String? {
/// String text = "hello"; /// String text = "hello";
/// String capitalized = text.capitalize; // "Hello" /// String capitalized = text.capitalize; // "Hello"
/// ``` /// ```
String get capitalize { String? get capitalize {
if (isNullOrEmpty) return ""; if (isNullOrEmpty) return null;
return "${this![0].toUpperCase()}${this!.substring(1).toLowerCase()}"; return "${this![0].toUpperCase()}${this!.substring(1).toLowerCase()}";
} }
@@ -102,8 +102,8 @@ extension TextManipulation on String? {
/// String text = "hello world"; /// String text = "hello world";
/// String capitalizedWords = text.capitalizeWords; // "Hello World" /// String capitalizedWords = text.capitalizeWords; // "Hello World"
/// ``` /// ```
String get capitalizeWords { String? get capitalizeWords {
if (isNullOrEmpty) return ""; if (isNullOrEmpty) return null;
final strings = this!.split(" "); final strings = this!.split(" ");
return strings.map((s) => s.capitalize).join(" "); return strings.map((s) => s.capitalize).join(" ");
} }
@@ -120,8 +120,8 @@ extension TextManipulation on String? {
/// String text = "ArcaneHelperUtils"; /// String text = "ArcaneHelperUtils";
/// String spaced = text.spacePascalCase; // "Arcane Helper Utils" /// String spaced = text.spacePascalCase; // "Arcane Helper Utils"
/// ``` /// ```
String get spacePascalCase { String? get spacePascalCase {
if (isNullOrEmpty) return ""; if (isNullOrEmpty) return null;
final List<String> strings = this!.split( final List<String> strings = this!.split(
"", "",
); );
+1 -1
View File
@@ -1,7 +1,7 @@
name: arcane_helper_utils name: arcane_helper_utils
description: Provides a variety of helpful utilities and extensions for Flutter description: Provides a variety of helpful utilities and extensions for Flutter
and Dart. and Dart.
version: 1.2.4 version: 1.2.5
repository: https://github.com/hanskokx/arcane_helper_utils repository: https://github.com/hanskokx/arcane_helper_utils
issue_tracker: https://github.com/hanskokx/arcane_helper_utils/issues issue_tracker: https://github.com/hanskokx/arcane_helper_utils/issues