| 1 |
import { derived } from "svelte/store"; |
| 2 |
|
| 3 |
import { _ } from "../i18n"; |
| 4 |
import { account_details, fava_options, options } from "."; |
| 5 |
|
| 6 |
/** Whether an account should be collapsed in the account trees. */ |
| 7 |
export const collapse_account = derived(fava_options, ($fava_options) => { |
| 8 |
const matchers = $fava_options.collapse_pattern.map((p) => new RegExp(p)); |
| 9 |
return (name: string) => matchers.some((p) => p.test(name)); |
| 10 |
}); |
| 11 |
|
| 12 |
/** Whether the balances for an account should be inverted. */ |
| 13 |
export const invert_account = derived( |
| 14 |
[fava_options, options], |
| 15 |
([$fava_options, $options]): ((name: string) => boolean) => |
| 16 |
$fava_options.invert_income_liabilities_equity |
| 17 |
? (name) => |
| 18 |
name.startsWith($options.name_income) || |
| 19 |
name.startsWith($options.name_liabilities) || |
| 20 |
name.startsWith($options.name_equity) || |
| 21 |
name === _("Net Profit") |
| 22 |
: () => false, |
| 23 |
); |
| 24 |
|
| 25 |
/** Whether an account is closed before the given date. */ |
| 26 |
export const is_closed_account = derived( |
| 27 |
[account_details], |
| 28 |
([$account_details]) => |
| 29 |
(name: string, date: Date | null) => { |
| 30 |
const close_date = $account_details[name]?.close_date; |
| 31 |
if (!close_date) { |
| 32 |
return false; |
| 33 |
} |
| 34 |
return date === null ? true : close_date < date; |
| 35 |
}, |
| 36 |
); |