mirror of
https://github.com/foss42/apidash.git
synced 2025-06-07 20:08:42 +08:00
22 lines
408 B
Dart
22 lines
408 B
Dart
extension StringExtension on String {
|
|
String capitalize() {
|
|
if (isEmpty) {
|
|
return this;
|
|
}
|
|
if (length == 1) {
|
|
return toUpperCase();
|
|
}
|
|
return "${this[0].toUpperCase()}${substring(1).toLowerCase()}";
|
|
}
|
|
|
|
String clip(int limit) {
|
|
if (limit < 0) {
|
|
return '...';
|
|
}
|
|
if (length <= limit) {
|
|
return this;
|
|
}
|
|
return "${substring(0, limit)}...";
|
|
}
|
|
}
|