Skip to content

leomeloxp/ledger-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ledger-parser

A NodeJS file parser for ledger-cli formatted files.

Github Repository available here.

Limitations

  • Currently only supports listing transactions in JSON format and adding new transaction from JSON.

  • Only supports one currency.

Usage

Install package

npm install ledger-parser

Require module and supply ledger file to be processed

var ledger = require('ledger-parser');
ledger.file = "path/to/file.ldgr";
ledger.currency = "£";

List recent transactions

Call ledger.recent(). It returns a JS Object literal for easy parsing or sending to front-end. For example, to send it as a response using express you could do something like (assuming express has been required and set):

app.get('/recent', function (req, res) { res.status(200).send(ledger.recent()) });
//returns
{
    date: "2015/01/05",
    consolidated: "*",
    payee: "Dinner Takeaway",
    postings: [
        {
        account: [
            "expenses",
            "food",
            "takeaway"
        ],
        currency: "£",
        amount: "41.40"
        },
        {
        account: [
            "assets",
            "bank",
            "checking"
        ],
        currency: "",
        amount: ""
        }
    ]
},

Adding transactions to your ledger file

Call ledger.add(transaction) it takes in a JSON/JS Object Literal like the one above and transforms it into a multi lined string that follows Ledger's syntax. Using the example above as our transaction we'd get:

ledger.add(transaction);
// Appends this to your file
2015/01/05 * Dinner Takeaway
    expenses:food:takeaway  £41.40
    assets:bank:checking

About

A NodeJS file parser for ledger-cli files.

Resources

License

Stars

Watchers

Forks

Packages

No packages published