This package parses a ledger-format CSV input and allows for balance inquiries on any account (payer or payee) contained in the source CSV.
Note: This package requires Node.js >= 6.2.0
- clone or download repository
npm install
npm startwill put you in a REPL withLedgerin global contextnpm testto run testsnpm run docsto generate JSDoc documentation (open createdout/index.htmlin a browser)
const ledger = new Ledger();
ledger.parseFile(`./data/ledger-example.csv`).then(() => {
console.log(ledger.balance('mary')); // -> 3183
console.log(ledger.balance('mary', '2015-01-17')); // -> 125
console.log(ledger.account('mary')); // -> Account { ... }
console.log(ledger.account('mary').balance()); // -> 3183
console.log(ledger.account('garfield')); // -> undefined
console.log(ledger.balance('garfield')); // -> undefined
});
Notes:
- There is also a
Ledger#parsemethod which takes a CSV string (or Stream) directly. See docs generated bynpm run docsfor more details - Balance granularity by date is +1 day. e.g. a transaction for the date
2017-11-01will affect the balance of affected accounts on2017-11-02(and not on2017-11-01). This is per my interpretation of requirements. - I've opted not to implement currency formatting, leaving it to the as-yet unimplemented UI layer
Ledger expects CSV input rows to contain the following columns (only):
date- ISO-8601-compatible date stringpayer- account name of payerpayee- account name of payeeamount- amount of transaction
Valid example:
2015-01-16,john,mary,125.00
2015-01-17,john,supermarket,20.00
2015-01-17,mary,insurance,100.00
2016-01-01,mary,gas,42.00
2016-01-03,bigcorp,mary,3200.00