Number.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _vue = require("vue");
  7. const StatisticNumber = props => {
  8. const {
  9. value,
  10. formatter,
  11. precision,
  12. decimalSeparator,
  13. groupSeparator = '',
  14. prefixCls
  15. } = props;
  16. let valueNode;
  17. if (typeof formatter === 'function') {
  18. // Customize formatter
  19. valueNode = formatter({
  20. value
  21. });
  22. } else {
  23. // Internal formatter
  24. const val = String(value);
  25. const cells = val.match(/^(-?)(\d*)(\.(\d+))?$/);
  26. // Process if illegal number
  27. if (!cells) {
  28. valueNode = val;
  29. } else {
  30. const negative = cells[1];
  31. let int = cells[2] || '0';
  32. let decimal = cells[4] || '';
  33. int = int.replace(/\B(?=(\d{3})+(?!\d))/g, groupSeparator);
  34. if (typeof precision === 'number') {
  35. decimal = decimal.padEnd(precision, '0').slice(0, precision > 0 ? precision : 0);
  36. }
  37. if (decimal) {
  38. decimal = `${decimalSeparator}${decimal}`;
  39. }
  40. valueNode = [(0, _vue.createVNode)("span", {
  41. "key": "int",
  42. "class": `${prefixCls}-content-value-int`
  43. }, [negative, int]), decimal && (0, _vue.createVNode)("span", {
  44. "key": "decimal",
  45. "class": `${prefixCls}-content-value-decimal`
  46. }, [decimal])];
  47. }
  48. }
  49. return (0, _vue.createVNode)("span", {
  50. "class": `${prefixCls}-content-value`
  51. }, [valueNode]);
  52. };
  53. StatisticNumber.displayName = 'StatisticNumber';
  54. var _default = exports.default = StatisticNumber;