-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Removed space after colons in account names.
Sometimes the android keyboard / autosuggestion adds it.
- Loading branch information
Showing
4 changed files
with
67 additions
and
14 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Transaction } from 'pta-journal'; | ||
|
||
import { clearTransaction, fixColons } from './fix-transaction'; | ||
|
||
describe("clearTransaction", () => { | ||
test("Clears empty postings", () => { | ||
const trx: Transaction = { | ||
comment: "comment", | ||
date: new Date("2019-01-01"), | ||
description: "string", | ||
entries: [ | ||
{ account: "", amount: "" }, | ||
{ account: "A", amount: "" }, | ||
{ account: "", amount: "123" }, | ||
], | ||
}; | ||
|
||
expect(clearTransaction(trx).entries.length).toBe(2); | ||
}); | ||
}); | ||
|
||
describe("fixColons", () => { | ||
test("Clears empty spaces in accounts", () => { | ||
const trx: Transaction = { | ||
comment: "comment", | ||
date: new Date("2019-01-01"), | ||
description: "string", | ||
entries: [{ account: "Expenses: Groceries", amount: "" }], | ||
}; | ||
|
||
expect(fixColons(trx).entries[0].account).toBe("Expenses:Groceries"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import dayjs from 'dayjs'; | ||
import { Transaction } from 'pta-journal'; | ||
|
||
type FixTransaction = (trx: Transaction) => Transaction; | ||
|
||
// Removes empty entries | ||
export const clearTransaction: FixTransaction = (trx) => { | ||
return { | ||
...trx, | ||
entries: trx.entries.filter((e) => !(e.account == "" && e.amount === "")), | ||
}; | ||
}; | ||
|
||
// Removes empty entries | ||
export const fixColons: FixTransaction = (trx) => { | ||
return { | ||
...trx, | ||
entries: trx.entries.map((e) => ({ | ||
...e, | ||
account: e.account.replace(/:\s+/g, ":"), | ||
})), | ||
}; | ||
}; | ||
|
||
const compose = | ||
(...functions) => | ||
(args) => | ||
functions.reduceRight((arg, fn) => fn(arg), args); | ||
|
||
const fixer: FixTransaction = compose(clearTransaction, fixColons); | ||
|
||
export default fixer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters