index.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { FORMAT_DEFAULT } from '../../constant';
  2. export default (function (o, c, d) {
  3. var proto = c.prototype;
  4. var oldFormat = proto.format;
  5. var englishFormats = {
  6. LTS: 'h:mm:ss A',
  7. LT: 'h:mm A',
  8. L: 'MM/DD/YYYY',
  9. LL: 'MMMM D, YYYY',
  10. LLL: 'MMMM D, YYYY h:mm A',
  11. LLLL: 'dddd, MMMM D, YYYY h:mm A'
  12. };
  13. d.en.formats = englishFormats;
  14. var t = function t(format) {
  15. return format.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, function (_, a, b) {
  16. return a || b.slice(1);
  17. });
  18. };
  19. proto.format = function (formatStr) {
  20. if (formatStr === void 0) {
  21. formatStr = FORMAT_DEFAULT;
  22. }
  23. var _this$$locale = this.$locale(),
  24. _this$$locale$formats = _this$$locale.formats,
  25. formats = _this$$locale$formats === void 0 ? {} : _this$$locale$formats;
  26. var result = formatStr.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g, function (_, a, b) {
  27. var B = b && b.toUpperCase();
  28. return a || formats[b] || englishFormats[b] || t(formats[B]);
  29. });
  30. return oldFormat.call(this, result);
  31. };
  32. });