<commit_before>(function (window) {
  function ajax(method, url, body, callback) {

    return new Promise(function (resolve, reject) {

      var httpRequest;
      if (window.XMLHttpRequest)
        httpRequest = new XMLHttpRequest();
      else
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
      httpRequest.onreadystatechange = function () {

        if (httpRequest.readyState === XMLHttpRequest.DONE) {
          var response = JSON.parse(httpRequest.responseText);
          if (httpRequest.status === 200) {
            if (callback)
              callback(null, response);
            return resolve(response);
          } else {
            if (callback)
              callback(response, null);
            return reject(response);
          }
        }
      }
      httpRequest.open(method.toUpperCase(), url);
      httpRequest.setRequestHeader('Content-Type', 'application/json');
      httpRequest.setRequestHeader('Accept', 'application/json');
      httpRequest.setRequestHeader('Cache-Control', 'no-cache');
      httpRequest.send(JSON.stringify(body));
    })
  }

  window.api = {
    list: function (prefix, start, length, sort, descending, searchTerm) {
      var q = '/list';
      q += '?start=' + start;
      q += '&length=' + length;
      q += '&sort=' + sort;
      q += '&desc=' + ((descending === true || descending === 'true') ? 'true' : 'false');
      if (searchTerm)
        q += '&term=' + searchTerm;

      return ajax('GET', prefix + q);
    },
    get: function (prefix, id) {
      return ajax('GET', prefix + '/' + id);
    },
    create: function (prefix, item) {
      return ajax('POST', prefix + '/', item);
    },
    update: function (prefix, item) {
      return ajax('PUT', prefix + '/' + item._id, item);
    },
    destroy: function (prefix, item) {
      return ajax('DELETE', prefix + '/' + item._id);
    }
  };
})(window);<commit_msg>Add api.action call, and add flash() method for font end<commit_after>(function (window) {
  function ajax(method, url, body, callback) {

    return new Promise(function (resolve, reject) {

      var httpRequest;
      if (window.XMLHttpRequest)
        httpRequest = new XMLHttpRequest();
      else
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
      httpRequest.onreadystatechange = function () {

        if (httpRequest.readyState === XMLHttpRequest.DONE) {
          var response = JSON.parse(httpRequest.responseText);
          if (httpRequest.status === 200) {
            if (callback)
              callback(null, response);
            return resolve(response);
          } else {
            if (callback)
              callback(response, null);
            return reject(response);
          }
        }
      }
      httpRequest.open(method.toUpperCase(), url);
      httpRequest.setRequestHeader('Content-Type', 'application/json');
      httpRequest.setRequestHeader('Accept', 'application/json');
      httpRequest.setRequestHeader('Cache-Control', 'no-cache');
      httpRequest.send(JSON.stringify(body));
    })
  }

  window.api = {
    list: function (prefix, start, length, sort, descending, searchTerm) {
      var q = '/list';
      q += '?start=' + start;
      q += '&length=' + length;
      q += '&sort=' + sort;
      q += '&desc=' + ((descending === true || descending === 'true') ? 'true' : 'false');
      if (searchTerm)
        q += '&term=' + searchTerm;

      return ajax('GET', prefix + q);
    },
    get: function (prefix, id) {
      return ajax('GET', prefix + '/' + id);
    },
    create: function (prefix, item) {
      return ajax('POST', prefix + '/', item);
    },
    update: function (prefix, item) {
      return ajax('PUT', prefix + '/' + item._id, item);
    },
    destroy: function (prefix, item) {
      return ajax('DELETE', prefix + '/' + item._id);
    },
    action: function (prefix, actionType, ids) {
      var body = {
        action: actionType,
        _id: ids
      };
      return ajax('POST', prefix + '/action', body);
    },
  };

  window.flash = function (type, message) {
    if (type === 'error')
      type = 'danger';
    $('#flash-container').append('<div class="alert alert-' + 
      type + 
      ' alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' + 
      message + 
      '</div>');
  }
})(window);
{'fraction_non_alphanumeric': 0.16183793571751923, 'fraction_numerical': 0.001358080579447714, 'mean_word_length': 2.441588785046729, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '293024', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1251, 'n_words': 302}