41ad9da ←567e31cantonApr 11, 2026 api

rename to .bin-VsWjm9nR

M /sublimated/undefined
binary file or content unavailable
A /sublimated/undefined +104 -0
1import zeroFill from '../utils/zero-fill';
2import isFunction from '../utils/is-function';
3
4var formattingTokens =
5 /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|N{1,5}|YYYYYY|YYYYY|YYYY|YY|y{2,4}|yo?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,
6 localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g,
7 formatFunctions = {},
8 formatTokenFunctions = {};
9
10export { formattingTokens, formatTokenFunctions };
11
12// token: 'M'
13// padded: ['MM', 2]
14// ordinal: 'Mo'
15// callback: function () { this.month() + 1 }
16export function addFormatToken(token, padded, ordinal, callback) {
17 var func = callback;
18 if (typeof callback === 'string') {
19 func = function () {
20 return this[callback]();
21 };
22 }
23 if (token) {
24 formatTokenFunctions[token] = func;
25 }
26 if (padded) {
27 formatTokenFunctions[padded[0]] = function () {
28 return zeroFill(func.apply(this, arguments), padded[1], padded[2]);
29 };
30 }
31 if (ordinal) {
32 formatTokenFunctions[ordinal] = function () {
33 return this.localeData().ordinal(
34 func.apply(this, arguments),
35 token
36 );
37 };
38 }
39}
40
41function removeFormattingTokens(input) {
42 if (input.match(/\[[\s\S]/)) {
43 return input.replace(/^\[|\]$/g, '');
44 }
45 return input.replace(/\\/g, '');
46}
47
48function makeFormatFunction(format) {
49 var array = format.match(formattingTokens),
50 i,
51 length;
52
53 for (i = 0, length = array.length; i < length; i++) {
54 if (formatTokenFunctions[array[i]]) {
55 array[i] = formatTokenFunctions[array[i]];
56 } else {
57 array[i] = removeFormattingTokens(array[i]);
58 }
59 }
60
61 return function (mom) {
62 var output = '',
63 i;
64 for (i = 0; i < length; i++) {
65 output += isFunction(array[i])
66 ? array[i].call(mom, format)
67 : array[i];
68 }
69 return output;
70 };
71}
72
73// format date using native date object
74export function formatMoment(m, format) {
75 if (!m.isValid()) {
76 return m.localeData().invalidDate();
77 }
78
79 format = expandFormat(format, m.localeData());
80 formatFunctions[format] =
81 formatFunctions[format] || makeFormatFunction(format);
82
83 return formatFunctions[format](m);
84}
85
86export function expandFormat(format, locale) {
87 var i = 5;
88
89 function replaceLongDateFormatTokens(input) {
90 return locale.longDateFormat(input) || input;
91 }
92
93 localFormattingTokens.lastIndex = 0;
94 while (i >= 0 && localFormattingTokens.test(format)) {
95 format = format.replace(
96 localFormattingTokens,
97 replaceLongDateFormatTokens
98 );
99 localFormattingTokens.lastIndex = 0;
100 i -= 1;
101 }
102
103 return format;
104}