<commit_before>/** @returns {Array|Object} */
function mewt(target) {
  const multiRet = 'push pop shift unshift'
  const mutArrMethods = 'reverse sort splice fill copyWithin'
  const nonMutArrMethods = 'filter map concat slice'
  
  const isA = Array.isArray(target)
  const clone = isA ? v => [].concat(v) : v => Object.assign({}, v)

  const override = prop => (...args) => {
    const mutMethod = mutArrMethods.includes(prop)
    const nonMutMethod = nonMutArrMethods.includes(prop)

    const cl = nonMutMethod ? target : clone(target)
    const res = cl[prop](...args)
    const wrappedRes = (mutMethod || nonMutMethod) ? mewt(res) : res
    
    return multiRet.includes(prop) ? [wrappedRes, mewt(cl)] : wrappedRes
  }

  const api = {
    $set: (prop, val) => {
      const newObj = clone(target)
      newObj[prop] = val
      return mewt(newObj)
    },
    $unset: prop => {
      const newObj = clone(target)
      delete newObj[prop]
      return mewt(newObj)
    }
  }

  if (!isA && typeof target !== 'object') {
    throw new Error('mewt accepts array or object')
  }

  return new Proxy(target, {
    set: () => {
      throw new Error(`${isA ? 'array' : 'object'} is immutable`)
    },
    get: (_, prop) => {
      if (api[prop]) {
        return api[prop]
      }
      return target[prop] && ({}.hasOwnProperty.call(target, prop) ? target[prop] : override(prop))
    }
  })
}

module.exports = mewt<commit_msg>Add space optimizations (#14)<commit_after>/** @returns {Array|Object} */
function mewt(target) {
  const multiRet = 'push pop shift unshift'
  const mutArrMethods = 'reverse sort splice fill copyWithin'
  const nonMutArrMethods = 'filter map concat slice'
  
  const isA = Array.isArray(target)
  const clone = isA ? v => [...v] : v => Object.assign({}, v)

  const override = prop => (...args) => {
    const mutMethod = mutArrMethods.includes(prop)
    const nonMutMethod = nonMutArrMethods.includes(prop)

    const cl = nonMutMethod ? target : clone(target)
    const res = cl[prop](...args)
    const wrappedRes = (mutMethod || nonMutMethod) ? mewt(res) : res
    
    return multiRet.includes(prop) ? [wrappedRes, mewt(cl)] : wrappedRes
  }

  const api = {
    $set (prop, val) {
      const newObj = clone(target)
      newObj[prop] = val
      return mewt(newObj)
    },
    $unset (prop) {
      const newObj = clone(target)
      delete newObj[prop]
      return mewt(newObj)
    }
  }

  if (!isA && typeof target !== 'object') {
    throw new Error('mewt accepts array or object')
  }

  return new Proxy(target, {
    set () {
      throw new Error(`${isA ? 'array' : 'object'} is immutable`)
    },
    get (_, prop) {
      return api[prop] || target[prop] && ({}.hasOwnProperty.call(target, prop) ? target[prop] : override(prop))
    }
  })
}

module.exports = mewt
{'fraction_non_alphanumeric': 0.14681834340561678, 'fraction_numerical': 0.0007109847138286527, 'mean_word_length': 2.930167597765363, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '5943616', 'n_tokens_mistral': 932, 'n_tokens_neox': 919, 'n_words': 243}