feat: int and string extension

This commit is contained in:
efrilm
2025-08-13 00:26:59 +07:00
parent e732a27914
commit 3d43d7a934
4 changed files with 49 additions and 8 deletions
@@ -0,0 +1,28 @@
part of 'extension.dart';
extension StringExt on String {
int get toIntegerFromText {
final cleanedText = replaceAll(RegExp(r'[^0-9]'), '');
final parsedValue = int.tryParse(cleanedText) ?? 0;
return parsedValue;
}
String get currencyFormatRpV2 {
final parsedValue = int.tryParse(this) ?? 0;
return NumberFormat.currency(
locale: 'id',
symbol: 'Rp. ',
decimalDigits: 0,
).format(parsedValue);
}
String get toTitleCase {
if (isEmpty) return '';
return split(' ')
.map((word) {
if (word.isEmpty) return '';
return word[0].toUpperCase() + word.substring(1).toLowerCase();
})
.join(' ');
}
}