node package manager

hledger

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