<commit_before>// @flow

import vm from 'vm';
import jsdom from 'jsdom';

/**
 * Runs code and returns the value of the last expression evaluated.
 */
export default (code: string, userOptions: Object = {}): any => {
  const window = jsdom.jsdom('<html><body></body></html>').defaultView;

  const sandbox = {
    document: window.document,
    require,
    window
  };

  const options = {
    displayErrors: true,
    timeout: 5000,
    ...userOptions
  };

  return vm.runInNewContext(code, sandbox, options);
};
<commit_msg>fix: expose console object to the VM<commit_after>// @flow

import vm from 'vm';
import jsdom from 'jsdom';

/**
 * Runs code and returns the value of the last expression evaluated.
 */
export default (code: string, userOptions: Object = {}): any => {
  const window = jsdom.jsdom('<html><body></body></html>').defaultView;

  const sandbox = {
    console,
    document: window.document,
    require,
    window
  };

  const options = {
    displayErrors: true,
    timeout: 5000,
    ...userOptions
  };

  return vm.runInNewContext(code, sandbox, options);
};

{'fraction_non_alphanumeric': 0.14102564102564102, 'fraction_numerical': 0.007326007326007326, 'mean_word_length': 3.3373015873015874, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '7286812', 'n_tokens_mistral': 348, 'n_tokens_neox': 333, 'n_words': 103}