npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

beancount

v0.0.31

Published

Parse and work with Beancount accounting files in TypeScript with full type safety

Readme

beancount

A parser and editor for Beancount accounting files with full type safety.

Installation

npm install beancount

Features

  • Full Beancount Support - All directives supported: transactions, open/close, balance, pad, note, document, price, event, query, custom, commodity, include, option, plugin, pushtag/poptag
  • Type-Safe - Complete TypeScript types for all entries and components
  • Rich Transaction Support - Tags, links, metadata, costs, price annotations, and postings
  • Round-Trip Parsing - Parse to objects and serialize back to text
  • Formatted Output - Column-aligned output with toFormattedString() and CLI formatter
  • CLI Formatter - Command-line tool beancount-format for formatting files with auto-aligned columns

Quick Start

import { parse, ParseResult } from 'beancount'

const beancountContent = `
2024-01-01 open Assets:Checking USD

2024-01-15 * "Grocery Store" "Weekly shopping"
  Assets:Checking   -50.00 USD
  Expenses:Food      50.00 USD
`

const result = parse(beancountContent)

// Access parsed entries
console.log(result.entries.length) // 2

// Convert back to string
console.log(result.toString())

// Convert to JSON
const resultJSON = JSON.stringify(result)
console.log(resultJSON)

// Convert back to parsed entries
console.log(ParseResult.fromJSON(result))

// Or with formatted output (aligned columns)
// only partially implemented at this point
console.log(result.toFormattedString())

Parsing Files

Use parseFile to parse a Beancount file directly from the filesystem:

import { parseFile } from 'beancount'

// Parse a single file
const result = await parseFile('/path/to/ledger.beancount')

// Parse with recursive includes - follows all `include` directives
const result = await parseFile('/path/to/main.beancount', { recurse: true })

When recurse: true, the parser follows all include directives and merges the entries from included files into the result. Circular includes are handled gracefully (each file is only parsed once).

CLI Usage

The package includes a beancount-format command-line tool for formatting Beancount files with aligned currency columns.

Basic Usage

# Format a file to stdout (preview changes)
beancount-format ledger.beancount

# Format a file in-place (modify the file)
beancount-format -w ledger.beancount

# Format multiple files
beancount-format -w accounts.beancount transactions.beancount

Options

  • -w, --write - Write formatted output back to the file(s) (default: print to stdout)
  • -c, --currency-column N - Align currencies at column N (default: auto-calculate optimal alignment)
  • -h, --help - Show help message

Examples

# Preview formatting changes
beancount-format my-ledger.beancount

# Apply formatting to multiple files
beancount-format -w income.beancount expenses.beancount

# Use custom currency column alignment
beancount-format --currency-column 60 ledger.beancount

Documentation

Full API documentation is available at https://Boelensman1.github.io/node-beancount/

Contributing

This project uses Make for task orchestration. Common commands:

# Install dependencies
make install

# Build the project
make build

# Run tests
make test

# Run linting (prettier, tsc, eslint, typedoc)
make lint

# Generate documentation
make docs

Requirements

  • Node.js >= 22

License

ISC