import QuillDeltaToHtmlConverter from 'quill-delta-to-html';
export function text2Delta(description) {
  if (!description) {
    return undefined;
  } // eslint-disable-next-line no-restricted-globals


  if (!isNaN(description)) {
    return String(description);
  }

  var temp = description;

  try {
    temp = JSON.parse(description.replace(/\\n/g, '\\n').replace(/\\'/g, '\\\'').replace(/\\"/g, '\\"').replace(/\\&/g, '\\&').replace(/\\r/g, '\\r').replace(/\\t/g, '\\t').replace(/\\b/g, '\\b').replace(/\\f/g, '\\f'));
  } catch (error) {
    temp = description;
  } // return temp;


  return temp || '';
}
/**
 * 将quill特有的文本结构转为html
 * @param {*} description
 */

export function delta2Html(description) {
  var delta = text2Delta(description);
  var converter = new QuillDeltaToHtmlConverter(delta, {});
  var text = converter.convert();

  if (text.substring(0, 3) === '<p>') {
    return text.substring(3);
  }

  return text;
}
/**
 * 生成指定长度的随机字符串
 * @param len 字符串长度
 * @returns {string}
 */

export function randomString() {
  var len = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 32;
  var code = '';
  var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  var maxPos = chars.length;

  for (var i = 0; i < len; i += 1) {
    code += chars.charAt(Math.floor(Math.random() * (maxPos + 1)));
  }

  return code;
}
/**
 * randomWord 产生任意长度随机字母数字组合
 * @param randomFlag 是否任意长度 min-任意长度最小位[固定位数] max-任意长度最大位
 * @param min
 * @param max
 * @returns {string}
 */

export function randomWord(randomFlag, min, max) {
  var str = '';
  var range = min;
  var arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; // 随机产生

  if (randomFlag) {
    range = Math.round(Math.random() * (max - min)) + min;
  }

  for (var i = 0; i < range; i += 1) {
    var pos = Math.round(Math.random() * (arr.length - 1));
    str += arr[pos];
  }

  return str;
}
//# sourceMappingURL=utils.js.map
