@vpdn/moneymoney-cli
Version:
Command-line interface for MoneyMoney app - list accounts and fetch transactions
70 lines • 2.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatAccounts = formatAccounts;
exports.formatTransactions = formatTransactions;
function formatAccounts(accounts) {
if (accounts.length === 0) {
return 'No accounts found';
}
const lines = [];
lines.push('Available Accounts:');
lines.push('==================');
accounts.forEach((account, index) => {
lines.push('');
lines.push(`Account ${index + 1}:`);
lines.push(` Name: ${account.name}`);
lines.push(` Number: ${account.accountNumber}`);
if (account.owner)
lines.push(` Owner: ${account.owner}`);
if (account.bankCode)
lines.push(` Bank Code: ${account.bankCode}`);
if (account.currency)
lines.push(` Currency: ${account.currency}`);
if (account.balance !== undefined)
lines.push(` Balance: ${formatAmount(account.balance, account.currency)}`);
if (account.type)
lines.push(` Type: ${account.type}`);
});
return lines.join('\n');
}
function formatTransactions(transactions) {
if (transactions.length === 0) {
return 'No transactions found';
}
const lines = [];
lines.push(`Found ${transactions.length} transactions:`);
lines.push('================================');
transactions.forEach((trans, index) => {
lines.push('');
lines.push(`Transaction ${index + 1}:`);
lines.push(` Date: ${formatDate(trans.bookingDate)}`);
lines.push(` Name: ${trans.name}`);
lines.push(` Amount: ${formatAmount(trans.amount)}`);
if (trans.accountNumber)
lines.push(` Account: ${trans.accountNumber}`);
if (trans.purpose)
lines.push(` Purpose: ${trans.purpose}`);
if (trans.category)
lines.push(` Category: ${trans.category}`);
if (trans.comment)
lines.push(` Comment: ${trans.comment}`);
});
return lines.join('\n');
}
function formatDate(date) {
if (!date || !(date instanceof Date)) {
return 'N/A';
}
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
}
function formatAmount(amount, currency) {
if (amount === undefined || amount === null) {
return 'N/A';
}
const formatted = amount.toFixed(2);
return currency ? `${formatted} ${currency}` : formatted;
}
//# sourceMappingURL=formatters.js.map