<commit_before>
module.exports = (ctor) => {

  function oauth (options) {
    var oa = options.oauth || {}

    if (oa.consumer_key || ctor.key) {
      oa.consumer_key = oa.consumer_key || ctor.key
    }
    if (oa.consumer_secret || ctor.secret) {
      oa.consumer_secret = oa.consumer_secret || ctor.secret
    }

    if (oa.token) {
      oa.token = oa.token
    }
    if (oa.secret || oa.token_secret) {
      oa.token_secret = oa.secret || oa.token_secret
    }

    delete oa.secret

    // hackpad
    if (Object.keys(oa).length) {
      options.oauth = oa
    }
  }

  function parse (options) {
    if (options.parse === undefined) {
      options.parse = {json: true}
    }
    else if (options.parse.json === undefined) {
      options.parse.json = true
    }
  }

  function callback (callback) {
    return function (err, res, body) {
      if (err) {
        return callback(err, res, body)
      }

      // request doesn't support JSONP parsing
      if (typeof body === 'string' && body.trim()) {
        var type = res.headers['content-type']
        var encoding = res.headers['content-encoding']

        if (/json|javascript/.test(type) || /json/.test(encoding)) {
          // JSONP
          if (/[^(]+\(([\s\S]+)\)/.test(body)) {
            try {
              body = JSON.parse(body.replace(/[^(]+\(([\s\S]+)\)/, '$1'))
            }
            catch (e) {
              return callback(new Error('Purest: JSON parse error'), res, body)
            }
          }
        }
      }

      if (res.statusCode >= 400 && res.statusCode < 600) {
        return callback(body, res, body)
      }

      callback(err, res, body)
    }
  }

  return {oauth, parse, callback}
}<commit_msg>Minor refactoring for the transform module<commit_after>
module.exports = (ctor) => ({

  oauth: (options) => {
    var oa = options.oauth || {}

    if (oa.consumer_key || ctor.key) {
      oa.consumer_key = oa.consumer_key || ctor.key
    }
    if (oa.consumer_secret || ctor.secret) {
      oa.consumer_secret = oa.consumer_secret || ctor.secret
    }

    if (oa.token) {
      oa.token = oa.token
    }
    if (oa.secret || oa.token_secret) {
      oa.token_secret = oa.secret || oa.token_secret
    }

    delete oa.secret

    // hackpad
    if (Object.keys(oa).length) {
      options.oauth = oa
    }
  },

  parse: (options) => {
    if (options.parse === undefined) {
      options.parse = {json: true}
    }
    else if (options.parse.json === undefined) {
      options.parse.json = true
    }
  },

  callback: (callback) => (err, res, body) => {
    if (err) {
      return callback(err, res, body)
    }

    // request doesn't support JSONP parsing
    if (typeof body === 'string' && body.trim()) {
      var type = res.headers['content-type']
      var encoding = res.headers['content-encoding']

      if (/json|javascript/.test(type) || /json/.test(encoding)) {
        // JSONP
        if (/[^(]+\(([\s\S]+)\)/.test(body)) {
          try {
            body = JSON.parse(body.replace(/[^(]+\(([\s\S]+)\)/, '$1'))
          }
          catch (e) {
            return callback(new Error('Purest: JSON parse error'), res, body)
          }
        }
      }
    }

    if (res.statusCode >= 400 && res.statusCode < 600) {
      return callback(body, res, body)
    }

    callback(err, res, body)
  }
})
{'fraction_non_alphanumeric': 0.16656662665066027, 'fraction_numerical': 0.004201680672268907, 'mean_word_length': 1.928822495606327, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '7413742', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1100, 'n_words': 234}