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