<commit_before>import React from 'react'
import _ from 'lodash'
import moment from 'moment'
import numeral from 'numeral'
import {Link} from 'react-router'

class Format extends React.Component {

  render() {
    const { format } = this.props
    let Content = Default
    if(_.isFunction(format)) {
      Content = format
    } else if(format === 'status') {
      Content = Status
    } else if(format === 'price') {
      Content = Price
    } else if(format === 'date') {
      Content = Date
    } else if(format === 'datetime') {
      Content = DateTime
    } else if(format === 'check_times') {
      Content = CheckTimes
    } else if(format === 'check') {
      Content = Check
    } else if(format === 'capitalize') {
      Content = Capitalize
    } else if(format === 'email') {
      Content = Email
    } else if(format === 'raw') {
      Content = Raw
    } else if(this.props.value === '') {
      Content = Empty
    }
    return <Content {...this.props} />
  }

}

const Default = (props) => {
  return <span>{props.value}</span>
}

const Raw = (props) => {
  return <span dangerouslySetInnerHTML={{__html: props.value}}></span>
}

const Empty = () => {
  return <span dangerouslySetInnerHTML={{__html: '&nbsp;'}}></span>
}

const Status = (props) => {
  return (props.value) ? <span className={props.value.toLowerCase()}>{props.value.toUpperCase()}</span> : <span />
}

const CheckTimes = (props) => {
  return ((props.value !== false && !_.isNull(props.value)) || props.value === true) ? <i className="icon green check" /> : <i className="icon red times" />
}

const Check = (props) => {
  return ((props.value !== false && !_.isNull(props.value)) || props.value === true) ? <i className="icon green check" /> : <span />
}

const Price = (props) => {
  return <span>{numeral(props.value).format('$0,0.00')}</span>
}

const Date = (props) => {
  return <span>{(props.value) ? moment(props.value).format('MM/DD/YY') : ''}</span>
}

const DateTime = (props) => {
  return <span>{(props.value) ? moment(props.value).format('MM/DD/YY @ hh:mm A') : ''}</span>
}

const Capitalize = (props) => {
  return <span>{props.value.toUpperCase()}</span>
}

const Email = (props) => {
  return <Link to={`mailto:${props.value}`}>{props.value}</Link>
}

export default Format<commit_msg>making format dry<commit_after>import React from 'react'
import _ from 'lodash'
import moment from 'moment'
import numeral from 'numeral'
import {Link} from 'react-router'

class Format extends React.Component {

  render() {
    const { format } = this.props
    if(_.isFunction(format)) {
      return format(this.props)
    } else if(format === 'status') {
      return Status(this.props)
    } else if(format === 'price') {
      return Price(this.props)
    } else if(format === 'date') {
      return Date(this.props, 'MM/DD/YY')
    } else if(format === 'datetime') {
      return Date(this.props, 'MM/DD/YY @ hh:mm A')
    } else if(format === 'check_times') {
      return Check(this.props, true)
    } else if(format === 'check') {
      return Check(this.props, false)
    } else if(format === 'capitalize') {
      return Capitalize(this.props)
    } else if(format === 'email') {
      return Email(this.props)
    } else if(format === 'raw') {
      return Raw(this.props)
    } else if(this.props.value === '') {
      return Empty(this.props)
    } else {
      return Default(this.props)
    }
  }

}

const Default = (props) => {
  return <span>{props.value}</span>
}

const Raw = (props) => {
  return <span dangerouslySetInnerHTML={{__html: props.value}}></span>
}

const Empty = () => {
  return <span dangerouslySetInnerHTML={{__html: '&nbsp;'}}></span>
}

const Status = (props) => {
  return (props.value) ? <span className={props.value.toLowerCase()}>{props.value.toUpperCase()}</span> : <span />
}

const Check = (props, times) => {
  let alternate = (times) ? <i className="icon red times" /> : <span />
  return ((props.value !== false && !_.isNull(props.value)) || props.value === true) ? <i className="icon green check" /> : alternate
}

const Price = (props) => {
  return <span>{numeral(props.value).format('$0,0.00')}</span>
}

const Date = (props, format) => {
  return <span>{(props.value) ? moment(props.value).format(format) : ''}</span>
}

const Capitalize = (props) => {
  return <span>{props.value.toUpperCase()}</span>
}

const Email = (props) => {
  return <Link to={`mailto:${props.value}`}>{props.value}</Link>
}

export default Format
{'fraction_non_alphanumeric': 0.19302169537016328, 'fraction_numerical': 0.0017893088794453142, 'mean_word_length': 3.4409136047666338, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 67, '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': '3582403', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1476, 'n_words': 342}