Skip to content

Commit a675347

Browse files
committed
Add more String extensions
1 parent ccc38e6 commit a675347

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

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

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

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

5681
extension NullableStringExtensions on String? {

0 commit comments

Comments
 (0)