Commit ·
45e898d
1
Parent(s): 1f2ec65
feat: add data formatters
Browse files
web/src/utils/informationFormatters.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export const capitalizeFirstNameLetter = (string) => {
|
| 2 |
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
| 3 |
+
};
|
| 4 |
+
|
| 5 |
+
export const replaceDotWithComma = (number) => {
|
| 6 |
+
const numberToString = number.toString();
|
| 7 |
+
return numberToString.replace('.', ',');
|
| 8 |
+
};
|
| 9 |
+
|
| 10 |
+
export const replaceCommaWithDot = (amount) => {
|
| 11 |
+
return amount.replace(',', '.');
|
| 12 |
+
};
|
| 13 |
+
|
| 14 |
+
export const formatAmount = (amount) => {
|
| 15 |
+
const amountToString = amount.toString();
|
| 16 |
+
|
| 17 |
+
const formattedAmount = replaceDotWithComma(amountToString);
|
| 18 |
+
|
| 19 |
+
if (formattedAmount.indexOf(',') === -1) {
|
| 20 |
+
return formattedAmount + ',00';
|
| 21 |
+
}
|
| 22 |
+
return formattedAmount;
|
| 23 |
+
};
|
| 24 |
+
|
| 25 |
+
export const formatDate = (date) => {
|
| 26 |
+
const splittedDate = date.split('T');
|
| 27 |
+
|
| 28 |
+
const dayMonthYear = splittedDate[0].split('-');
|
| 29 |
+
|
| 30 |
+
const newDayMonthYear =
|
| 31 |
+
dayMonthYear[2] + '/' + dayMonthYear[1] + '/' + dayMonthYear[0];
|
| 32 |
+
|
| 33 |
+
const time = splittedDate[1].split('.');
|
| 34 |
+
|
| 35 |
+
return newDayMonthYear + ' às ' + time[0];
|
| 36 |
+
};
|
| 37 |
+
|
| 38 |
+
export const formatTransactionCategory = (category) => {
|
| 39 |
+
switch (category) {
|
| 40 |
+
case (category = 'deposit'):
|
| 41 |
+
return (category = 'Depósito');
|
| 42 |
+
case (category = 'payment'):
|
| 43 |
+
return (category = 'Pagamento');
|
| 44 |
+
case (category = 'withdrawl'):
|
| 45 |
+
return (category = 'Retirada');
|
| 46 |
+
default:
|
| 47 |
+
return null;
|
| 48 |
+
}
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
export const formatSingleDecimal = (amount) => {
|
| 52 |
+
const stringAmount = amount.toString();
|
| 53 |
+
const splitedAmount = stringAmount.split(',');
|
| 54 |
+
if (splitedAmount[1].length < 2) {
|
| 55 |
+
return stringAmount + '0';
|
| 56 |
+
}
|
| 57 |
+
return amount;
|
| 58 |
+
};
|
| 59 |
+
|
| 60 |
+
export const statementFormatter = (statement) => {
|
| 61 |
+
return {
|
| 62 |
+
category: formatTransactionCategory(statement.category),
|
| 63 |
+
amount: formatAmount(statement.amount),
|
| 64 |
+
created_at: formatDate(statement.created_at),
|
| 65 |
+
};
|
| 66 |
+
};
|