<commit_before>/**
 *
 * Helpers
 *
 * Copyright 2019, Author Name
 * Some information on the license.
 *
**/

;(function(Helpers, window) 
{

  /**
   * Customised and cross browser window.Helpers.log.
   *
   * @since 1.0.0
   * @version 1.0.0
  **/
  Helpers.log = function(message, type, alertlog) 
  {
    // Guard :: Check environment.
    if ((window.config && window.config.env === 'production')) {
      return
    }

    alertlog = (typeof alertlog === 'undefined')
    if (typeof console === 'undefined' || typeof console.log === 'undefined') {
      if (alertlog) {
        window.alert(message)
      }
    } else {
      var color = (type === 'positive') ? '#097809' : (type === 'negative') ? '#c5211d' : (typeof type !== 'undefined') ? type : '#240ad0'
      console.log('%c-- DEBUG ---------------------------------------------------------', 'color:' + color + ';font-weight:bold;')
      if (message instanceof Array || message instanceof Object) {
        console.log(message)
      } else {
        console.log('%c' + message, 'color: ' + color)
      }
      console.log('%c-- DEBUG ---------------------------------------------------------', 'color:' + color + ';font-weight:bold;')
      console.log('')
    }
  }

  /**
   * Measures a hidden element.
   *
   * @since 1.0.0
   * @version 1.0.0
  **/
  Helpers.mhe = function(el) 
  {
    // Clone element.
    let clone = el.clone()
    // Add to DOM in place and measure height.
    let height = clone.addClass('mhe-clone-remove').css({'position': 'absolute', 'top': '-100%', 'display': 'block', 'max-height': 'none', 'height': 'auto', 'visibility': 'hidden'}).prependTo(el.parent()).outerHeight()
    // Destroy the clone.
    $('.mhe-clone-remove').remove()

    return height
  }

  /**
   * Checks if a value is empty, undefined or false.
   *
   * @since 1.0.0
   * @version 1.0.0
  **/
  Helpers.isEmpty = function(value) 
  {
    return (value === undefined || value === null || value === '' || value.length === 0)
  }

  /**
   * Returns a function, that, as long as it continues to be invoked, will not
   * be triggered. The function will be called after it stops being called for
   * N milliseconds. If `immediate` is passed, trigger the function on the
   * leading edge, instead of the trailing.
   *
   * $(window).on('resize', Module.test)
   *
   * Module.test = this.debounce(function () {
   *     window.Helpers.log('This has been debounced')
   * }, 250)
   *
   * @since 1.0.0
   * @version 1.0.0
  **/
  Helpers.debounce = function(func, wait, immediate) 
  {
    let timeout

    return function () {
      let args = arguments
      let later = () => {
        timeout = null
        if (!immediate) {
          func.apply(this, args)
        }
      }
      let callNow = immediate && !timeout
      clearTimeout(timeout)
      timeout = setTimeout(later, wait)
      if (callNow) {
        func.apply(this, args)
      }
    }
  }

  /**
   * Converts the URL parameters into an object.
   *
   * @since 1.0.0
   * @version 1.0.0
  **/
  Helpers.parseURLParams = function(url) 
  {
    // Check if URL contains a ?.
    if (url && url.indexOf('?') !== -1) {
      // Split URL at ?
      let urlSplit = url.split('?')
      let urlParsed = urlSplit[1]
      let urlParams = (!this.isEmpty(urlParsed)) ? urlParsed : false

      if (urlParams) {
        return  {url: urlSplit[0], params: JSON.parse('{"' + decodeURI(urlParams).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}')}
      }
    }

    return false
  }

  /**
   * Converts an object in URL parameters.
   *
   * @since 1.0.0
   * @version 1.0.0
  **/
  Helpers.parseParamObject = function(obj) 
  {
    let str = ''
    for (let key in obj) {
      if (encodeURIComponent(obj[key])) {
        if (str != '') {
          str += '&'
        } else {
          str += '?'
        }
        str += key + '=' + encodeURIComponent(obj[key])
      }
    }

    return str
  }

  /**
   * Updates the URL parameters.
   *
   * @since 1.0.0
   * @version 1.0.0
  **/
  Helpers.updateURLParameter = function(uri, param, value) 
  {
    var re = new RegExp("[\\?&]" + param + "=([^&#]*)", "i")
    var matchString = re.exec(uri)
    var delimiter
    var newString

    if (!value || value === 'null' || value === 'undefined') {
      return uri.replace(re, '')
    }

    if (matchString === null) {
      // append new param
      var hasQuestionMark = /\?/.test(uri)
      delimiter = hasQuestionMark ? "&" : "?"
      newString = uri + delimiter + param + "=" + value
    } else if (matchString.length) {
      delimiter = matchString[0].charAt(0)
      newString = uri.replace(re, delimiter + param + "=" + value)
    }

    return newString
  }

  /**
   * Updates the URL.
   *
   * @since 1.0.0
   * @version 1.0.0
  **/
  Helpers.updateURL = function(key, value) 
  {
    window.history.pushState(null, null, this.updateURLParameter(window.location.href, key, encodeURIComponent(value)))
  }

  /**
   * Splits an array into chunks.
   *
   * @since 1.0.0
   * @version 1.0.0
  **/
  Helpers.splitArrayIntoChunks = function(arr, n) 
  {
    if (!arr.length) {
      return []
    }

    var rest = arr.length % n,
        restUsed = rest,
        partLength = Math.floor(arr.length / n),
        result = []
<commit_msg>Fixes<commit_after>/**
 *
 * Helpers
 *
 * Copyright 2019, Author Name
 * Some information on the license.
 *
**/

;(function(Helpers, window) 
{

  /**
   * Customised and cross browser window.Helpers.log.
   *
   * @since 1.0.0
   * @version 1.0.0
  **/
  Helpers.log = function(message, type, alertlog) 
  {
    // Guard :: Check environment.
    if ((window.config && window.config.env === 'production')) {
      return
    }

    alertlog = (typeof alertlog === 'undefined')
    if (typeof console === 'undefined' || typeof console.log === 'undefined') {
      if (alertlog) {
        window.alert(message)
      }
    } else {
      var color = (type === 'positive') ? '#097809' : (type === 'negative') ? '#c5211d' : (typeof type !== 'undefined') ? type : '#240ad0'
      console.log('%c-- DEBUG ---------------------------------------------------------', 'color:' + color + ';font-weight:bold;')
      if (message instanceof Array || message instanceof Object) {
        console.log(message)
      } else {
        console.log('%c' + message, 'color: ' + color)
      }
      console.log('%c-- DEBUG ---------------------------------------------------------', 'color:' + color + ';font-weight:bold;')
      console.log('')
    }
  }

  /**
   * Measures a hidden element.
   *
   * @since 1.0.0
   * @version 1.0.0
  **/
  Helpers.mhe = function(el) 
  {
    // Clone element.
    let clone = el.clone()
    // Add to DOM in place and measure height.
    let height = clone.addClass('mhe-clone-remove').css({'position': 'absolute', 'top': '-100%', 'display': 'block', 'max-height': 'none', 'height': 'auto', 'visibility': 'hidden'}).prependTo(el.parent()).outerHeight()
    // Destroy the clone.
    $('.mhe-clone-remove').remove()

    return height
  }

  /**
   * Checks if a value is empty, undefined or false.
   *
   * @since 1.0.0
   * @version 1.0.0
  **/
  Helpers.isEmpty = function(value) 
  {
    return (value === undefined || value === null || value === '' || value.length === 0)
  }

  /**
   * Returns a function, that, as long as it continues to be invoked, will not
   * be triggered. The function will be called after it stops being called for
   * N milliseconds. If `immediate` is passed, trigger the function on the
   * leading edge, instead of the trailing.
   *
   * $(window).on('resize', Module.test)
   *
   * Module.test = this.debounce(function () {
   *     window.Helpers.log('This has been debounced')
   * }, 250)
   *
   * @since 1.0.0
   * @version 1.0.0
  **/
  Helpers.debounce = function(func, wait, immediate) 
  {
    let timeout

    return function () {
      let args = arguments
      let later = () => {
        timeout = null
        if (!immediate) {
          func.apply(this, args)
        }
      }
      let callNow = immediate && !timeout
      clearTimeout(timeout)
      timeout = setTimeout(later, wait)
      if (callNow) {
        func.apply(this, args)
      }
    }
  }

  /**
   * Converts the URL parameters into an object.
   *
   * @since 1.0.0
   * @version 1.0.0
  **/
  Helpers.parseURLParams = function(url) 
  {
    // Check if URL contains a ?.
    if (url && url.indexOf('?') !== -1) {
      // Split URL at ?
      let urlSplit = url.split('?')
      let urlParsed = urlSplit[1]
      let urlParams = (!this.isEmpty(urlParsed)) ? urlParsed : false

      if (urlParams) {
        return  {url: urlSplit[0], params: JSON.parse('{"' + decodeURI(urlParams).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}')}
      }
    }

    return false
  }

  /**
   * Converts an object in URL parameters.
   *
   * @since 1.0.0
   * @version 1.0.0
  **/
  Helpers.parseParamObject = function(obj) 
  {
    let str = ''
    for (let key in obj) {
      if (encodeURIComponent(obj[key])) {
        if (str != '') {
          str += '&'
        } else {
          str += '?'
        }
        str += key + '=' + encodeURIComponent(obj[key])
      }
    }

    return str
  }

  /**
   * Updates the URL parameters.
   *
   * @since 1.0.0
   * @version 1.0.0
  **/
  Helpers.updateUrlParameter = function(uri, param, value) 
  {
    var re = new RegExp("[\\?&]" + param + "=([^&#]*)", "i")
    var matchString = re.exec(uri)
    var delimiter
    var newString

    if (!value || value === 'null' || value === 'undefined') {
      return uri.replace(re, '')
    }

    if (matchString === null) {
      // append new param
      var hasQuestionMark = /\?/.test(uri)
      delimiter = hasQuestionMark ? "&" : "?"
      newString = uri + delimiter + param + "=" + value
    } else if (matchString.length) {
      delimiter = matchString[0].charAt(0)
      newString = uri.replace(re, delimiter + param + "=" + value)
    }

    return newString
  }

  /**
   * Updates a URL parameter.
   *
   * @since 1.0.0
   * @version 1.0.0
  **/
  Helpers.updateUrlHistoryParameter = function(key, value) 
  {
    window.history.pushState(null, null, this.updateUrlParameter(window.location.href, key, encodeURIComponent(value)))
  }

  /**
   * Updates a URL path.
   *
   * @since 1.0.0
   * @version 1.0.0
  **/
  Helpers.updateUrlPath = function(value) 
  {
    window.history.pushState(null, null, value)
  }

  /**
   * Splits an array into chunks.
   *
   * @since 1.0.0
   * @version 1.0.0
  **/
  Helpers.splitArrayIntoChunks = function(arr, n) 
  {
    if (!arr.length) {
      return []
    }

    var rest = arr.length % n,
        restUsed = rest,
        partLength = Math.floor(arr.length / n),
        result = []

{'fraction_non_alphanumeric': 0.18894649139048325, 'fraction_numerical': 0.016108128124421403, 'mean_word_length': 2.044813979706877, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, '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': '3925484', 'n_tokens_mistral': 3696, 'n_tokens_neox': 3563, 'n_words': 854}