<commit_before>module.exports = AlgoliaSearch;

/*
 * Algolia Search library initialization
 * https://www.algolia.com/
 *
 * @param {string} applicationID - Your applicationID, found in your dashboard
 * @param {string} apiKey - Your API key, found in your dashboard
 * @param {Object} [opts]
 * @param {number} [opts.timeout=2000] - The request timeout set in milliseconds, another request will be issued after this timeout
 * @param {string} [opts.protocol='http:'] - The protocol used to query Algolia Search API.
 *                                        Set to 'https:' to force using https. Default to document.location.protocol in browsers
 * @param {string[]} [opts.hosts=[
 *          this.applicationID + '-1.algolia.' + opts.tld,
 *          this.applicationID + '-2.algolia.' + opts.tld,
 *          this.applicationID + '-3.algolia.' + opts.tld]
 *        ] - The hosts to use for Algolia Search API. It this your responsibility to shuffle the hosts and add a DSN host in it
 * @param {string} [opts.tld='net'] - The tld to use when computing hosts default list
 */
function AlgoliaSearch(applicationID, apiKey, opts, _request) {
  var usage = 'Usage: algoliasearch(applicationID, apiKey, opts)';

  if (!applicationID) {
    throw new Error('Please provide an application ID. ' + usage);
  }

  if (!apiKey) {
    throw new Error('Please provide an API key. ' + usage);
  }

  opts = opts || {};

  // now setting default options
  // could not find a tiny module to do that, let's go manual
  if (opts.timeout === undefined) {
    opts.timeout = 2000;
  }

  if (opts.protocol === undefined) {
    var locationProtocol = document && document.location.protocol;
    opts.protocol = (locationProtocol === 'http:' || locationProtocol === 'https:') ? locationProtocol : 'http:';
  }

  if (opts.hosts === undefined) {
    opts.hosts = []; // filled later on, has dependencies
  }

  if (opts.tld === undefined) {
    opts.tld = 'net';
  }

  // while we advocate for colon-at-the-end values: 'http:' for `opts.protocol`
  // we also accept `http` and `https`. It's a common error.
  if (!/:$/.test(opts.protocol)) {
    opts.protocol = opts.protocol + ':';
  }

  // no hosts given, add defaults
  if (opts.hosts.length === 0) {
    opts.hosts = shuffle([
      applicationID + '-1.algolia.' + opts.tld,
      applicationID + '-2.algolia.' + opts.tld,
      applicationID + '-3.algolia.' + opts.tld
    ]);

    // add default dsn host
    opts.hosts.unshift(applicationID + '-dsn.algolia.' + opts.tld);
  }<commit_msg>add small comment around protocol<commit_after>module.exports = AlgoliaSearch;

/*
 * Algolia Search library initialization
 * https://www.algolia.com/
 *
 * @param {string} applicationID - Your applicationID, found in your dashboard
 * @param {string} apiKey - Your API key, found in your dashboard
 * @param {Object} [opts]
 * @param {number} [opts.timeout=2000] - The request timeout set in milliseconds, another request will be issued after this timeout
 * @param {string} [opts.protocol='http:'] - The protocol used to query Algolia Search API.
 *                                        Set to 'https:' to force using https. Default to document.location.protocol in browsers
 * @param {string[]} [opts.hosts=[
 *          this.applicationID + '-1.algolia.' + opts.tld,
 *          this.applicationID + '-2.algolia.' + opts.tld,
 *          this.applicationID + '-3.algolia.' + opts.tld]
 *        ] - The hosts to use for Algolia Search API. It this your responsibility to shuffle the hosts and add a DSN host in it
 * @param {string} [opts.tld='net'] - The tld to use when computing hosts default list
 */
function AlgoliaSearch(applicationID, apiKey, opts, _request) {
  var usage = 'Usage: algoliasearch(applicationID, apiKey, opts)';

  if (!applicationID) {
    throw new Error('Please provide an application ID. ' + usage);
  }

  if (!apiKey) {
    throw new Error('Please provide an API key. ' + usage);
  }

  opts = opts || {};

  // now setting default options
  // could not find a tiny module to do that, let's go manual
  if (opts.timeout === undefined) {
    opts.timeout = 2000;
  }

  if (opts.protocol === undefined) {
    var locationProtocol = document && document.location.protocol;
    // our API is only available with http or https. When in file:// mode (local html file), default to http
    opts.protocol = (locationProtocol === 'http:' || locationProtocol === 'https:') ? locationProtocol : 'http:';
  }

  if (opts.hosts === undefined) {
    opts.hosts = []; // filled later on, has dependencies
  }

  if (opts.tld === undefined) {
    opts.tld = 'net';
  }

  // while we advocate for colon-at-the-end values: 'http:' for `opts.protocol`
  // we also accept `http` and `https`. It's a common error.
  if (!/:$/.test(opts.protocol)) {
    opts.protocol = opts.protocol + ':';
  }

  // no hosts given, add defaults
  if (opts.hosts.length === 0) {
    opts.hosts = shuffle([
      applicationID + '-1.algolia.' + opts.tld,
      applicationID + '-2.algolia.' + opts.tld,
      applicationID + '-3.algolia.' + opts.tld
    ]);

    // add default dsn host
    opts.hosts.unshift(applicationID + '-dsn.algolia.' + opts.tld);
  }
{'fraction_non_alphanumeric': 0.13889424003082257, 'fraction_numerical': 0.005779233288383741, 'mean_word_length': 2.9037593984962404, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4698928', 'n_tokens_mistral': 1593, 'n_tokens_neox': 1525, 'n_words': 517}