diff --git a/packages/netglade_utils/CHANGELOG.md b/packages/netglade_utils/CHANGELOG.md index 5d04a9f..d734b30 100644 --- a/packages/netglade_utils/CHANGELOG.md +++ b/packages/netglade_utils/CHANGELOG.md @@ -1,4 +1,7 @@ +## 2.3.0 +- Add more String extensions. + ## 2.2.0 - Add `mapIndexed2` - replacement for built-in mapIndexed which uses sync* - Add `where` extension on Map type - returning new map instance. diff --git a/packages/netglade_utils/lib/src/extensions/string_extensions.dart b/packages/netglade_utils/lib/src/extensions/string_extensions.dart index b6990bf..4c72f57 100644 --- a/packages/netglade_utils/lib/src/extensions/string_extensions.dart +++ b/packages/netglade_utils/lib/src/extensions/string_extensions.dart @@ -51,6 +51,33 @@ extension StringExtensions on String { return replaceAll(pattern, ''); } + + String capitalize() { + if (length < 2) return this; + + return '${this[0].toUpperCase()}${characters.getRange(1).toLowerCase()}'; + } + + String shorten(int maxLength) { + if (length < maxLength) return this; + + return '${characters.getRange(0, maxLength)}...'; + } + + String stripOuterQuotes() { + var result = this; + if (result.startsWith('"')) result = result.replaceFirst('"', ''); + + if (result.endsWith('"')) result = result.replaceRange(result.length - 1, null, ''); + + return result; + } + + String firstLetterUppercase() => '${this[0].toUpperCase()}${characters.getRange(1)}'; + + String stripNewLines([String placeholder = ' ']) { + return replaceAll(RegExp(r'\s+'), placeholder); + } } extension NullableStringExtensions on String? { diff --git a/packages/netglade_utils/pubspec.yaml b/packages/netglade_utils/pubspec.yaml index dfc40f8..962f5f8 100644 --- a/packages/netglade_utils/pubspec.yaml +++ b/packages/netglade_utils/pubspec.yaml @@ -1,5 +1,5 @@ name: netglade_utils -version: 2.2.0 +version: 2.3.0 description: Dart utils used internally at netglade. repository: https://github.com/netglade/flutter_core/tree/main/packages/netglade_utils issue_tracker: https://github.com/netglade/flutter_core/issues