Node.js API for hledger
JavaScript Makefile
Switch branches/tags
Nothing to show
Clone or download
Latest commit 6422d16 Aug 7, 2016
Permalink
Failed to load latest commit information.
lib Update docs Aug 7, 2016
test Support mode: 'list' Aug 7, 2016
.gitignore Initial commit Dec 4, 2015
.travis.yml Use hledger from apt Dec 7, 2015
HISTORY.md Release v1.1.1 Aug 7, 2016
Makefile Update docs Dec 6, 2015
README.md Update docs Aug 7, 2016
index.js Tableizes CSVs Dec 6, 2015
package.json Release v1.1.1 Aug 7, 2016

README.md

node-hledger

Node.js API for hledger.

npm install --save-exact hledger

Status

API

hledger

hledger(args, options)

Invokes hledger and returns a promise. It resolves into the CSV output as a 2D array.

var hledger = require('hledger')

hledger(['bal', 'Assets'])
  .then((data) => ...)

[ [ 'account', 'balance' ],
  [ 'Assets', '$200' ],
  [ 'Assets:Savings', '$150' ],
  [ 'Assets:Checking', '$50' ] ]

You can invoke it with a string:

hledger('bal Assets')

You can then use functions to make better sense of them:

hledger(['bal', 'Assets'])
  .then(hledger.tableize)
  .then((data) => ...)

[ { account: 'Assets', balance: '$200' },
  { account: 'Assets:Savings', balance: '$150' },
  ... ]

You may pass the option { mode: 'list' } to support commands that don't have CSV output (eg, accounts).

hledger('accounts', { mode: 'list' })
.then(data => ...)

[ 'Assets:Savings',
  'Assets:Checking'
]

hledger.tableize

tableize(list)

hledger.tableize: Turns a CSV-based array into an table list.

input = [
  ['account', 'amount'],
  ['Savings', '$100'],
  ['Checking', '$150']
]

tableize(input)
// [ { account: 'Savings', amount: '$100' },
//   { account: 'Checking', amount: '$200' } ]

Used for piping into hledger()'s promise output:

hledger('...')
  .then(hledger.tableize)
  .then((data) => ...)

Thanks

node-hledger © 2015+, Rico Sta. Cruz. Released under the MIT License.
Authored and maintained by Rico Sta. Cruz with help from contributors (list).

ricostacruz.com  ·  GitHub @rstacruz  ·  Twitter @rstacruz