PromoCursed/node_modules/antd/lib/statistic/Number.js

54 lines
1.6 KiB
JavaScript
Raw Normal View History

2024-08-20 23:25:37 +04:00
"use strict";
"use client";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
const StatisticNumber = props => {
const {
value,
formatter,
precision,
decimalSeparator,
groupSeparator = '',
prefixCls
} = props;
let valueNode;
if (typeof formatter === 'function') {
// Customize formatter
valueNode = formatter(value);
} else {
// Internal formatter
const val = String(value);
const cells = val.match(/^(-?)(\d*)(\.(\d+))?$/);
// Process if illegal number
if (!cells || val === '-') {
valueNode = val;
} else {
const negative = cells[1];
let int = cells[2] || '0';
let decimal = cells[4] || '';
int = int.replace(/\B(?=(\d{3})+(?!\d))/g, groupSeparator);
if (typeof precision === 'number') {
decimal = decimal.padEnd(precision, '0').slice(0, precision > 0 ? precision : 0);
}
if (decimal) {
decimal = `${decimalSeparator}${decimal}`;
}
valueNode = [/*#__PURE__*/React.createElement("span", {
key: "int",
className: `${prefixCls}-content-value-int`
}, negative, int), decimal && ( /*#__PURE__*/React.createElement("span", {
key: "decimal",
className: `${prefixCls}-content-value-decimal`
}, decimal))];
}
}
return /*#__PURE__*/React.createElement("span", {
className: `${prefixCls}-content-value`
}, valueNode);
};
var _default = exports.default = StatisticNumber;