<commit_before>/*!
 * try-catch-core <https://github.com/tunnckoCore/try-catch-core>
 *
 * Copyright (c) 2016 <NAME> <@tunnckoCore> (http://www.tunnckocore.tk)
 * Released under the MIT license.
 */

'use strict'

var utils = require('./utils')

module.exports = function tryCatchCore (fn, cb) {
  if (typeof fn !== 'function') {
    throw new TypeError('try-catch-core: expect `fn` to be a function')
  }
  if (typeof cb !== 'function') {
    return function thunk (done) {
      tryCatchCore(fn, done)
    }
  }
  if (utils.isAsync(fn)) {
    fn(utils.once(utils.dezalgo(cb)))
    return
  }

  var ret = null
  cb = utils.once(cb)

  try {
    ret = fn(cb)
  } catch (err) {
    if (!cb.called) return cb(err)
  }

  if (!cb.called) return cb(null, ret)
}<commit_msg>chore(index.js): fix complexity<commit_after>/*!
 * try-catch-core <https://github.com/tunnckoCore/try-catch-core>
 *
 * Copyright (c) 2016 <NAME> <@tunnckoCore> (http://www.tunnckocore.tk)
 * Released under the MIT license.
 */

'use strict'

var utils = require('./utils')

module.exports = function tryCatchCore (fn, cb) {
  if (typeof fn !== 'function') {
    throw new TypeError('try-catch-core: expect `fn` to be a function')
  }
  if (typeof cb !== 'function') {
    return function thunk (done) {
      tryCatch(fn, done)
    }
  }
  tryCatch(fn, cb)
}

function tryCatch (fn, cb) {
  if (utils.isAsync(fn)) {
    fn(utils.once(utils.dezalgo(cb)))
    return
  }

  var ret = null
  cb = utils.once(cb)

  try {
    ret = fn(cb)
  } catch (err) {
    if (!cb.called) return cb(err)
  }

  if (!cb.called) return cb(null, ret)
}
{'fraction_non_alphanumeric': 0.1707165109034268, 'fraction_numerical': 0.004984423676012461, 'mean_word_length': 3.045340050377834, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '840214', 'n_tokens_mistral': 624, 'n_tokens_neox': 606, 'n_words': 148}