Number.js 1.6 KB

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