<commit_before>var gamejs = require('gamejs');
var uri = require('gamejs/utils/uri');

/**
 * @fileoverview
 * Workers are useful to relieve your GameJs application from code which
 * might take long to run. Either expensive algorithms, which might get called
 * every now and then (e.g., path-finding) or another logic being run continously
 * within the rendering loop (e.g., physics engine).
 *
 * A Worker is like a seperate GameJs application being executed - another `main.js`
 * with its own `gamejs.ready()`. The Worker's most important feature is that
 * code executing within it does not block the rendering code. The Worker's
 * greatest limitation is that you can only communicate with it through text
 * messages.
 *
 * See the `examples/workers` directory for a running example.
 *
 * @example
 *  // Create a worker with the main module "./test"
 *  var fooWorker = new Worker('./test');
 *  // Send a message to your worker.
 *  // The Message doesn't have to be a string but it must be `JSON.stringify()`-able
 *  fooWorker.post("foobar");
 *
 *  // The result of the worker will be accessible
 *  // in the main application via the gamejs.event queue
 *  if (event.type === gamejs.event.WORKER_RESULT) {
 *     gamejs.log('Worker #' + event.worker.id + ' returned ' + event.data);
 *  }
 *
 *  // In the worker module, we can send results back to the main application
 *  // by posting them to the gamejs event queue as type `gamejs.event.WORKER_RESULT`
 *  gamejs.event.post({
 *     type: gamejs.event.WORKER_RESULT,
 *     data: "zarzar"
 *  });
 *
 */

/**
 * true if this GameJs instance is being executed within a WebWorker
 * @type Boolean
 */
exports.inWorker = (this.importScripts !== undefined);

/**
 * Executed in scope of worker after user's main module
 * @ignore
 */
exports._ready = function () {
   var gamejs = require('gamejs');
   self.onmessage = function(event) {
      gamejs.event.post(event.data)
   };
   self.postMessage({
      type: gamejs.event.WORKER_ALIVE
   });
};

/**
 * Send message to main context for logging
 * @ignore
 **/
exports._logMessage = function(arguments) {
   self.postMessage({
      type: gamejs.event.WORKER_LOGMESSAGE,
      arguments: Array.prototype.slice.apply(arguments)
   });
};

/**
 * Send result message to main context
 * @ignore
 */
exports._messageMain = function(event) {
   self.postMessage({
      type: gamejs.event.WORKER_RESULT,
      data: event.data
   });
};

/**
  * executed in scope of worker before user's main module
  * @ignore
  */
var workerPrefix = function workerPrefix() {
   __scripts.forEach(function(script) {
      try {
         importScripts(script)
      } catch (e) {
         // can't help the worker
      }
   });
};

/**
 * Setup a worker which has `require()` defined
 * @ignore
 **/
var create = function(workerModuleId) {
   var moduleRoot = uri.resolve(document.location.href, window.require.getModuleRoot());
   var initialScripts = [];
   Array.prototype.slice.apply(document.getElementsByTagName('script'), [0]).forEach(function(script) {
      if (script.src) {
         initialScripts.push(script.src);
      }
   });

   var URL = window.URL || window.webkitURL;
   var prefixString = workerPrefix.toString();
   // don't be afraid...
   prefixString = prefixString.substring(prefixString.indexOf("{") + 1, prefixString.lastIndexOf("}"));
   var blob = new Blob([
      'var __scripts = ["' + initialScripts.join('","') + '"];',
      prefixString,
      'self.require.setModuleRoot("' + moduleRoot + '");',
      'self.require.run("'+ workerModuleId +'");'
   ]);

   var blobURL = URL.createObjectURL(blob);<commit_msg>create worker blog as type "application/javascript"<commit_after>var gamejs = require('gamejs');
var uri = require('gamejs/utils/uri');

/**
 * @fileoverview
 * Workers are useful to relieve your GameJs application from code which
 * might take long to run. Either expensive algorithms, which might get called
 * every now and then (e.g., path-finding) or another logic being run continously
 * within the rendering loop (e.g., physics engine).
 *
 * A Worker is like a seperate GameJs application being executed - another `main.js`
 * with its own `gamejs.ready()`. The Worker's most important feature is that
 * code executing within it does not block the rendering code. The Worker's
 * greatest limitation is that you can only communicate with it through text
 * messages.
 *
 * See the `examples/workers` directory for a running example.
 *
 * @example
 *  // Create a worker with the main module "./test"
 *  var fooWorker = new Worker('./test');
 *  // Send a message to your worker.
 *  // The Message doesn't have to be a string but it must be `JSON.stringify()`-able
 *  fooWorker.post("foobar");
 *
 *  // The result of the worker will be accessible
 *  // in the main application via the gamejs.event queue
 *  if (event.type === gamejs.event.WORKER_RESULT) {
 *     gamejs.log('Worker #' + event.worker.id + ' returned ' + event.data);
 *  }
 *
 *  // In the worker module, we can send results back to the main application
 *  // by posting them to the gamejs event queue as type `gamejs.event.WORKER_RESULT`
 *  gamejs.event.post({
 *     type: gamejs.event.WORKER_RESULT,
 *     data: "zarzar"
 *  });
 *
 */

/**
 * true if this GameJs instance is being executed within a WebWorker
 * @type Boolean
 */
exports.inWorker = (this.importScripts !== undefined);

/**
 * Executed in scope of worker after user's main module
 * @ignore
 */
exports._ready = function () {
   var gamejs = require('gamejs');
   self.onmessage = function(event) {
      gamejs.event.post(event.data)
   };
   self.postMessage({
      type: gamejs.event.WORKER_ALIVE
   });
};

/**
 * Send message to main context for logging
 * @ignore
 **/
exports._logMessage = function(arguments) {
   self.postMessage({
      type: gamejs.event.WORKER_LOGMESSAGE,
      arguments: Array.prototype.slice.apply(arguments)
   });
};

/**
 * Send result message to main context
 * @ignore
 */
exports._messageMain = function(event) {
   self.postMessage({
      type: gamejs.event.WORKER_RESULT,
      data: event.data
   });
};

/**
  * executed in scope of worker before user's main module
  * @ignore
  */
var workerPrefix = function workerPrefix() {
   __scripts.forEach(function(script) {
      try {
         importScripts(script)
      } catch (e) {
         // can't help the worker
      }
   });
};

/**
 * Setup a worker which has `require()` defined
 * @ignore
 **/
var create = function(workerModuleId) {
   var moduleRoot = uri.resolve(document.location.href, window.require.getModuleRoot());
   var initialScripts = [];
   Array.prototype.slice.apply(document.getElementsByTagName('script'), [0]).forEach(function(script) {
      if (script.src) {
         initialScripts.push(script.src);
      }
   });

   var URL = window.URL || window.webkitURL;
   var prefixString = workerPrefix.toString();
   // don't be afraid...
   prefixString = prefixString.substring(prefixString.indexOf("{") + 1, prefixString.lastIndexOf("}"));
   var blob = new Blob([
      'var __scripts = ["' + initialScripts.join('","') + '"];',
      prefixString,
      'self.require.setModuleRoot("' + moduleRoot + '");',
      'self.require.run("'+ workerModuleId +'");'
   ], {type: 'application\/javascript'});

   var blobURL = URL.createObjectURL(blob);
{'fraction_non_alphanumeric': 0.13397583819736664, 'fraction_numerical': 0.0005429618569295507, 'mean_word_length': 3.2515868436237736, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1417046', 'n_tokens_mistral': 2199, 'n_tokens_neox': 2158, 'n_words': 666}