<commit_before>(function (window) {

  // jQuery alias
  var $ = window.$;

  // create our class
  var BatchSync = function (func) {
    this.requests = [];
  };

  // add our class to the global namespace
  window.BatchSync = BatchSync;

  // our methods
  _.extend(BatchSync.prototype, {

    // method for adding requests to the batch
    add: function (func) {
      // set global _batch variable in jQuery.ajaxSettings
      $.ajaxSettings._batch = this;

      // call the user's function
      func.call(this);
      
      // remove the global _batch variable
      delete $.ajaxSettings._batch;

      return this;
    },

    // method for running the batch request
    sync: function (options) {
      var instance = this;

      // map an array of requests
      var requests = _.map(this.requests, function (data, i) {
        return data.request;
      });

      // setup our base options
      options = _.extend({
        url: '/_bulk',
        type: 'POST',
        data: requests,
        contentType: 'application/json',
        processData: false,
        dataType: 'text'
      }, options);

      // extend the success option
      var success = options.success;
      options.success = function (data, status, xhr) {
        // call our _deliver method to handle each individual batch request response
        instance._deliver.call(instance, data, status, xhr);
        
        // user's success function
        if (success) {
          success(data, status, xhr);
        }
      };

      // call the request
      return $.ajax(options);
    },

    // private method to add a request to the batch requests array
    _addRequest: function (xhr, settings) {
      // create data object
      var data = {
        xhr: xhr,
        settings: settings,
        request: {
          method: settings.type,
          path: settings.url,
          headers: {},
          body: settings.data
        }
      };

      // extract query params
      var queryparams = this._extractParams(settings.url);

      if (queryparams) {
        // remove query params from url
        data.request.path = settings.url.replace('?' + queryparams, '');<commit_msg>Allow options to be passed on instantiation<commit_after>(function (window) {

  // jQuery alias
  var $ = window.$;

  // create our class
  var BatchSync = function (options) {
    // default options
    this.options = $.extend({
      url: '/_bulk',
      type: 'POST',
      contentType: 'application/json',
      processData: false,
      dataType: 'text'
    }, options);

    // requests storage
    this.requests = [];
    
    return this;
  };

  // add our class to the global namespace
  window.BatchSync = BatchSync;

  // our methods
  _.extend(BatchSync.prototype, {

    // method for adding requests to the batch
    add: function (func) {
      // set global _batch variable in jQuery.ajaxSettings
      $.ajaxSettings._batch = this;

      // call the user's function
      func.call(this);
      
      // remove the global _batch variable
      delete $.ajaxSettings._batch;

      return this;
    },

    // method for running the batch request
    sync: function (options) {
      var instance = this;

      // map an array of requests
      var requests = _.map(this.requests, function (data, i) {
        return data.request;
      });

      // set options
      $.extend(this.options, { data: requests }, options);

      // extend the success option
      var success = this.options.success;
      this.options.success = function (data, status, xhr) {
        // call our _deliver method to handle each individual batch request response
        instance._deliver.call(instance, data, status, xhr);
        
        // user's success function
        if (success) {
          success(data, status, xhr);
        }
      };

      // call the request
      return $.ajax(this.options);
    },

    // private method to add a request to the batch requests array
    _addRequest: function (xhr, settings) {
      // create data object
      var data = {
        xhr: xhr,
        settings: settings,
        request: {
          method: settings.type,
          path: settings.url,
          headers: {},
          body: settings.data
        }
      };

      // extract query params
      var queryparams = this._extractParams(settings.url);

      if (queryparams) {
        // remove query params from url
        data.request.path = settings.url.replace('?' + queryparams, '');
{'fraction_non_alphanumeric': 0.10640196297122463, 'fraction_numerical': 0.0, 'mean_word_length': 1.9288047028086217, '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': '3567151', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1184, 'n_words': 392}