UNPKG

1.35 kBJavaScriptView Raw
1// Plugin template from https://day.js.org/docs/en/plugin/plugin
2export default (function (option, dayjsClass) {
3 var oldParse = dayjsClass.prototype.parse;
4
5 dayjsClass.prototype.parse = function (cfg) {
6 if (typeof cfg.date === 'string') {
7 var locale = this.$locale();
8 cfg.date = locale && locale.preparse ? locale.preparse(cfg.date) : cfg.date;
9 } // original parse result
10
11
12 return oldParse.bind(this)(cfg);
13 }; // // overriding existing API
14 // // e.g. extend dayjs().format()
15
16
17 var oldFormat = dayjsClass.prototype.format;
18
19 dayjsClass.prototype.format = function () {
20 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
21 args[_key] = arguments[_key];
22 }
23
24 // original format result
25 var result = oldFormat.call.apply(oldFormat, [this].concat(args)); // return modified result
26
27 var locale = this.$locale();
28 return locale && locale.postformat ? locale.postformat(result) : result;
29 };
30
31 var oldFromTo = dayjsClass.prototype.fromToBase;
32
33 if (oldFromTo) {
34 dayjsClass.prototype.fromToBase = function (input, withoutSuffix, instance, isFrom) {
35 var locale = this.$locale() || instance.$locale(); // original format result
36
37 return oldFromTo.call(this, input, withoutSuffix, instance, isFrom, locale && locale.postformat);
38 };
39 }
40});
\No newline at end of file