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 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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | 39x 39x 39x 767x 350x 350x 350x 767x 74x 74x 74x 74x 74x 74x 767x 71x 71x 71x 71x 767x 458x 458x 458x 458x 458x 458x 458x 458x 458x 767x 375x 375x 375x 375x 375x 375x 375x 375x 375x 375x 375x 375x 375x 767x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 767x 392x 392x 392x 17x 365x 392x 392x 392x 767x 8x 8x 8x 8x 8x 767x 13x 13x 29x 29x 29x 29x 13x 13x 13x 13x 13x 29x 29x 29x 29x 29x 28x 29x 29x 29x 29x 2x 2x 29x 13x 13x 13x 767x 440x 440x 767x 576x 576x 296x 554x 808x 808x 808x 808x 1256x 1256x 1256x 1256x 1256x 1256x 1256x 1256x 808x 296x 576x 767x 4x 4x 88x 88x 88x 88x 4x 4x 4x 4x 4x 4x 4x 767x 36x 36x 36x 767x 767x 767x 767x 767x 767x 767x 39x | 'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
module.exports = ({ numeric: { decimal: { formatDecimalFixed, parseDecimal, }, }, }) => {
function csvField(value) {
const text = String(value);
return /[",\r\n]/u.test(text) ? `"${text.replaceAll('"', '""')}"` : text;
}
function groupThousands(quantity) {
const [integer, fraction] = quantity.split('.');
const negative = integer.startsWith('-');
const digits = negative ? integer.slice(1) : integer;
const groupedInteger = digits.replace(/\B(?=(\d{3})+(?!\d))/gu, ',');
return `${negative ? '-' : ''}${groupedInteger}${fraction === undefined ? '' : `.${fraction}`}`;
}
function commodityFormats(descriptions) {
return new Map((descriptions ?? [])
.filter(({ format }) => format !== null)
.map(({ commodity, format }) => [commodity, format]));
}
function parseCommodityFormat(format) {
const match = /^((?:\d{1,3}(?:,\d{3})+|\d+))(?:\.(\d+))?[ \t]+[^ \t]+$/u.exec(format);
if (!match)
return null;
return {
decimalSeparator: match[2] ? '.' : null,
groupingSeparator: match[1].includes(',') ? ',' : null,
scale: match[2]?.length ?? 0,
};
}
function formatDeclaredQuantity(quantity, format) {
const parsedFormat = parseCommodityFormat(format);
if (!parsedFormat)
return quantity;
const fixed = formatDecimalFixed(parseDecimal(quantity), parsedFormat.scale);
const [integer, fraction] = fixed.split('.');
const negative = integer.startsWith('-');
const digits = negative ? integer.slice(1) : integer;
const grouped = parsedFormat.groupingSeparator === null
? digits
: digits.replace(/\B(?=(\d{3})+(?!\d))/gu, parsedFormat.groupingSeparator);
const decimal = fraction === undefined ? '' : `${parsedFormat.decimalSeparator}${fraction}`;
return `${negative ? '-' : ''}${grouped}${decimal}`;
}
function formatPriceQuantity(quantity, commodity, formats) {
const format = formats.get(commodity);
if (!format)
return quantity;
const parsedFormat = parseCommodityFormat(format);
if (!parsedFormat)
return quantity;
const point = quantity.indexOf('.');
const sourceScale = point < 0 ? 0 : quantity.length - point - 1;
const scale = Math.max(sourceScale, parsedFormat.scale);
const fixed = formatDecimalFixed(parseDecimal(quantity), scale);
const [integer, fraction] = fixed.split('.');
const grouped = parsedFormat.groupingSeparator === null
? integer
: groupThousands(integer);
return fraction === undefined ? grouped : `${grouped}.${fraction}`;
}
function displayQuantity(quantity, commodity, formats, fallbackScale) {
const format = formats.get(commodity);
if (format)
return formatDeclaredQuantity(quantity, format);
const fallback = fallbackScale === null
? quantity
: formatDecimalFixed(parseDecimal(quantity), fallbackScale);
return groupThousands(fallback);
}
function formatCsvTable(headings, rows) {
const lines = [headings.map(csvField).join(',')];
for (const row of rows)
lines.push(row.map(csvField).join(','));
return `${lines.join('\n')}\n`;
}
function formatAlignedAmounts(rows, showLabels) {
const commodityWidth = Math.max(0, ...rows.map((row) => row.commodity.length));
const amounts = rows.map((row) => {
const [integer, fraction] = row.decimalSeparator === null
? [row.quantity, undefined]
: row.quantity.split(row.decimalSeparator);
return { integer, fraction, separator: row.decimalSeparator };
});
const integerWidth = Math.max(0, ...amounts.map((amount) => amount.integer.length));
const fractionWidth = Math.max(0, ...amounts.map((amount) => amount.fraction?.length ?? 0));
const lines = [];
rows.forEach((row, index) => {
const { integer, fraction, separator } = amounts[index];
const integerColumn = integer.padStart(integerWidth);
const fractionColumn = fractionWidth === 0
? ''
: fraction === undefined
? ' '.repeat(fractionWidth + 1)
: `${separator}${fraction.padEnd(fractionWidth)}`;
const commodity = showLabels ? row.commodity.padEnd(commodityWidth) : row.commodity;
const amountColumn = `${integerColumn}${fractionColumn} ${commodity}`;
if (row.isTotal && !rows[index - 1]?.isTotal) {
lines.push('-'.repeat(amountColumn.length));
}
lines.push(showLabels ? `${amountColumn} ${row.label}` : amountColumn);
});
return lines.length === 0 ? '' : `${lines.join('\n')}\n`;
}
function formatJson(value) {
return `${JSON.stringify(value, null, 2)}\n`;
}
function formatWarnings(warnings) {
if (warnings.length === 0)
return '';
const lines = [];
for (const warning of warnings) {
if (lines.length > 0)
lines.push('');
lines.push(`[${warning.code}] ${warning.message}`);
for (const instance of warning.instances) {
const position = instance.column === null
? `${instance.source}:${instance.line}`
: `${instance.source}:${instance.line}:${instance.column}`;
const affectedLines = instance.startLine === instance.endLine
? ''
: ` (affected lines ${instance.startLine}-${instance.endLine})`;
lines.push(` ${position}${affectedLines}`);
}
}
return `${lines.join('\n')}\n`;
}
function formatTextTable(rows, columns) {
const widths = columns.map(({ heading, value }) => Math.max(heading.length, ...rows.map((row) => String(value(row)).length)));
const line = (values) => values.map((value, index) => {
const text = String(value);
return columns[index].align === 'right'
? text.padStart(widths[index])
: text.padEnd(widths[index]);
}).join(' ').trimEnd();
return `${[
line(columns.map(({ heading }) => heading)),
line(widths.map((width) => '-'.repeat(width))),
...rows.map((row) => line(columns.map(({ value }) => value(row)))),
].join('\n')}\n`;
}
function decimalScale(quantity) {
const point = quantity.indexOf('.');
return point < 0 ? 0 : quantity.length - point - 1;
}
return {
commodityFormats, csvField, decimalScale, formatCsvTable,
displayQuantity, formatAlignedAmounts, formatJson,
formatPriceQuantity, formatTextTable, parseCommodityFormat,
formatWarnings,
$$private: { parseCommodityFormat },
};
};
|