<commit_before>import {
  arrayToObject,
  isNumber,
  isObject,
  isString,
  isNullOrUndefined,
  propertyValueConverters,
} from './core'

// this will be an object of properties that map to their corresponding rtl property (their doppelganger)
const propertiesToConvert = arrayToObject([
  ['paddingLeft', 'paddingRight'],
  ['marginLeft', 'marginRight'],
  ['left', 'right'],
  ['borderLeft', 'borderRight'],
  ['borderLeftColor', 'borderRightColor'],
  ['borderLeftStyle', 'borderRightStyle'],
  ['borderLeftWidth', 'borderRightWidth'],
  ['borderTopLeftRadius', 'borderTopRightRadius'],
  ['borderBottomLeftRadius', 'borderBottomRightRadius'],
])

const propsToIgnore = ['content']

// this is the same as the propertiesToConvert except for values
const valuesToConvert = arrayToObject([
  ['ltr', 'rtl'],
  ['left', 'right'],
  ['w-resize', 'e-resize'],
  ['sw-resize', 'se-resize'],
  ['nw-resize', 'ne-resize'],
])

// Sorry for the regex 😞, but basically thisis used to replace _every_ instance of
// `ltr`, `rtl`, `right`, and `left` in `backgroundimage` with the corresponding opposite.
// A situation we're accepting here:
// url('/left/right/rtl/ltr.png') will be changed to url('/right/left/ltr/rtl.png')
// Definite trade-offs here, but I think it's a good call.
const bgImgDirectionRegex = new RegExp(
  '(^|\\W|_)((ltr)|(rtl)|(left)|(right))(\\W|_|$)',
  'g',
)
const bgPosDirectionRegex = new RegExp('(left)|(right)')

/**
 * converts properties and values in the CSS in JS object to their corresponding RTL values
 * @param {Object} object the CSS in JS object
 * @return {Object} the RTL converted object
 */
function convert(object) {
  return Object.keys(object).reduce((newObj, originalKey) => {
    let originalValue = object[originalKey]
    if (isString(originalValue)) {
      // you're welcome to later code 😺
      originalValue = originalValue.trim()
    }

    // Some properties should never be transformed
    if (propsToIgnore.includes(originalKey)) {
      newObj[originalKey] = originalValue
      return newObj
    }

    const {key, value} = convertProperty(originalKey, originalValue)
    newObj[key] = value
    return newObj
  }, {})
}

/**
 * Converts a property and its value to the corresponding RTL key and value
 * @param {String} originalKey the original property key
 * @param {Number|String|Object} originalValue the original css property value
 * @return {Object} the new {key, value} pair<commit_msg>fix(convert function): Use include util instead of Array.prototype.includes (#28)<commit_after>import {
  includes,
  arrayToObject,
  isNumber,
  isObject,
  isString,
  isNullOrUndefined,
  propertyValueConverters,
} from './core'

// this will be an object of properties that map to their corresponding rtl property (their doppelganger)
const propertiesToConvert = arrayToObject([
  ['paddingLeft', 'paddingRight'],
  ['marginLeft', 'marginRight'],
  ['left', 'right'],
  ['borderLeft', 'borderRight'],
  ['borderLeftColor', 'borderRightColor'],
  ['borderLeftStyle', 'borderRightStyle'],
  ['borderLeftWidth', 'borderRightWidth'],
  ['borderTopLeftRadius', 'borderTopRightRadius'],
  ['borderBottomLeftRadius', 'borderBottomRightRadius'],
])

const propsToIgnore = ['content']

// this is the same as the propertiesToConvert except for values
const valuesToConvert = arrayToObject([
  ['ltr', 'rtl'],
  ['left', 'right'],
  ['w-resize', 'e-resize'],
  ['sw-resize', 'se-resize'],
  ['nw-resize', 'ne-resize'],
])

// Sorry for the regex 😞, but basically thisis used to replace _every_ instance of
// `ltr`, `rtl`, `right`, and `left` in `backgroundimage` with the corresponding opposite.
// A situation we're accepting here:
// url('/left/right/rtl/ltr.png') will be changed to url('/right/left/ltr/rtl.png')
// Definite trade-offs here, but I think it's a good call.
const bgImgDirectionRegex = new RegExp(
  '(^|\\W|_)((ltr)|(rtl)|(left)|(right))(\\W|_|$)',
  'g',
)
const bgPosDirectionRegex = new RegExp('(left)|(right)')

/**
 * converts properties and values in the CSS in JS object to their corresponding RTL values
 * @param {Object} object the CSS in JS object
 * @return {Object} the RTL converted object
 */
function convert(object) {
  return Object.keys(object).reduce((newObj, originalKey) => {
    let originalValue = object[originalKey]
    if (isString(originalValue)) {
      // you're welcome to later code 😺
      originalValue = originalValue.trim()
    }

    // Some properties should never be transformed
    if (includes(propsToIgnore, originalKey)) {
      newObj[originalKey] = originalValue
      return newObj
    }

    const {key, value} = convertProperty(originalKey, originalValue)
    newObj[key] = value
    return newObj
  }, {})
}

/**
 * Converts a property and its value to the corresponding RTL key and value
 * @param {String} originalKey the original property key
 * @param {Number|String|Object} originalValue the original css property value
 * @return {Object} the new {key, value} pair
{'fraction_non_alphanumeric': 0.13976338480048126, 'fraction_numerical': 0.0004010427110487267, 'mean_word_length': 4.481318681318681, 'pattern_counts': {'":': 0, '<': 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': '290501', 'n_tokens_mistral': 1508, 'n_tokens_neox': 1464, 'n_words': 471}