beancount
    Preparing search index...

    Class ParseResult

    Container class for the result of a parse. Provides methods for converting node back to string format.

    Index

    Constructors

    Properties

    nodes: Node[]

    Array of parsed nodes

    Accessors

    • get accounts(): Set<string>

      Gets all unique account names used across all directives. Extracts accounts from transactions (via postings), open, close, balance, pad, note, and document nodes.

      Returns Set<string>

      Set of unique account names

    Methods

    • Gets all accounts that are active (open and not yet closed) at a given date. An account is considered active if:

      • It has an open directive with date <= the given date
      • It either has no close directive, or the close directive date > the given date

      Parameters

      • date: PlainDate

        The date to check account status for

      Returns Set<string>

      Set of account names that are active on the given date

    • 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 nodes to a formatted string with aligned columns. Uses each node's toFormattedString() method for consistent formatting.

      Parameters

      • formatOptions: FormatOptions = defaultFormatOptions

        Formatting options

      Returns string

      The formatted Beancount file content as a string

    • Converts all nodes to their string representation. Each node 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 node by mapping it to the appropriate Node class based on its type.

      Parameters

      Returns ParseResult

      A new ParseResult instance with deserialized nodes

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

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