Function parseLedgerToCooked

  • Scans, lexes, and parses an HLedger journal file into a 'cooked' journal object format. This method produces a !.!Journal object containing the data from the journal source code in an organized format. All contextual information is 'baked in' to the data structure - e.g. inferred date years are expanded, default account names are inserted, etc.

    Example (ESModule)

    import { parseLedgerToCooked } from '@jones.tristand/hledger-parser'

    const parseResult = parseLedgerToCooked(sourceCode)
    console.log(`Lexing errors: ${parseResult.lexErrors.length}`);
    console.log(`Parsing errors: ${parseResult.parseErrors.length}`);
    console.log('Result:', parseResult.cookedJournal);

    // => Lexing errors: 0
    // => Parsing errors: 0
    // => Result: {
    // => transactions: [
    // => {
    // => date: [Object],
    // => status: 'unmarked',
    // => description: 'Transaction',
    // => postings: [Array],
    // => tags: []
    // => }
    // => ],
    // => accounts: [],
    // => prices: []
    // => }

    Example (CommonJS)

    const { parseLedgerToCooked } = require('@jones.tristand/hledger-parser');

    const parseResult = parseLedgerToRaw(sourceCode)
    console.log(`Lexing errors: ${parseResult.lexErrors.length}`);
    console.log(`Parsing errors: ${parseResult.parseErrors.length}`);
    console.log('Result:', parseResult.cookedJournal);

    // => Lexing errors: 0
    // => Parsing errors: 0
    // => Result: {
    // => transactions: [
    // => {
    // => date: [Object],
    // => status: 'unmarked',
    // => description: 'Transaction',
    // => postings: [Array],
    // => tags: []
    // => }
    // => ],
    // => accounts: [],
    // => prices: []
    // => }

    Parameters

    • source: string

      the source code of the journal to parse

    Returns CookedParseReturn

Generated using TypeDoc