mirror of
https://github.com/immich-app/immich.git
synced 2024-12-17 12:22:31 +02:00
31 lines
640 B
Dart
31 lines
640 B
Dart
|
extension StringExtension on String {
|
||
|
String capitalize() {
|
||
|
return split(" ")
|
||
|
.map(
|
||
|
(str) => str.isEmpty ? str : str[0].toUpperCase() + str.substring(1),
|
||
|
)
|
||
|
.join(" ");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
extension DurationExtension on String {
|
||
|
Duration? toDuration() {
|
||
|
try {
|
||
|
final parts = split(':')
|
||
|
.map((e) => double.parse(e).toInt())
|
||
|
.toList(growable: false);
|
||
|
return Duration(hours: parts[0], minutes: parts[1], seconds: parts[2]);
|
||
|
} catch (e) {
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
double toDouble() {
|
||
|
return double.parse(this);
|
||
|
}
|
||
|
|
||
|
int toInt() {
|
||
|
return int.parse(this);
|
||
|
}
|
||
|
}
|