beancount
    Preparing search index...

    Class ParseResult

    Container class for parsed Beancount entries. Provides methods for converting entries back to string format.

    Index

    Constructors

    Properties

    entries: Entry[]

    Array of parsed Entry objects

    Accessors

    Methods

    • Calculates the optimal currency column position for formatting.

      The currency column is determined by analyzing all postings across transactions and finding the maximum widths needed for account names and amounts.

      Formula: currencyColumn = maxLeftPartLength + maxAmountLength + minPadding + 6

      Where:

      • maxLeftPartLength = max((flag.length + 1 if flag) + account.length)
      • maxAmountLength = max(amount.length) for all postings with amounts
      • minPadding = desired minimum spaces between account and amount (default: 2)
      • 6 = fixed overhead (2 for indent + 2 for spacing + 2 for buffer)

      Parameters

      Returns number

      The calculated currency column position (1-indexed)

      const parseResult = parse(beancountString)
      const currencyColumn = parseResult.calculateCurrencyColumn()
      const formatted = parseResult.toFormattedString({ currencyColumn })
    • Converts all entries to a formatted string with aligned columns. Uses each entry's toFormattedString() method for consistent formatting.

      Parameters

      • formatOptions: FormatOptions = defaultFormatOptions

        Formatting options

      Returns string

      The formatted Beancount file content as a string

    • Converts all entries to their string representation. Each entry is converted using its toString() method and joined with newlines.

      Returns string

      The complete Beancount file content as a string

    • Creates an ParseResult instance from JSON data. Calls fromJSONData to allow subclasses to transform the data before construction.

      Parameters

      • jsonString: string

        JSON data representing an ParseResult

      Returns ParseResult

      A new instance of ParseResult loaded with the data in the JSON

      Warning: No validation is performed on the JSON input. We assume the JSON is valid and well-formed.

    • Creates a ParseResult instance from a plain JavaScript object. Deserializes each entry by mapping it to the appropriate Entry class based on its type.

      Parameters

      Returns ParseResult

      A new ParseResult instance with deserialized entries

      If an entry has an unknown type with no corresponding entry class

      Warning: No validation is performed on the input object. We assume the object is valid and well-formed.