@accounter/shaam-uniform-format-generator
Version:
Fully typed application that generates, parses, and validates SHAAM uniform format tax reports (INI.TXT and BKMVDATA.TXT).
95 lines (94 loc) • 3.02 kB
JavaScript
;
/**
* BKMVDATA.TXT file parsing utilities
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseDataFile = parseDataFile;
const index_js_1 = require("../generator/records/index.js");
/**
* Parses BKMVDATA.TXT file content
*
* @param content - Raw BKMVDATA.TXT file content
* @returns Parsed data structure
*/
function parseDataFile(content) {
const lines = content.split(/\r?\n/).map(line => line.replace(/\r$/, ''));
const records = {
a100: null,
b100: [],
b110: [],
c100: [],
d110: [],
d120: [],
m100: [],
z900: null,
};
const recordCounts = {};
const errors = [];
const unknownRecords = [];
for (let index = 0; index < lines.length; index++) {
const line = lines[index];
if (line.trim().length === 0)
continue;
if (line.length < 4)
continue;
const lineNumber = index + 1;
const recordType = line.slice(0, 4);
try {
switch (recordType) {
case 'A100':
records.a100 = (0, index_js_1.parseA100)(line);
break;
case 'B100':
records.b100.push((0, index_js_1.parseB100)(line));
break;
case 'B110':
records.b110.push((0, index_js_1.parseB110)(line));
break;
case 'C100':
records.c100.push((0, index_js_1.parseC100)(line));
break;
case 'D110':
records.d110.push((0, index_js_1.parseD110)(line));
break;
case 'D120':
records.d120.push((0, index_js_1.parseD120)(line));
break;
case 'M100':
records.m100.push((0, index_js_1.parseM100)(line));
break;
case 'Z900':
records.z900 = (0, index_js_1.parseZ900)(line);
break;
default:
unknownRecords.push({
lineNumber,
recordType,
line,
});
continue;
}
recordCounts[recordType] = (recordCounts[recordType] || 0) + 1;
}
catch (error) {
errors.push({
lineNumber,
recordType,
message: error instanceof Error ? error.message : 'Unknown parse error',
line,
});
}
}
return {
records,
summary: {
totalLines: lines.length,
parsedRecords: Object.values(recordCounts).reduce((sum, count) => sum + count, 0),
failedRecords: errors.length,
unknownRecords: unknownRecords.length,
perType: recordCounts,
},
errors,
unknownRecords,
};
}