Number.js 2.0 KB

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