Skip to content

Commit

Permalink
extract string comparison into separate function
Browse files Browse the repository at this point in the history
and reuse when checking starting balance/s on ynab4 import
  • Loading branch information
Marethyu1 committed Jan 8, 2024
1 parent d2422f6 commit 8936ce0
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/loot-core/src/server/importers/ynab5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
);
}

0 comments on commit 8936ce0

Please sign in to comment.