peberminta - v0.10.0
    Preparing search index...

    Function tryParse

    • Utility function that provides a bit cleaner interface for running a parser over a string. Returns undefined in case parser did not match.

      Input string is broken down to characters as [...str] unless you provide a pre-split array.

      Note: this doesn't capture errors thrown during parsing. Nonmatch is considered a part or normal flow. Errors mean unrecoverable state and it's up to client code to decide where to throw errors and how to get back to safe state.

      Type Parameters

      • TOptions
      • TValue

      Parameters

      • parser: Parser<string, TOptions, TValue>

        A parser to run.

      • str: string | string[]

        Input string or an array of graphemes.

      • options: TOptions

        Parser options.

      Returns undefined | TValue

      A matched value or undefined in case of nonmatch.