2025-09-29 23:01:09 +05:30
|
|
|
import 'dart:convert';
|
|
|
|
|
|
2023-11-09 16:19:53 +00:00
|
|
|
extension StringExtension on String {
|
|
|
|
|
String capitalize() {
|
2025-07-29 00:34:03 +05:30
|
|
|
return split(" ").map((str) => str.isEmpty ? str : str[0].toUpperCase() + str.substring(1)).join(" ");
|
2023-11-09 16:19:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension DurationExtension on String {
|
2024-01-05 05:20:55 +00:00
|
|
|
/// Parses and returns the string of format HH:MM:SS as a duration object else null
|
2023-11-09 16:19:53 +00:00
|
|
|
Duration? toDuration() {
|
|
|
|
|
try {
|
2025-07-25 08:07:22 +05:30
|
|
|
final parts = split(':').map((e) => double.parse(e).toInt()).toList(growable: false);
|
2023-11-09 16:19:53 +00:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-29 23:01:09 +05:30
|
|
|
|
|
|
|
|
Map<String, dynamic>? tryJsonDecode(dynamic json) {
|
|
|
|
|
try {
|
|
|
|
|
return jsonDecode(json) as Map<String, dynamic>;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|