code: function(conn, loggerOptions = {}) {
    EventEmitter.call(this);
  
    const consoleDecorator = function(arrow, data) {
      return console.log(arrow, JSON.stringify(data));
    };
    this.log = (loggerOptions.logger) ?
      loggerOptions.logger :
      consoleDecorator;
  
  
    this.debug = loggerOptions.debug;
    this.conn = conn;
    this.stream = new Readable(); 
    this.stream.setEncoding('utf8');
    this.stream.wrap(this.conn);
    this.state = state.init;
  
    this.msg = '';
    this.variables = {};
    this.pending = null;
  
    const self = this;
    this.stream.on('readable', function() {
      // always keep the 'leftover' part of the message
      self.msg = self.read();
    });
  
    this.stream.on('error', this.emit.bind(this, 'error'));
    this.stream.on('close', this.emit.bind(this, 'close'));
  }
docs: base context