Number.js
1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import * as React from 'react';
import padEnd from 'lodash/padEnd';
var StatisticNumber = function StatisticNumber(props) {
var value = props.value,
formatter = props.formatter,
precision = props.precision,
decimalSeparator = props.decimalSeparator,
_props$groupSeparator = props.groupSeparator,
groupSeparator = _props$groupSeparator === void 0 ? '' : _props$groupSeparator,
prefixCls = props.prefixCls;
var valueNode;
if (typeof formatter === 'function') {
// Customize formatter
valueNode = formatter(value);
} else {
// Internal formatter
var val = String(value);
var cells = val.match(/^(-?)(\d*)(\.(\d+))?$/); // Process if illegal number
if (!cells || val === '-') {
valueNode = val;
} else {
var negative = cells[1];
var _int = cells[2] || '0';
var decimal = cells[4] || '';
_int = _int.replace(/\B(?=(\d{3})+(?!\d))/g, groupSeparator);
if (typeof precision === 'number') {
decimal = padEnd(decimal, precision, '0').slice(0, precision);
}
if (decimal) {
decimal = "".concat(decimalSeparator).concat(decimal);
}
valueNode = [/*#__PURE__*/React.createElement("span", {
key: "int",
className: "".concat(prefixCls, "-content-value-int")
}, negative, _int), decimal && /*#__PURE__*/React.createElement("span", {
key: "decimal",
className: "".concat(prefixCls, "-content-value-decimal")
}, decimal)];
}
}
return /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-content-value")
}, valueNode);
};
export default StatisticNumber;