<commit_before>/* global ActiveXObject */

import http from './wrapper';

var RE_contentType = /([^\/]+)\/([^+]+\+)?([^;]*)/;
function parseContentType(contentType) {
  var matches = contentType && contentType.match(RE_contentType);
  return matches ? matches[3] : 'text';
}

function headerToCamelCase(text) {
  var key = text[0].toLowerCase() + text.substr(1);
  return key.replace(/([a-z])-([a-zA-Z])/g, function (match, lower, upper) {
    return lower + upper.toUpperCase();
  });
}

var useRequest = http.useRequest,
    requests = {
      fetch: function () {

        function getFetchResponse (response, config) {
          var headers = {},
              iterator = response.headers.entries(),
              entry = iterator.next();

          while( entry && !entry.done ) {
            headers[headerToCamelCase(entry.value[0])] = entry.value[1];
            entry = iterator.next();
          }

          var type = parseContentType(headers.contentType);

          return ( response[config.format || type] ? response[config.format || type]() : response.text() ).then(function (data) {
            return {
              config: config,
              status: response.status,
              statusText: response.statusText,
              data: data,
              headers: headers,
            };
          });
        }

        function fetchRequest (config, resolve, reject) {
          var options = { headers: new Headers(config.headers), redirect: 'follow', credentials: 'same-origin' };
          if( config.withCredentials ) options.credentials = 'include';
          if( config.credentials ) options.credentials = config.credentials;

          fetch(config.url, options).then(function (response) {
            getFetchResponse(response, config).then(response.ok ? resolve : reject);
          }, function (response) {
            getFetchResponse(response, config).then(reject);
          });<commit_msg>tweaks on method functions<commit_after>/* global ActiveXObject */

import http from './wrapper';

var RE_contentType = /([^\/]+)\/([^+]+\+)?([^;]*)/;
function parseContentType(contentType) {
  var matches = contentType && contentType.match(RE_contentType);
  return matches ? matches[3] : 'text';
}

function headerToCamelCase(text) {
  var key = text[0].toLowerCase() + text.substr(1);
  return key.replace(/([a-z])-([a-zA-Z])/g, function (match, lower, upper) {
    return lower + upper.toUpperCase();
  });
}

var useRequest = http.useRequest,
    requests = {
      fetch: function () {

        function getFetchResponse (response, config) {
          var headers = {},
              iterator = response.headers.entries(),
              entry = iterator.next();

          while( entry && !entry.done ) {
            headers[headerToCamelCase(entry.value[0])] = entry.value[1];
            entry = iterator.next();
          }

          var type = parseContentType(headers.contentType);

          return ( response[config.format || type] ? response[config.format || type]() : response.text() ).then(function (data) {
            return {
              config: config,
              status: response.status,
              statusText: response.statusText,
              data: data,
              headers: headers,
            };
          });
        }

        function fetchRequest (config, resolve, reject) {
          var options = {
            method: config.method || 'GET',
            headers: new Headers(config.headers),
            redirect: 'follow', credentials: 'same-origin'
          };
          if( config.withCredentials ) options.credentials = 'include';
          if( config.credentials ) options.credentials = config.credentials;

          fetch(config.url, options).then(function (response) {
            getFetchResponse(response, config).then(response.ok ? resolve : reject);
          }, function (response) {
            getFetchResponse(response, config).then(reject);
          });
{'fraction_non_alphanumeric': 0.14271229404309252, 'fraction_numerical': 0.0025348542458808617, 'mean_word_length': 2.329957805907173, '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': '6845136', 'n_tokens_mistral': 1067, 'n_tokens_neox': 1058, 'n_words': 230}