@fuzzle/opencode-accountant 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +32 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -17272,6 +17272,11 @@ function validateDetectionRule(providerName, index, rule) {
|
|
|
17272
17272
|
}
|
|
17273
17273
|
}
|
|
17274
17274
|
}
|
|
17275
|
+
if (ruleObj.closingBalanceField !== undefined) {
|
|
17276
|
+
if (typeof ruleObj.closingBalanceField !== "string" || ruleObj.closingBalanceField === "") {
|
|
17277
|
+
throw new Error(`Invalid config: provider '${providerName}' detect[${index}].closingBalanceField must be a non-empty string`);
|
|
17278
|
+
}
|
|
17279
|
+
}
|
|
17275
17280
|
return {
|
|
17276
17281
|
filenamePattern: ruleObj.filenamePattern,
|
|
17277
17282
|
header: ruleObj.header,
|
|
@@ -17279,7 +17284,8 @@ function validateDetectionRule(providerName, index, rule) {
|
|
|
17279
17284
|
skipRows: ruleObj.skipRows,
|
|
17280
17285
|
delimiter: ruleObj.delimiter,
|
|
17281
17286
|
renamePattern: ruleObj.renamePattern,
|
|
17282
|
-
metadata: ruleObj.metadata
|
|
17287
|
+
metadata: ruleObj.metadata,
|
|
17288
|
+
closingBalanceField: ruleObj.closingBalanceField
|
|
17283
17289
|
};
|
|
17284
17290
|
}
|
|
17285
17291
|
function validateProviderConfig(name, config2) {
|
|
@@ -17386,6 +17392,25 @@ function parseCSVPreview(content, skipRows = 0, delimiter = ",") {
|
|
|
17386
17392
|
firstRow: result.data[0]
|
|
17387
17393
|
};
|
|
17388
17394
|
}
|
|
17395
|
+
function extractLastRowField(content, skipRows, delimiter, fieldName) {
|
|
17396
|
+
let csvContent = content;
|
|
17397
|
+
if (skipRows > 0) {
|
|
17398
|
+
const lines = content.split(`
|
|
17399
|
+
`);
|
|
17400
|
+
csvContent = lines.slice(skipRows).join(`
|
|
17401
|
+
`);
|
|
17402
|
+
}
|
|
17403
|
+
const result = import_papaparse.default.parse(csvContent, {
|
|
17404
|
+
header: true,
|
|
17405
|
+
skipEmptyLines: true,
|
|
17406
|
+
delimiter
|
|
17407
|
+
});
|
|
17408
|
+
if (result.data.length === 0)
|
|
17409
|
+
return;
|
|
17410
|
+
const lastRow = result.data[result.data.length - 1];
|
|
17411
|
+
const value = lastRow[fieldName];
|
|
17412
|
+
return value ? value.trim() : undefined;
|
|
17413
|
+
}
|
|
17389
17414
|
function normalizeHeader(fields) {
|
|
17390
17415
|
return fields.map((f) => f.trim()).join(",");
|
|
17391
17416
|
}
|
|
@@ -17416,6 +17441,12 @@ function detectProvider(filename, content, config2) {
|
|
|
17416
17441
|
continue;
|
|
17417
17442
|
}
|
|
17418
17443
|
const metadata = extractMetadata(content, skipRows, delimiter, rule.metadata);
|
|
17444
|
+
if (rule.closingBalanceField) {
|
|
17445
|
+
const closingBalance = extractLastRowField(content, skipRows, delimiter, rule.closingBalanceField);
|
|
17446
|
+
if (closingBalance) {
|
|
17447
|
+
metadata["closing-balance"] = closingBalance;
|
|
17448
|
+
}
|
|
17449
|
+
}
|
|
17419
17450
|
const outputFilename = generateOutputFilename(rule.renamePattern, metadata);
|
|
17420
17451
|
const normalizedCurrency = providerConfig.currencies[rawCurrency];
|
|
17421
17452
|
if (!normalizedCurrency) {
|