<commit_before>/**
 * Library spacing compute handles returning className values for numbers and
 * inline style values for custom strings.
 */
export default function spacing(props) {
  const classNames = []
  const styles = {}

  Object.keys(props).forEach(key => {
    let value = props[key]

    if (typeof value === 'number') {
      classNames.push(`${key}-${value}`)
      return
    }

    // Else add the key value to style props map
    const styleName = key.replace(/([mp])([trbl]?)/, (match, p1, p2) => {
      let styleKey = p1 === 'm' ? 'margin' : 'padding'
      if (p2) {
        /* eslint-disable default-case */
        switch (p2) {
          case 't':
            styleKey += 'Top'
            break
          case 'r':
            styleKey += 'Right'
            break
          case 'b':
            styleKey += 'Bottom'
            break
          case 'l':
            styleKey += 'Left'
            break
        }
        /* eslint-enable default-case */
      }

      return styleKey
    })

    // Append px if a unit isn't set otherwise inline styles don't work
    if (!/[a-z]/.test(value)) value += 'px'

    styles[styleName] = value
  })

  return { classNames, styles }
}<commit_msg>fix: space util x+y handlers (#72)<commit_after>/**
 * Library spacing compute handles returning className values for numbers and
 * inline style values for custom strings.
 */
export default function spacing(props) {
  const classNames = []
  const styles = {}

  Object.keys(props).forEach(key => {
    let value = props[key]

    if (typeof value === 'number') {
      classNames.push(`${key}-${value}`)
      return
    }

    // Append px if a unit isn't set otherwise inline styles don't work
    if (!/[a-z]/.test(value)) value += 'px'

    const [, base, modifier] = key.match(/([mp])([trblxy]?)/)
    const styleKey = base === 'm' ? 'margin' : 'padding'

    switch (modifier) {
      case 't':
        styles[`${styleKey}Top`] = value
        break
      case 'r':
        styles[`${styleKey}Right`] = value
        break
      case 'b':
        styles[`${styleKey}Bottom`] = value
        break
      case 'l':
        styles[`${styleKey}Left`] = value
        break
      case 'x':
        styles[`${styleKey}Left`] = value
        styles[`${styleKey}Right`] = value
        break
      case 'y':
        styles[`${styleKey}Top`] = value
        styles[`${styleKey}Bottom`] = value
        break
      default:
        styles[styleKey] = value
    }
  })

  return { classNames, styles }
}
{'fraction_non_alphanumeric': 0.1464867010718539, 'fraction_numerical': 0.00277888050813815, 'mean_word_length': 2.058252427184466, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '312913', 'n_tokens_mistral': 779, 'n_tokens_neox': 756, 'n_words': 215}