<commit_before>const _ = require('underscore');
const request = require('superagent');
const debug = require('debug');
const debugRequest = debug('leancloud:request');
const debugRequestError = debug('leancloud:request:error');
const Promise = require('../promise');

let requestsCount = 0;

const ajax = ({
  method,
  url,
  query,
  data,
  headers = {},
  onprogress,
  timeout,
}) => {
  const count = requestsCount++;

  debugRequest(`request(${count})`, method, url, query, data, headers);

  const flattenedQuery = {};
  if (query) {
    for (const k in query) {
      if (typeof query[k] === 'object') {
        flattenedQuery[k] = JSON.stringify(query[k]);
      } else {
        flattenedQuery[k] = query[k];
      }
    }
  }

  return new Promise((resolve, reject) => {
    const req = request(method, url)
      .set(headers)
      .query(flattenedQuery)
      .send(data);
    if (onprogress) {
      req.on('progress', onprogress);
    }
    if (timeout) {
      req.timeout(timeout);
    }
    req.end((err, res) => {
      if (err) {
        if (res) {
          if (!debug.enabled('leancloud:request')) {
            debugRequestError(
              `request(${count})`,
              method,
              url,
              query,
              data,
              headers
            );
          }
          debugRequestError(
            `response(${count})`,
            res.status,
            res.body || res.text,
            res.header
          );
          err.statusCode = res.status;
          err.responseText = res.text;
          err.response = res.body;
        }
        return reject(err);
      }
      debugRequest(
        `response(${count})`,
        res.status,
        res.body || res.text,
        res.header
      );
      return resolve(res.body);
    });
  });
};

// Helper function to check null or undefined.
const isNullOrUndefined = x => _.isNull(x) || _.isUndefined(x);

const ensureArray = target => {
  if (_.isArray(target)) {
    return target;
  }<commit_msg>refactor: pretty print debug info<commit_after>const _ = require('underscore');
const request = require('superagent');
const debug = require('debug');
const debugRequest = debug('leancloud:request');
const debugRequestError = debug('leancloud:request:error');
const Promise = require('../promise');

let requestsCount = 0;

const ajax = ({
  method,
  url,
  query,
  data,
  headers = {},
  onprogress,
  timeout,
}) => {
  const count = requestsCount++;

  debugRequest(
    'request(%d) %s %s %o %o %o',
    count,
    method,
    url,
    query,
    data,
    headers
  );

  const flattenedQuery = {};
  if (query) {
    for (const k in query) {
      if (typeof query[k] === 'object') {
        flattenedQuery[k] = JSON.stringify(query[k]);
      } else {
        flattenedQuery[k] = query[k];
      }
    }
  }

  return new Promise((resolve, reject) => {
    const req = request(method, url)
      .set(headers)
      .query(flattenedQuery)
      .send(data);
    if (onprogress) {
      req.on('progress', onprogress);
    }
    if (timeout) {
      req.timeout(timeout);
    }
    req.end((err, res) => {
      if (err) {
        if (res) {
          if (!debug.enabled('leancloud:request')) {
            debugRequestError(
              'request(%d) %s %s %o %o %o',
              count,
              method,
              url,
              query,
              data,
              headers
            );
          }
          debugRequestError(
            'response(%d) %d %O %o',
            count,
            res.status,
            res.body || res.text,
            res.header
          );
          err.statusCode = res.status;
          err.responseText = res.text;
          err.response = res.body;
        }
        return reject(err);
      }
      debugRequest(
        'response(%d) %d %O %o',
        count,
        res.status,
        res.body || res.text,
        res.header
      );
      return resolve(res.body);
    });
  });
};

// Helper function to check null or undefined.
const isNullOrUndefined = x => _.isNull(x) || _.isUndefined(x);

const ensureArray = target => {
  if (_.isArray(target)) {
    return target;
  }
{'fraction_non_alphanumeric': 0.14576352321685015, 'fraction_numerical': 0.0004786979415988511, 'mean_word_length': 1.8800827015851138, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '2926814', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1274, 'n_words': 285}