All files / src/modules/implementations/commands/list-definitions/reports total-history.js

100% Statements 22/22
90% Branches 9/10
100% Functions 4/4
100% Lines 22/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 2340x 40x 40x 768x 2x 768x 768x 1x 1x 2x 2x 2x 1x 768x 768x 2x 2x 2x 2x 2x 768x 40x  
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
module.exports = ({ numeric: { decimal: { formatDecimalFixed, parseDecimal } } }) => ({
    loadFormatData(journal) {
        return journal.commodities({ usage: 'all' });
    },
    formatCsv(rows, _cliOptions, { csvField }) {
        const lines = ['date,amount'];
        for (const row of rows) {
            const fields = [row.date, formatDecimalFixed(parseDecimal(row.amount), 2)];
            lines.push(fields.map(csvField).join(','));
        }
        return `${lines.join('\n')}\n`;
    },
    formatText(rows, _cliOptions, { commodityFormats, displayQuantity }, descriptions) {
        const formats = commodityFormats(descriptions);
        const amounts = rows.map((row) => displayQuantity(row.amount, row.commodity, formats, 2, false));
        const amountWidth = Math.max(0, ...amounts.map((amount) => amount.length));
        const lines = rows.map((row, index) => `${row.date}  ${amounts[index].padStart(amountWidth)} ${row.commodity}`);
        return lines.length === 0 ? '' : `${lines.join('\n')}\n`;
    },
});