<commit_before>/*
 * debugger.io: An interactive web scripting sandbox
 *
 * utils.js: utility functions
 */

define(['config', 'jquery', 'underscore'],
function(config, $, _) {
  'use strict';

  var utils = {};
  if (config.debug) { window.utils = utils; }

  /**
   * Log messages to console only in debug
   *
   * @param {Mixed} - messages to log
   */
  utils.log = function() {
    if (config.debug) {
      var args = _.toArray(arguments);
      args.unshift('==>');
      console.log.apply(console, args);
    }
  };

  /**
   * Ensure that a value is wrapped with jQuery
   *
   * @param {Mixed} value
   * @return {jQuery}
   */
  utils.ensure_jquery = function(value) {
    if (value instanceof $) { return value; }
    if ((value instanceof HTMLElement) || _.isArray(value)) { return $(value); }
    return $();
  };

  /**
   * Ensure that a value is an array
   *
   * @param {Mixed} value
   * @return {Array}
   */
  utils.ensure_array = function(value) {
    if (value === undefined || value === null) { return []; }
    return _.isArray(value) ? value : [value];
  };

  /**
   * New module is just an empty object, but attach it to the global window
   * object if config.debug is set
   *
   * @param {String} name - name of the module (only relevant to window)
   * @param {Object} [base] - base object to use
   * @return {Object} empty module object
   */
  utils.module = function(name, base) {
    var module = base || {};
    module.priv = module.priv || {};
    if (config.debug) { window[name] = module; }
    return module;
  };

  /**
   * Remove all double quotes (") from a string
   *
   * @param {String} str - input string
   * @return {String} input string with double quotes removed
   */
  utils.no_quotes = function(str) {
    return _.isString(str) ? str.replace(/\"/g, '') : '';
  };

  /**
   * Get an absolute URI on the debugger.io domain
   * TODO: if URI is already absolute, return the string unmodified
   *
   * @param {String} path - relative or absolute URI
   * @return {String} absolute URI<commit_msg>allow attaching modules to window without config.debug<commit_after>/*
 * debugger.io: An interactive web scripting sandbox
 *
 * utils.js: utility functions
 */

define(['config', 'jquery', 'underscore'],
function(config, $, _) {
  'use strict';

  var utils = {};
  if (config.debug) { window.utils = utils; }

  /**
   * Log messages to console only in debug
   *
   * @param {Mixed} - messages to log
   */
  utils.log = function() {
    if (config.debug) {
      var args = _.toArray(arguments);
      args.unshift('==>');
      console.log.apply(console, args);
    }
  };

  /**
   * Ensure that a value is wrapped with jQuery
   *
   * @param {Mixed} value
   * @return {jQuery}
   */
  utils.ensure_jquery = function(value) {
    if (value instanceof $) { return value; }
    if ((value instanceof HTMLElement) || _.isArray(value)) { return $(value); }
    return $();
  };

  /**
   * Ensure that a value is an array
   *
   * @param {Mixed} value
   * @return {Array}
   */
  utils.ensure_array = function(value) {
    if (value === undefined || value === null) { return []; }
    return _.isArray(value) ? value : [value];
  };

  /**
   * New module is just an empty object, but attach it to the global window
   * object if config.debug is set
   *
   * @param {String} name - name of the module (only relevant to window)
   * @param {Object} [base] - base object to use
   * @param {Boolean} [global] - if true, attach to global window object as well
   * @return {Object} empty module object
   */
  utils.module = function(name, base, global) {
    var module = base || {};
    module.priv = module.priv || {};

    if (global || (global === undefined && config.debug)) {
      window[name] = module;
    }

    return module;
  };

  /**
   * Remove all double quotes (") from a string
   *
   * @param {String} str - input string
   * @return {String} input string with double quotes removed
   */
  utils.no_quotes = function(str) {
    return _.isString(str) ? str.replace(/\"/g, '') : '';
  };

  /**
   * Get an absolute URI on the debugger.io domain
   * TODO: if URI is already absolute, return the string unmodified
   *
   * @param {String} path - relative or absolute URI
   * @return {String} absolute URI
{'fraction_non_alphanumeric': 0.14662004662004663, 'fraction_numerical': 0.0, 'mean_word_length': 2.689595872742906, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4509347', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1333, 'n_words': 433}