Documentation
    Preparing search index...

    A REPL (Read-Eval-Print Loop) server implementation that provides an interactive command line interface for executing JavaScript/TypeScript code with custom methods and context management.

    const repl = new Repl({ historyFilePath: '.repl_history' })

    repl.addMethod('greet', (repl, name) => `Hello ${name}!`, {
    description: 'Greets a person',
    usage: 'greet (name)'
    })

    repl.start({ myVar: 'Hello World' })
    Index

    Constructors

    • Creates a new REPL instance with optional configuration

      Parameters

      • Optionaloptions: { compiler?: Compiler; historyFilePath?: string } & ReplOptions

        Configuration options for the REPL

        • Optionalcompiler?: Compiler

          Custom compiler for transforming user input

        • OptionalhistoryFilePath?: string

          Path to store command history

        • compiler

          Custom compiler for transforming user input

        • historyFilePath

          Path to store command history

      Returns Repl

      const repl = new Repl({
      historyFilePath: '.repl_history',
      compiler: myTypeScriptCompiler
      })

    Properties

    colors: Colors = ...

    Colors reference

    server?: REPLServer

    Reference to the repl server. Available after the start method is invoked

    Methods

    • Notify by writing to the console

      Parameters

      • message: string

        The message to display

      Returns void

      repl.notify('Server connected successfully')
      
    • Register a callback to be invoked once the server is ready

      Parameters

      • callback: (repl: Repl) => void

        Function to call when the REPL is ready

      Returns this

      repl.ready((repl) => {
      repl.notify('REPL is ready!')
      })
    • Register a custom loader function to be added to the context

      Parameters

      • name: string

        The name of the method

      • handler: MethodCallback

        The function to execute

      • Optionaloptions: MethodOptions

        Optional configuration for the method

      Returns this

      repl.addMethod('greet', (repl, name) => {
      return `Hello ${name}!`
      }, {
      description: 'Greets a person by name',
      usage: 'greet (name)'
      })
    • Returns the collection of registered methods

      Returns {
          [name: string]: {
              handler: MethodCallback;
              options: MethodOptions & { width: number };
          };
      }

      const methods = repl.getMethods()
      console.log(Object.keys(methods)) // ['clear', 'p', 'myCustomMethod']
    • Register a compiler. Make sure register the compiler before calling the start method

      Parameters

      • compiler: Compiler

        The compiler instance to use for transforming code

      Returns this

      const tsCompiler = {
      compile: (code, filename) => ts.transpile(code),
      supportsTypescript: true
      }
      repl.useCompiler(tsCompiler)
    • Start the REPL server

      Parameters

      • Optionalcontext: Record<string, any>

        Optional initial context to populate the REPL with

      Returns Repl

      repl.start({
      db: databaseConnection,
      utils: myUtilities
      })