Skip to content

Commit c279316

Browse files
authored
Merge pull request #43 from netglade/feat/update
Add more String extensions
2 parents ccc38e6 + c3f21d3 commit c279316

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

packages/netglade_utils/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

2+
## 2.3.0
3+
- Add more String extensions.
4+
25
## 2.2.0
36
- Add `mapIndexed2` - replacement for built-in mapIndexed which uses sync*
47
- Add `where` extension on Map type - returning new map instance.

packages/netglade_utils/lib/src/extensions/string_extensions.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,33 @@ extension StringExtensions on String {
5151

5252
return replaceAll(pattern, '');
5353
}
54+
55+
String capitalize() {
56+
if (length < 2) return this;
57+
58+
return '${this[0].toUpperCase()}${characters.getRange(1).toLowerCase()}';
59+
}
60+
61+
String shorten(int maxLength) {
62+
if (length < maxLength) return this;
63+
64+
return '${characters.getRange(0, maxLength)}...';
65+
}
66+
67+
String stripOuterQuotes() {
68+
var result = this;
69+
if (result.startsWith('"')) result = result.replaceFirst('"', '');
70+
71+
if (result.endsWith('"')) result = result.replaceRange(result.length - 1, null, '');
72+
73+
return result;
74+
}
75+
76+
String firstLetterUppercase() => '${this[0].toUpperCase()}${characters.getRange(1)}';
77+
78+
String stripNewLines([String placeholder = ' ']) {
79+
return replaceAll(RegExp(r'\s+'), placeholder);
80+
}
5481
}
5582

5683
extension NullableStringExtensions on String? {

packages/netglade_utils/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: netglade_utils
2-
version: 2.2.0
2+
version: 2.3.0
33
description: Dart utils used internally at netglade.
44
repository: https://github.com/netglade/flutter_core/tree/main/packages/netglade_utils
55
issue_tracker: https://github.com/netglade/flutter_core/issues

0 commit comments

Comments
 (0)