<commit_before>// in console:
// eval(fs.readFileSync('../bootstrap.js', 'utf8'))

// in index.html:
// <script src="../../../../bootstrap.js" crossorigin></script>

const MOD_DIR = '../mods';

const fs = require('fs');
const path = require('path');

fs.readdirSync(MOD_DIR).forEach(modFile => {
  const script = fs.readFileSync(path.join(MOD_DIR, modFile), 'utf8');
  if (/MOD:UNSAFE/.test(script)) {
    eval(script);
  }
  else {
    const require = undefined;
    eval(script);
  }
})<commit_msg>Update bootstrap.js<commit_after>// in console:
// eval(fs.readFileSync('../bootstrap.js', 'utf8'))
// in index.html:
// <script src="../../../../bootstrap.js" crossorigin></script>

const MOD_DIR = '../mods';

const fs = require('fs');
const path = require('path');

const mods = {};

// When some condition is met, run some code. Ugly polling. Whatever.
mods.run = {
  log(...args) { console.log('[mods.run]', ...args); },
  timeoutId: null,
  tests: [],
  when(name, testFn, runFn) {
    this.tests.push({ name, testFn, runFn });
    this.log('register:', name);
    if (!this.timeoutId) {
      this.checkTests();
    }
  },
  checkTests() {
    this.log('check tests');
    const { tests } = this;
    for (let i = 0; i < tests.length; i++) {
      const { name, testFn, runFn } = tests[i];
      if (testFn()) {
        this.log('run:', name);
        runFn();
        tests.splice(i, 1);
        i--;
      }
    }
    if (tests.length > 0) {
      this.timeoutId = setTimeout(() => this.checkTests(), 30);
    }
    else {
      this.timeoutId = null;
    }
  },
};

// Load and eval each mod script.
fs.readdirSync(MOD_DIR).forEach(modFile => {
  const script = fs.readFileSync(path.join(MOD_DIR, modFile), 'utf8');
  if (/MOD:UNSAFE/.test(script)) {
    eval(script);
  }
  else {
    const require = undefined;
    eval(script);
  }
});
{'fraction_non_alphanumeric': 0.20790471034109367, 'fraction_numerical': 0.004872766648619383, 'mean_word_length': 2.7034068136272547, 'pattern_counts': {'":': 0, '<': 8, '<?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': '6226616', 'n_tokens_mistral': 654, 'n_tokens_neox': 643, 'n_words': 141}