<commit_before>// detect node for conditional import for jsonToFormData
const isNode = typeof process !== 'undefined' && process.versions && !!process.versions.node
if (isNode) {
// TODO : deal with node.js side  for example using https://www.npmjs.com/package/form-data: fake one for now
}

export function jsonToFormData (jsonData) {
  jsonData = JSON.parse(JSON.stringify(jsonData))
  let formData
  if (isNode) {
    formData = {append: function (fieldName, value) {}} // FIXME: hack for tests/nodes.js
  } else {
    formData = new FormData()
  }
  for (let fieldName in jsonData) {
    let value = jsonData[fieldName]
    // value = encodeURIComponent(JSON.stringify(value))
    // value = JSON.stringify(value)
    // value = value.replace(/\"/g, '')
    if (Object.prototype.toString.call(value) === '[object Object]') {
      value = JSON.stringify(value)
    // console.log("value",value)
    }
    if (Object.prototype.toString.call(value) === '[object Array]') {
      // value = //JSON.stringify(value)
      // value = 'arr[]', arr[i]//value.reduce()
      // console.log("value",value)
      value = `{ ${value.join(',')} }`
    }
    if(typeof value === 'boolean') {
      value = `'${value}'`
    }

    // console.log("append",fieldName, value)
    formData.append(fieldName, value)
  }
  return formData
}<commit_msg>fix(boolean formadata handling): fixed boolean formdata field handling (for real this time)<commit_after>// detect node for conditional import for jsonToFormData
const isNode = typeof process !== 'undefined' && process.versions && !!process.versions.node
if (isNode) {
// TODO : deal with node.js side  for example using https://www.npmjs.com/package/form-data: fake one for now
}

export function jsonToFormData (jsonData) {
  jsonData = JSON.parse(JSON.stringify(jsonData))
  let formData
  if (isNode) {
    formData = {append: function (fieldName, value) {}} // FIXME: hack for tests/nodes.js
  } else {
    formData = new FormData()
  }
  for (let fieldName in jsonData) {
    let value = jsonData[fieldName]
    // value = encodeURIComponent(JSON.stringify(value))
    // value = JSON.stringify(value)
    // value = value.replace(/\"/g, '')
    if (Object.prototype.toString.call(value) === '[object Object]') {
      value = JSON.stringify(value)
    // console.log("value",value)
    }
    if (Object.prototype.toString.call(value) === '[object Array]') {
      // value = //JSON.stringify(value)
      // value = 'arr[]', arr[i]//value.reduce()
      // console.log("value",value)
      value = `{ ${value.join(',')} }`
    }
    if (typeof value === 'boolean') {
      value = '' + value
    }

    // console.log("append",fieldName, value)
    formData.append(fieldName, value)
  }
  return formData
}
{'fraction_non_alphanumeric': 0.16333212077118953, 'fraction_numerical': 0.0, 'mean_word_length': 3.17298937784522, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '80236', 'n_tokens_mistral': 858, 'n_tokens_neox': 851, 'n_words': 206}