<commit_before>import angular from 'angular'
import forEach from 'lodash.foreach'
import includes from 'lodash.includes'
import isEmpty from 'lodash.isempty'
import isNumber from 'lodash.isnumber'
import map from 'lodash.map'
import slice from 'lodash.slice'
import xoApi from 'xo-api'
import moment from 'moment'

// ===================================================================

export default angular.module('xoWebApp.filters', [
  xoApi
])

  // The bytes filters takes a number and formats it using adapted
  // units (KB, MB, etc.).
  .filter('bytesToSize', () => {
    const powers = ['', 'K', 'M', 'G', 'T', 'P']

    return function bytesToSize (bytes, unit = 'iB', base = 1024) {
      if (!isNumber(bytes)) {
        return bytes
      }

      let i = 0
      while (bytes >= base) {
        bytes /= base
        ++i
      }

      if (bytes === -1) {
        return '-'
      }

      // Maximum 1 decimals.
      bytes = ((bytes * 10) | 0) / 10

      return `${bytes} ${powers[i]}${unit}`
    }
  })

  // Takes a size (eg.: '8 GiB') and returns a number of bytes
  .filter('sizeToBytes', () => {
    const powers = ['', 'K', 'M', 'G', 'T', 'P']

    return function sizeToBytes (size, unit = 'iB', base = 1024) {
      const split = size.split(' ')
      if (split.length !== 2) {
        return size
      }
      let number = parseInt(split[0], 10)
      const powerUnit = split[1]
      const power = powerUnit.slice(0, 1)
      const effUnit = powerUnit.slice(1)

      if (!includes(powers, power) || unit !== effUnit) {
        return size
      }

      let i = 0
      while (powers[i] !== power) {
        number *= base
        ++i
      }

      return number
    }
  })

  // Takes a number of bytes and converts it to the desired unit (GiB, MiB, etc.).
  .filter('bytesConvert', () => {
    return function bytesConvert (bytes, powerUnit = 'GiB', unit = 'iB', base = 1024) {
      let powerUnits = ['', 'K', 'M', 'G', 'T', 'P']
      powerUnits = powerUnits.map(pu => pu + unit)

      if (!isNumber(bytes) || !includes(powerUnits, powerUnit)) {
        return bytes
      }
<commit_msg>Size input should allow float numbers (Fix #719)<commit_after>import angular from 'angular'
import forEach from 'lodash.foreach'
import includes from 'lodash.includes'
import isEmpty from 'lodash.isempty'
import isNumber from 'lodash.isnumber'
import map from 'lodash.map'
import slice from 'lodash.slice'
import xoApi from 'xo-api'
import moment from 'moment'

// ===================================================================

export default angular.module('xoWebApp.filters', [
  xoApi
])

  // The bytes filters takes a number and formats it using adapted
  // units (KB, MB, etc.).
  .filter('bytesToSize', () => {
    const powers = ['', 'K', 'M', 'G', 'T', 'P']

    return function bytesToSize (bytes, unit = 'iB', base = 1024) {
      if (!isNumber(bytes)) {
        return bytes
      }

      let i = 0
      while (bytes >= base) {
        bytes /= base
        ++i
      }

      if (bytes === -1) {
        return '-'
      }

      // Maximum 1 decimals.
      bytes = ((bytes * 10) | 0) / 10

      return `${bytes} ${powers[i]}${unit}`
    }
  })

  // Takes a size (eg.: '8 GiB') and returns a number of bytes
  .filter('sizeToBytes', () => {
    const powers = ['', 'K', 'M', 'G', 'T', 'P']

    return function sizeToBytes (size, unit = 'iB', base = 1024) {
      const split = size.split(' ')
      if (split.length !== 2) {
        return size
      }
      let number = parseFloat(split[0], 10)
      const powerUnit = split[1]
      const power = powerUnit.slice(0, 1)
      const effUnit = powerUnit.slice(1)

      if (!includes(powers, power) || unit !== effUnit) {
        return size
      }

      let i = 0
      while (powers[i] !== power) {
        number *= base
        ++i
      }

      return number
    }
  })

  // Takes a number of bytes and converts it to the desired unit (GiB, MiB, etc.).
  .filter('bytesConvert', () => {
    return function bytesConvert (bytes, powerUnit = 'GiB', unit = 'iB', base = 1024) {
      let powerUnits = ['', 'K', 'M', 'G', 'T', 'P']
      powerUnits = powerUnits.map(pu => pu + unit)

      if (!isNumber(bytes) || !includes(powerUnits, powerUnit)) {
        return bytes
      }

{'fraction_non_alphanumeric': 0.18328274573896802, 'fraction_numerical': 0.014709315900070045, 'mean_word_length': 2.416267942583732, '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': '5546553', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1342, 'n_words': 427}