@fuzzle/opencode-accountant 0.7.1 → 0.7.2

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.
Files changed (2) hide show
  1. package/dist/index.js +13 -13
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -17417,11 +17417,18 @@ function normalizeHeader(fields) {
17417
17417
  function detectProvider(filename, content, config2) {
17418
17418
  for (const [providerName, providerConfig] of Object.entries(config2.providers)) {
17419
17419
  for (const rule of providerConfig.detect) {
17420
+ let filenameMetadata = {};
17420
17421
  if (rule.filenamePattern !== undefined) {
17421
17422
  const filenameRegex = new RegExp(rule.filenamePattern);
17422
- if (!filenameRegex.test(filename)) {
17423
+ const filenameMatch = filenameRegex.exec(filename);
17424
+ if (!filenameMatch) {
17423
17425
  continue;
17424
17426
  }
17427
+ if (filenameMatch.groups) {
17428
+ for (const [key, value] of Object.entries(filenameMatch.groups)) {
17429
+ filenameMetadata[key.replace(/_/g, "-")] = value;
17430
+ }
17431
+ }
17425
17432
  }
17426
17433
  const skipRows = rule.skipRows ?? 0;
17427
17434
  const delimiter = rule.delimiter ?? ",";
@@ -17440,27 +17447,20 @@ function detectProvider(filename, content, config2) {
17440
17447
  if (!rawCurrency) {
17441
17448
  continue;
17442
17449
  }
17443
- const metadata = extractMetadata(content, skipRows, delimiter, rule.metadata);
17450
+ const headerMetadata = extractMetadata(content, skipRows, delimiter, rule.metadata);
17451
+ const metadata = { ...filenameMetadata, ...headerMetadata };
17444
17452
  if (rule.closingBalanceField) {
17445
17453
  const closingBalance = extractLastRowField(content, skipRows, delimiter, rule.closingBalanceField);
17446
17454
  if (closingBalance) {
17447
17455
  metadata["closing-balance"] = closingBalance;
17448
17456
  }
17449
17457
  }
17450
- const outputFilename = generateOutputFilename(rule.renamePattern, metadata);
17451
17458
  const normalizedCurrency = providerConfig.currencies[rawCurrency];
17452
- if (!normalizedCurrency) {
17453
- return {
17454
- provider: providerName,
17455
- currency: rawCurrency.toLowerCase(),
17456
- rule,
17457
- outputFilename,
17458
- metadata: Object.keys(metadata).length > 0 ? metadata : undefined
17459
- };
17460
- }
17459
+ metadata["currency"] = normalizedCurrency || rawCurrency.toLowerCase();
17460
+ const outputFilename = generateOutputFilename(rule.renamePattern, metadata);
17461
17461
  return {
17462
17462
  provider: providerName,
17463
- currency: normalizedCurrency,
17463
+ currency: normalizedCurrency || rawCurrency.toLowerCase(),
17464
17464
  rule,
17465
17465
  outputFilename,
17466
17466
  metadata: Object.keys(metadata).length > 0 ? metadata : undefined
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fuzzle/opencode-accountant",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "An OpenCode accounting agent, specialized in double-entry-bookkepping with hledger",
5
5
  "author": {
6
6
  "name": "ali bengali",