<commit_before>repl = require('repl')
net = require('net')
merge = require('merge')
cluster = require('cluster')
colors = require('colors')
terminal = require('terminal')
async = require('async')
EventEmitter = require('events').EventEmitter
MemoryStream = require('memorystream')
portscanner = require('portscanner')
ReplrClient = require('./ReplrClient')
ReplrEvents = require('./ReplrEvents')
Util = require('./Util')

class ReplrServer extends EventEmitter

  @::OPTIONS_DEFAULT = 
    name: 'Replr'
    port: 2323
    prompt: 'replr> '.grey
    terminal: false
    useColors: false
    describeWorker: null

  @::OPTIONS_REPL_KEYS = ['port', 'prompt', 'terminal', 'useColors']

  constructor: (options, start=true)->
    if options 
      if options.port
        if typeof options.port == 'number'
          throw new Error('bad port') if !Util::isInt(options.port) || options.port < 1
        else if typeof options.port != 'string'
          throw new Error('bad port')
      if options.prompt
        throw new Error('bad prompt') if typeof options.prompt != 'string'
      #todo: validate other options

    @options = merge @OPTIONS_DEFAULT, options
    @clients = []
    @started = false
    @starting = false
    return if start then @start() else @


  start: (callback)->
    return if @starting
    @starting = true

    onVerified = (err, status)=>
      if err || status == 'open'
        callback(err || new Error('Port already taken')) if callback
        return
    <commit_msg>Add useGlobal and ignoreUndefined to repl options<commit_after>repl = require('repl')
net = require('net')
merge = require('merge')
cluster = require('cluster')
colors = require('colors')
terminal = require('terminal')
async = require('async')
EventEmitter = require('events').EventEmitter
MemoryStream = require('memorystream')
portscanner = require('portscanner')
ReplrClient = require('./ReplrClient')
ReplrEvents = require('./ReplrEvents')
Util = require('./Util')

class ReplrServer extends EventEmitter

  @::OPTIONS_DEFAULT = 
    name: 'Replr'
    port: 2323
    prompt: 'replr> '.grey
    terminal: false
    useColors: false
    describeWorker: null

  @::OPTIONS_REPL_KEYS = ['port', 'prompt', 'terminal', 'useColors', 'useGlobal', 'ignoreUndefined']

  constructor: (options, start=true)->
    if options 
      if options.port
        if typeof options.port == 'number'
          throw new Error('bad port') if !Util::isInt(options.port) || options.port < 1
        else if typeof options.port != 'string'
          throw new Error('bad port')
      if options.prompt
        throw new Error('bad prompt') if typeof options.prompt != 'string'
      #todo: validate other options

    @options = merge @OPTIONS_DEFAULT, options
    @clients = []
    @started = false
    @starting = false
    return if start then @start() else @


  start: (callback)->
    return if @starting
    @starting = true

    onVerified = (err, status)=>
      if err || status == 'open'
        callback(err || new Error('Port already taken')) if callback
        return
    
{'fraction_non_alphanumeric': 0.1325065274151436, 'fraction_numerical': 0.0032637075718015664, 'mean_word_length': 3.422799422799423, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3790896', 'n_tokens_mistral': 917, 'n_tokens_neox': 878, 'n_words': 264}