Skip to content

lyzadanger/ledger-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple "Ledger"

This package parses a ledger-format CSV input and allows for balance inquiries on any account (payer or payee) contained in the source CSV.

Install

Note: This package requires Node.js >= 6.2.0

  • clone or download repository
  • npm install

Use

  • npm start will put you in a REPL with Ledger in global context
  • npm test to run tests
  • npm run docs to generate JSDoc documentation (open created out/index.html in a browser)

Basic API

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#parse method which takes a CSV string (or Stream) directly. See docs generated by npm run docs for more details
  • Balance granularity by date is +1 day. e.g. a transaction for the date 2017-11-01 will affect the balance of affected accounts on 2017-11-02 (and not on 2017-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

Input format

Ledger expects CSV input rows to contain the following columns (only):

  1. date - ISO-8601-compatible date string
  2. payer - account name of payer
  3. payee - account name of payee
  4. amount - 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

About

Simple Ledger coding exercise

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors