amos-tool
Version:
amos ui tool
86 lines (84 loc) • 3.49 kB
JavaScript
;
var deepCopy = require("./_deepCopy"), utils = require("./utils");
module.exports = {
toCapitalStr: function(e) {
return utils.isNil(e) ? e : utils.isString(e) ? e[0].toUpperCase() + e.slice(1, e.length) : e;
},
camelCase: function(e) {
return e.charAt(0).toUpperCase() + e.slice(1).replace(/-(\w)/g, function(e, r) {
return r.toUpperCase();
});
},
transCamel: function(e) {
return (e = e.toLowerCase()).replace(/-(\w)/g, function(e, r) {
return r.toUpperCase();
});
},
capFirst: function(e) {
return e && "" !== e ? e.replace(/(\w)/, function(e) {
return e.toUpperCase();
}) : e;
},
hashCode: function(e) {
if (e) {
var r = function(e) {
return e > 2147483647 || e < -2147483648 ? 4294967295 & e : e;
};
e = e.toString();
for (var t = 0, n = 0; n < e.length; n++) t = r(t = 31 * t + e.charCodeAt(n));
return t;
}
return null;
},
dealScaleAndUnit: function(e, r) {
var t = deepCopy.clone(r);
if (t || (t = {
selfenable: !1,
fixnumber: 2,
thousandsplitchar: !0
}), !utils.isFloat(e)) return e;
var n = "";
"-" == (e = e.toString()).charAt(0) && (n = "-", e = e.substring(1, e.length)),
null != t.selfscale && "" != t.selfscale || null != t.selfunit && "" != t.selfunit || (t.selfscale = "1000,1000,1000",
t.selfunit = "K,M,B");
var l = 2;
null != t.fixnumber && "NaN" != parseInt(t.fixnumber).toString() && (l = parseInt(t.fixnumber));
var a = "";
if (null != t.suffix && (a = t.suffix), t.selfenable) {
var i = t.selfunit;
null == i && (i = "");
var s = t.selfscale;
if (null == s || "" == s.toString().trim()) a = i + a; else {
for (var o = i.split(","), u = s.split(","), f = [], p = !0, c = 0; c < u.length; c++) if (null != u[c] && "NaN" != parseFloat(u[c]).toString()) {
if ("NaN" == parseFloat(u[c]).toString() || "0" == parseFloat(u[c]).toString() || parseFloat(u[c]) < 0) {
p = !1;
break;
}
0 == f.length ? f[0] = u[c] : f[f.length] = parseFloat(u[c]) * parseFloat(f[f.length - 1]);
}
if (u = f, p) for (var h = u.length - 1; h >= 0; h--) if (!(h > o.length - 1)) {
null == o[h] && (o[h] = "");
var g = parseFloat(e) / u[h];
if (e.indexOf(".") > -1) {
var d = e.substr(e.indexOf(".") + 1, e.length).length;
g = parseFloat(e) * Math.pow(10, d) / (u[h] * Math.pow(10, d));
}
if (Math.abs(g) >= 1) {
e = g, a = o[h] + a;
break;
}
}
}
}
return l > -1 && (e = parseFloat(e).toFixed(l) + ""), t.fillzero || (e = parseFloat(e) + ""),
(null == t.thousandsplitchar || t.thousandsplitchar) && (e = e.indexOf(".") > -1 ? e.substr(0, e.indexOf(".")).replace(/\d{1,3}(?=(\d{3})+$)/g, "$&,") + e.substr(e.indexOf("."), e.length) : e.replace(/\d{1,3}(?=(\d{3})+$)/g, "$&,")),
e = n + e, null != t.prefix && (e = t.prefix + e), e += a;
},
toUTF8: function(e) {
var r, t, n, l = "";
for (t = e.length, r = 0; r < t; r++) (n = e.charCodeAt(r)) >= 1 && n <= 127 ? l += e.charAt(r) : n > 2047 ? (l += String.fromCharCode(224 | n >> 12 & 15),
l += String.fromCharCode(128 | n >> 6 & 63), l += String.fromCharCode(128 | 63 & n)) : (l += String.fromCharCode(192 | n >> 6 & 31),
l += String.fromCharCode(128 | 63 & n));
return l;
}
};