Function parseLedgerToRaw

  • Scans, lexes, and parses an HLedger journal file into a 'raw' journal object format. This method produces an ordered list of !.!JournalItems that represents the provided ledger journal source. Order is preserved in the raw format so that information such as default account or year directives can be preserved.

    A 'raw' journal object can be translated into a 'cooked' journal object using the rawToCookedLedger method.

    Example (ESModule)

    import { parseLedgerToRaw } from '@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.rawJournal);

    // => Lexing errors: 0
    // => Parsing errors: 0
    // => Result: [
    // => {
    // => type: 'transaction',
    // => value: {
    // => date: '2020/01/01',
    // => description: 'Transaction',
    // => status: 'unmarked',
    // => contentLines: [Array]
    // => }
    // => }
    // => ]

    Example (CommonJS)

    const { parseLedgerToRaw } = 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.rawJournal);

    // => Lexing errors: 0
    // => Parsing errors: 0
    // => Result: [
    // => {
    // => type: 'transaction',
    // => value: {
    // => date: '2020/01/01',
    // => description: 'Transaction',
    // => status: 'unmarked',
    // => contentLines: [Array]
    // => }
    // => }
    // => ]

    Parameters

    • source: string

      the source code of the journal to parse

    Returns RawParseReturn

Generated using TypeDoc