From 8936ce096d980b179d1d19b5738bb1ac96b738da Mon Sep 17 00:00:00 2001 From: stefanhall Date: Tue, 9 Jan 2024 09:03:45 +1300 Subject: [PATCH] extract string comparison into separate function and reuse when checking starting balance/s on ynab4 import --- .../loot-core/src/server/importers/ynab5.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/loot-core/src/server/importers/ynab5.ts b/packages/loot-core/src/server/importers/ynab5.ts index 57e3ed3f2e3..421c761ac13 100644 --- a/packages/loot-core/src/server/importers/ynab5.ts +++ b/packages/loot-core/src/server/importers/ynab5.ts @@ -133,15 +133,12 @@ async function importTransactions( const payees = await actual.getPayees(); const categories = await actual.getCategories(); const incomeCatId = categories.find(cat => cat.name === 'Income').id; - const startingBalanceCatId = categories.find( - cat => cat.name === 'Starting Balances', + const startingBalanceCatId = categories.find(cat => + equalsIgnoreCase(cat.name, 'Starting Balances'), ).id; //better way to do it? - const startingPayeeYNAB = data.payees.find( - payee => - payee.name.localeCompare('Starting Balance', undefined, { - sensitivity: 'base', - }) === 0, + const startingPayeeYNAB = data.payees.find(payee => + equalsIgnoreCase(payee.name, 'Starting Balance'), ).id; const transactionsGrouped = groupBy(data.transactions, 'account_id'); @@ -331,3 +328,11 @@ export function parseFile(buffer: Buffer): YNAB5.Budget { export function getBudgetName(_filepath: string, data: YNAB5.Budget) { return data.budget_name || data.name; } + +function equalsIgnoreCase(stringa: string, stringb: string): boolean { + return ( + stringa.localeCompare(stringb, undefined, { + sensitivity: 'base', + }) === 0 + ); +}