Something went wrong. Try again.
Convert CSV banking statements to hledger journals
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132// The condition a cell suggests (D12, §6.7 of DESIGN_M1.md): its alias// searched case-insensitively for the cell's text.//// The text becomes a regex with as little rewriting as keeps the literal// well-formed (M1-RULE-017). Anything subtler is left for the author to edit:// regex characters in the text keep their regex meaning, and a pattern the// engine refuses is reported like any other.
// What would end the literal, or put a line break in it, and what replaces it.// "." for "/" also matches the slash, and needs no escape of its own.const REWRITTEN = { "/": ".", "\r": "\\r", "\n": "\\n", "\t": "\\t" };
// The pattern for a cell's text, or null for text that is only whitespace,// whose pattern would match every row.export function patternOf(text) { const trimmed = text.trim(); if (trimmed === "") return null; return trimmed.replace(/[/\r\n\t]/g, (character) => REWRITTEN[character]);}
export const clause = (alias, pattern) => `${alias} ~= /${pattern}/i`;
// What adding the clauses of a row's selected cells appends to a condition:// the clauses, all of which must hold, as the condition itself when it says// nothing yet, and otherwise as an alternative to it on a line of its own.export function appended(clauses, condition) { const all = clauses.join(" and "); if (condition.trim() === "") return all; const alternative = clauses.length > 1 ? `(${all})` : all; return (condition.endsWith("\n") ? "" : "\n") + "or " + alternative;}