{"size": 1386, "ext": "js", "max_stars_repo_path": "src/util/toString.js", "max_stars_repo_name": "JinjieTech/react-native-echarts", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/util/toString.js", "max_issues_repo_name": "JinjieTech/react-native-echarts", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/util/toString.js", "max_forks_repo_name": "JinjieTech/react-native-echarts", "max_forks_repo_forks_event_min_datetime": "2018-08-29T12:35:22.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-29T12:35:22.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 27.1764705882, "max_line_length": 157, "alphanum_fraction": 0.5057720058}
export default function toString(objOrign) {
  let obj = JSON.parse(JSON.stringify(objOrign))

  let formatObj = formatLongName(obj)

  let result = JSON.stringify(obj, function(key, val) {
        if (typeof val === 'function') {
            return `~--demo--~${val}~--demo--~`;
        }
        return val;
    });

    do {
        result = result.replace('\"~--demo--~', '').replace('~--demo--~\"', '').replace(/\\n/g, '').replace(/\\\"/g,"\"");//最后一个replace将release模式中莫名生成的\"转换成"
    } while (result.indexOf('~--demo--~') >= 0);

    do {
      result = result.replace('**n**', `\\n`)
    } while (result.includes('**n**'))

    return result;
}

const formatLongName = (obj) => {
  if (obj && obj.radar && obj.radar.indicator) {
    obj.radar.indicator.forEach((item, index)=>{
      if (index === 1 || index === 4) {
        item.text = item.text.split(' ').map(i => splitString(i, 8)).join(`**n**`)
      }
      if (index === 2 || index === 3) {
        item.text = item.text.split(' ').map(i => splitString(i, 14)).join(`**n**`)
      }
    })
  } else {
    return obj
  }
}

const splitString =  (value, splitNum) => {
  let list = value.split('');
  let result = '';
  for (let i = 1; i <= list.length; i++) {
    if (!(i % splitNum) && list[i] !== undefined) {
      result += list[i - 1] + `**n**`;
    } else {
      result += list[i - 1];
    }
  }
  return result;
}
