/**
 * 首字母大写
 * @param str
 */
export var capitalize = function capitalize(str) {
  str = str || '';

  if (str.length > 0) {
    var first = str.substr(0, 1).toUpperCase();
    var spare = str.substr(1, str.length);
    return first + spare;
  }
};
/**
 * 格式化参数
 * @param formatter
 * @param val
 */

export var formatWrapper = function formatWrapper(val, formatter) {
  if (formatter) {
    return formatter(val);
  }

  return val;
};
/**
 * 获取随机id
 */

export var randomUuid = function randomUuid() {
  return "uuid_" + Math.random().toString(36).substr(2);
};
export var dataURLtoBlob = function dataURLtoBlob(dataurl, onlyData) {
  try {
    var arr = dataurl.split(',');
    var mime = (arr[0].match(/:(.*?);/) || [])[1];
    var bstr = atob(arr[1]);
    var n = bstr.length;
    var u8arr = new Uint8Array(n);

    while (n--) {
      u8arr[n] = bstr.charCodeAt(n);
    }

    return onlyData ? u8arr : new Blob([u8arr], {
      type: mime
    });
  } catch (e) {
    console.error(e);
  }
};
export var getStringFromHtml = function getStringFromHtml(htmlStr) {
  var con = htmlStr.replace(/\s*/g, ''); //去掉空格

  var res = con.replace(/<[^>]+>/g, ''); //去掉所有的html标记

  var res1 = res.replace(/↵/g, ''); //去掉所有的↵符号

  var res2 = res1.replace(/[\r\n]/g, '');
  return res2;
};
/**
 * 获取字符串有效数值
 * @param value string
 */

export var getNumber = function getNumber(value) {
  return value.replace(/[^\d.]/g, '').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.');
};
/**
 * 得到微信vcode
 */

export var getWxVcode = function getWxVcode() {
  var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  var LENGTH = 64;
  var result = '';

  for (var i = LENGTH; i > 0; --i) {
    result += chars[Math.floor(Math.random() * chars.length)];
  }

  return result;
};
/**
 * 驼峰转下划线
 * @param exp 名称
 */

export var humpToUnderLine = function humpToUnderLine(exp) {
  return exp.replace(/([A-Z])/g, '_$1').toLowerCase();
};
/**
 * 下划线转驼峰
 * @param exp 名称
 */

export var underLineToHump = function underLineToHump(exp) {
  return exp.replace(/_(\w)/g, function (_, letter) {
    return letter.toUpperCase();
  });
};

