@unicom-cloud/utils 0.1.10 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/caseName.js +11 -0
- package/className.js +5 -0
- package/clipboardCopy.js +6 -0
- package/constant.js +4 -0
- package/contentDisposition.js +7 -0
- package/convert-time/index.js +61 -0
- package/convertTime.js +4 -0
- package/cookie.js +7 -0
- package/dayjs.js +5 -0
- package/decimal.js +5 -0
- package/eventEmitter.js +4 -0
- package/file.js +6 -0
- package/filesize.js +8 -0
- package/index.js +38 -30
- package/invariant.js +4 -0
- package/is.js +92 -0
- package/lunar-converter/index.js +641 -0
- package/lunarConverter.js +4 -0
- package/math.js +9 -0
- package/md5.js +4 -0
- package/mock.js +8 -0
- package/normalizeWheel.js +6 -0
- package/number-to-chinese/index.js +72 -0
- package/numberToChinese.js +4 -0
- package/nzh.js +4 -0
- package/object-keys-sort/index.js +7 -0
- package/objectKeysSort.js +2 -5
- package/package.json +1 -1
- package/random.js +15 -0
- package/screenfull.js +4 -0
- package/search-tree/index.js +54 -0
- package/searchTree.js +4 -0
- package/snapdom.js +6 -0
- package/tree.js +11 -0
- package/turboStream.js +6 -0
- package/types/case-name/index.d.ts +11 -0
- package/types/class-name/index.d.ts +2 -0
- package/types/clipboard-copy/index.d.ts +2 -0
- package/types/constant/address.d.ts +14 -0
- package/types/constant/chineseCharacters.d.ts +2 -0
- package/types/constant/constellations.d.ts +2 -0
- package/types/constant/domain.d.ts +2 -0
- package/types/constant/identity.d.ts +2 -0
- package/types/constant/index.d.ts +1 -0
- package/types/constant/keyboardCode.d.ts +158 -0
- package/types/constant/licensePlate.d.ts +2 -0
- package/types/constant/name.d.ts +4 -0
- package/types/constant/platform.d.ts +11 -0
- package/types/constant/protocol.d.ts +2 -0
- package/types/constant/ui.d.ts +14 -0
- package/types/content-disposition/index.d.ts +10 -0
- package/types/convert-time/index.d.ts +32 -0
- package/types/cookie/index.d.ts +4 -0
- package/types/cookie/src/index.d.ts +114 -0
- package/types/dayjs/index.d.ts +1 -0
- package/types/decimal/decimal.d.ts +4 -0
- package/types/decimal/index.d.ts +1 -0
- package/types/event-emitter/index.d.ts +17 -0
- package/types/file/fileToURL.d.ts +2 -0
- package/types/file/index.d.ts +3 -0
- package/types/file/saveAs.d.ts +2 -0
- package/types/filesize/index.d.ts +2 -0
- package/types/filesize/src/constants.d.ts +42 -0
- package/types/filesize/src/filesize.d.ts +47 -0
- package/types/index.d.ts +24 -0
- package/types/invariant/index.d.ts +2 -0
- package/types/is/index.d.ts +53 -0
- package/types/lunar-converter/index.d.ts +113 -0
- package/types/math/index.d.ts +11 -0
- package/types/md5/index.d.ts +2 -0
- package/types/mock/MockWebSocket.d.ts +17 -0
- package/types/mock/MockXMLHttpRequest.d.ts +17 -0
- package/types/mock/index.d.ts +2 -0
- package/types/normalize-wheel/ExecutionEnvironment.d.ts +9 -0
- package/types/normalize-wheel/UserAgent_DEPRECATED.d.ts +86 -0
- package/types/normalize-wheel/index.d.ts +115 -0
- package/types/normalize-wheel/isEventSupported.d.ts +16 -0
- package/types/number-to-chinese/index.d.ts +11 -0
- package/types/nzh/cn.d.ts +8 -0
- package/types/nzh/hk.d.ts +8 -0
- package/types/nzh/index.d.ts +1 -0
- package/types/nzh/nzh.d.ts +36 -0
- package/types/nzh/src/autoGet.d.ts +8 -0
- package/types/nzh/src/index.d.ts +34 -0
- package/types/nzh/src/langs/cn_b.d.ts +10 -0
- package/types/nzh/src/langs/cn_s.d.ts +7 -0
- package/types/nzh/src/langs/hk_b.d.ts +10 -0
- package/types/nzh/src/langs/hk_s.d.ts +7 -0
- package/types/nzh/src/utils.d.ts +65 -0
- package/types/object-keys-sort/index.d.ts +4 -0
- package/types/random/address.d.ts +8 -0
- package/types/random/constellation.d.ts +2 -0
- package/types/random/image.d.ts +5 -0
- package/types/random/index.d.ts +40 -0
- package/types/random/licensePlate.d.ts +2 -0
- package/types/random/name.d.ts +9 -0
- package/types/random/number.d.ts +6 -0
- package/types/random/text.d.ts +13 -0
- package/types/random/time.d.ts +2 -0
- package/types/random/web.d.ts +11 -0
- package/types/screenfull/index.d.ts +10 -0
- package/types/search-tree/index.d.ts +20 -0
- package/types/snapdom/index.d.ts +1 -0
- package/types/snapdom/src/api/preCache.d.ts +8 -0
- package/types/snapdom/src/api/snapdom.d.ts +26 -0
- package/types/snapdom/src/core/cache.d.ts +11 -0
- package/types/snapdom/src/core/capture.d.ts +17 -0
- package/types/snapdom/src/core/clone.d.ts +11 -0
- package/types/snapdom/src/core/prepare.d.ts +8 -0
- package/types/snapdom/src/index.browser.d.ts +1 -0
- package/types/snapdom/src/index.d.ts +2 -0
- package/types/snapdom/src/modules/background.d.ts +10 -0
- package/types/snapdom/src/modules/fonts.d.ts +25 -0
- package/types/snapdom/src/modules/images.d.ts +8 -0
- package/types/snapdom/src/modules/pseudo.d.ts +12 -0
- package/types/snapdom/src/modules/styles.d.ts +10 -0
- package/types/snapdom/src/utils/cssTools.d.ts +38 -0
- package/types/snapdom/src/utils/helpers.d.ts +71 -0
- package/types/tree/index.d.ts +8 -0
- package/types/turbo-stream/index.d.ts +1 -0
- package/types/turbo-stream/src/decode.d.ts +7 -0
- package/types/turbo-stream/src/encode.d.ts +27 -0
- package/types/turbo-stream/src/shared.d.ts +107 -0
- package/types/turbo-stream/src/turbo-stream.d.ts +4 -0
- package/types/url-toolkit/index.d.ts +2 -0
- package/types/url-toolkit/src/url-toolkit.d.ts +18 -0
- package/urlToolkit.js +8 -0
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
class f {
|
|
2
|
+
static MIN = 1900;
|
|
3
|
+
static MAX = 2100;
|
|
4
|
+
// 1900-2100年的完整农历数据表(每个16进制数对应一年的数据)
|
|
5
|
+
static LUNAR_INFO = [
|
|
6
|
+
19416,
|
|
7
|
+
19168,
|
|
8
|
+
42352,
|
|
9
|
+
21717,
|
|
10
|
+
53856,
|
|
11
|
+
55632,
|
|
12
|
+
91476,
|
|
13
|
+
22176,
|
|
14
|
+
39632,
|
|
15
|
+
21970,
|
|
16
|
+
// 1900-1909
|
|
17
|
+
19168,
|
|
18
|
+
42422,
|
|
19
|
+
42192,
|
|
20
|
+
53840,
|
|
21
|
+
119381,
|
|
22
|
+
46400,
|
|
23
|
+
54944,
|
|
24
|
+
44450,
|
|
25
|
+
38320,
|
|
26
|
+
84343,
|
|
27
|
+
// 1910-1919
|
|
28
|
+
18800,
|
|
29
|
+
42160,
|
|
30
|
+
46261,
|
|
31
|
+
27216,
|
|
32
|
+
27968,
|
|
33
|
+
109396,
|
|
34
|
+
11104,
|
|
35
|
+
38256,
|
|
36
|
+
21234,
|
|
37
|
+
18800,
|
|
38
|
+
// 1920-1929
|
|
39
|
+
25958,
|
|
40
|
+
54432,
|
|
41
|
+
59984,
|
|
42
|
+
28309,
|
|
43
|
+
23248,
|
|
44
|
+
11104,
|
|
45
|
+
100067,
|
|
46
|
+
37600,
|
|
47
|
+
116951,
|
|
48
|
+
51536,
|
|
49
|
+
// 1930-1939
|
|
50
|
+
54432,
|
|
51
|
+
120998,
|
|
52
|
+
46416,
|
|
53
|
+
22176,
|
|
54
|
+
107956,
|
|
55
|
+
9680,
|
|
56
|
+
37584,
|
|
57
|
+
53938,
|
|
58
|
+
43344,
|
|
59
|
+
46423,
|
|
60
|
+
// 1940-1949
|
|
61
|
+
27808,
|
|
62
|
+
46416,
|
|
63
|
+
86869,
|
|
64
|
+
19872,
|
|
65
|
+
42416,
|
|
66
|
+
83315,
|
|
67
|
+
21168,
|
|
68
|
+
43432,
|
|
69
|
+
59728,
|
|
70
|
+
27296,
|
|
71
|
+
// 1950-1959
|
|
72
|
+
44710,
|
|
73
|
+
43856,
|
|
74
|
+
19296,
|
|
75
|
+
43748,
|
|
76
|
+
42352,
|
|
77
|
+
21088,
|
|
78
|
+
62051,
|
|
79
|
+
55632,
|
|
80
|
+
23383,
|
|
81
|
+
22176,
|
|
82
|
+
// 1960-1969
|
|
83
|
+
38608,
|
|
84
|
+
19925,
|
|
85
|
+
19152,
|
|
86
|
+
42192,
|
|
87
|
+
54484,
|
|
88
|
+
53840,
|
|
89
|
+
54616,
|
|
90
|
+
46400,
|
|
91
|
+
46752,
|
|
92
|
+
103846,
|
|
93
|
+
// 1970-1979
|
|
94
|
+
38320,
|
|
95
|
+
18864,
|
|
96
|
+
43380,
|
|
97
|
+
42160,
|
|
98
|
+
45690,
|
|
99
|
+
27216,
|
|
100
|
+
27968,
|
|
101
|
+
44870,
|
|
102
|
+
43872,
|
|
103
|
+
38256,
|
|
104
|
+
// 1980-1989
|
|
105
|
+
19189,
|
|
106
|
+
18800,
|
|
107
|
+
25776,
|
|
108
|
+
29859,
|
|
109
|
+
59984,
|
|
110
|
+
27480,
|
|
111
|
+
21952,
|
|
112
|
+
43872,
|
|
113
|
+
38613,
|
|
114
|
+
37600,
|
|
115
|
+
// 1990-1999
|
|
116
|
+
51552,
|
|
117
|
+
55636,
|
|
118
|
+
54432,
|
|
119
|
+
55888,
|
|
120
|
+
30034,
|
|
121
|
+
22176,
|
|
122
|
+
43959,
|
|
123
|
+
9680,
|
|
124
|
+
37584,
|
|
125
|
+
51893,
|
|
126
|
+
// 2000-2009
|
|
127
|
+
43344,
|
|
128
|
+
46240,
|
|
129
|
+
47780,
|
|
130
|
+
44368,
|
|
131
|
+
21977,
|
|
132
|
+
19360,
|
|
133
|
+
42416,
|
|
134
|
+
86390,
|
|
135
|
+
21168,
|
|
136
|
+
43312,
|
|
137
|
+
// 2010-2019
|
|
138
|
+
31060,
|
|
139
|
+
27296,
|
|
140
|
+
44368,
|
|
141
|
+
23378,
|
|
142
|
+
19296,
|
|
143
|
+
42726,
|
|
144
|
+
42208,
|
|
145
|
+
53856,
|
|
146
|
+
60005,
|
|
147
|
+
54576,
|
|
148
|
+
// 2020-2029
|
|
149
|
+
23200,
|
|
150
|
+
30371,
|
|
151
|
+
38608,
|
|
152
|
+
19415,
|
|
153
|
+
19152,
|
|
154
|
+
42192,
|
|
155
|
+
118966,
|
|
156
|
+
53840,
|
|
157
|
+
54560,
|
|
158
|
+
56645,
|
|
159
|
+
// 2030-2039
|
|
160
|
+
46496,
|
|
161
|
+
22224,
|
|
162
|
+
21938,
|
|
163
|
+
18864,
|
|
164
|
+
42359,
|
|
165
|
+
42160,
|
|
166
|
+
43600,
|
|
167
|
+
111189,
|
|
168
|
+
27936,
|
|
169
|
+
44448,
|
|
170
|
+
// 2040-2049
|
|
171
|
+
84835,
|
|
172
|
+
37744,
|
|
173
|
+
18936,
|
|
174
|
+
18800,
|
|
175
|
+
25776,
|
|
176
|
+
92326,
|
|
177
|
+
59984,
|
|
178
|
+
27424,
|
|
179
|
+
108228,
|
|
180
|
+
43744,
|
|
181
|
+
// 2050-2059
|
|
182
|
+
37600,
|
|
183
|
+
53987,
|
|
184
|
+
51552,
|
|
185
|
+
54615,
|
|
186
|
+
54432,
|
|
187
|
+
55888,
|
|
188
|
+
23893,
|
|
189
|
+
22176,
|
|
190
|
+
42704,
|
|
191
|
+
21972,
|
|
192
|
+
// 2060-2069
|
|
193
|
+
21200,
|
|
194
|
+
43448,
|
|
195
|
+
43344,
|
|
196
|
+
46240,
|
|
197
|
+
46758,
|
|
198
|
+
44368,
|
|
199
|
+
21920,
|
|
200
|
+
43940,
|
|
201
|
+
42416,
|
|
202
|
+
21168,
|
|
203
|
+
// 2070-2079
|
|
204
|
+
45683,
|
|
205
|
+
26928,
|
|
206
|
+
29495,
|
|
207
|
+
27296,
|
|
208
|
+
44368,
|
|
209
|
+
84821,
|
|
210
|
+
19296,
|
|
211
|
+
42352,
|
|
212
|
+
21732,
|
|
213
|
+
53600,
|
|
214
|
+
// 2080-2089
|
|
215
|
+
59752,
|
|
216
|
+
54560,
|
|
217
|
+
55968,
|
|
218
|
+
92838,
|
|
219
|
+
22224,
|
|
220
|
+
19168,
|
|
221
|
+
43476,
|
|
222
|
+
41680,
|
|
223
|
+
53584,
|
|
224
|
+
62034,
|
|
225
|
+
// 2090-2099
|
|
226
|
+
54560
|
|
227
|
+
// 2100
|
|
228
|
+
];
|
|
229
|
+
// 24节气名称
|
|
230
|
+
static SOLAR_TERMS = [
|
|
231
|
+
"小寒",
|
|
232
|
+
"大寒",
|
|
233
|
+
"立春",
|
|
234
|
+
"雨水",
|
|
235
|
+
"惊蛰",
|
|
236
|
+
"春分",
|
|
237
|
+
"清明",
|
|
238
|
+
"谷雨",
|
|
239
|
+
"立夏",
|
|
240
|
+
"小满",
|
|
241
|
+
"芒种",
|
|
242
|
+
"夏至",
|
|
243
|
+
"小暑",
|
|
244
|
+
"大暑",
|
|
245
|
+
"立秋",
|
|
246
|
+
"处暑",
|
|
247
|
+
"白露",
|
|
248
|
+
"秋分",
|
|
249
|
+
"寒露",
|
|
250
|
+
"霜降",
|
|
251
|
+
"立冬",
|
|
252
|
+
"小雪",
|
|
253
|
+
"大雪",
|
|
254
|
+
"冬至"
|
|
255
|
+
];
|
|
256
|
+
// 中国传统节日(农历)
|
|
257
|
+
static LUNAR_HOLIDAYS = {
|
|
258
|
+
"1-1": "春节",
|
|
259
|
+
"1-15": "元宵节",
|
|
260
|
+
"5-5": "端午节",
|
|
261
|
+
"7-7": "七夕节",
|
|
262
|
+
"7-15": "中元节",
|
|
263
|
+
"8-15": "中秋节",
|
|
264
|
+
"9-9": "重阳节",
|
|
265
|
+
"12-8": "腊八节",
|
|
266
|
+
"12-23": "小年",
|
|
267
|
+
"12-30": "除夕"
|
|
268
|
+
};
|
|
269
|
+
// 公历节日
|
|
270
|
+
static SOLAR_HOLIDAYS = {
|
|
271
|
+
"1-1": "元旦",
|
|
272
|
+
"2-14": "情人节",
|
|
273
|
+
"3-8": "妇女节",
|
|
274
|
+
"3-12": "植树节",
|
|
275
|
+
"4-5": "清明节",
|
|
276
|
+
"5-1": "劳动节",
|
|
277
|
+
"5-4": "青年节",
|
|
278
|
+
"6-1": "儿童节",
|
|
279
|
+
"7-1": "建党节",
|
|
280
|
+
"8-1": "建军节",
|
|
281
|
+
"9-10": "教师节",
|
|
282
|
+
"10-1": "国庆节",
|
|
283
|
+
"12-25": "圣诞节"
|
|
284
|
+
};
|
|
285
|
+
// 特殊节日(需要计算的)
|
|
286
|
+
static SPECIAL_HOLIDAYS = {
|
|
287
|
+
母亲节: (t) => ({ month: 5, day: this.findNthWeekdayInMonth(t, 5, 0, 2) }),
|
|
288
|
+
父亲节: (t) => ({ month: 6, day: this.findNthWeekdayInMonth(t, 6, 0, 3) }),
|
|
289
|
+
感恩节: (t) => ({ month: 11, day: this.findNthWeekdayInMonth(t, 11, 4, 4) })
|
|
290
|
+
};
|
|
291
|
+
/**
|
|
292
|
+
* 查找某月中第N个星期X的日期
|
|
293
|
+
* @param year 年份
|
|
294
|
+
* @param month 月份(1-12)
|
|
295
|
+
* @param weekday 星期几(0-6,0表示周日)
|
|
296
|
+
* @param nth 第几个(1-5)
|
|
297
|
+
* @returns 日期
|
|
298
|
+
*/
|
|
299
|
+
static findNthWeekdayInMonth(t, s, a, o) {
|
|
300
|
+
const e = new Date(t, s - 1, 1);
|
|
301
|
+
let r = 0;
|
|
302
|
+
for (; e.getDay() !== a; )
|
|
303
|
+
e.setDate(e.getDate() + 1);
|
|
304
|
+
for (; r < o - 1; ) {
|
|
305
|
+
if (e.setDate(e.getDate() + 7), e.getMonth() !== s - 1)
|
|
306
|
+
return -1;
|
|
307
|
+
r++;
|
|
308
|
+
}
|
|
309
|
+
return e.getDate();
|
|
310
|
+
}
|
|
311
|
+
// 天干
|
|
312
|
+
static GAN = [
|
|
313
|
+
"甲",
|
|
314
|
+
"乙",
|
|
315
|
+
"丙",
|
|
316
|
+
"丁",
|
|
317
|
+
"戊",
|
|
318
|
+
"己",
|
|
319
|
+
"庚",
|
|
320
|
+
"辛",
|
|
321
|
+
"壬",
|
|
322
|
+
"癸"
|
|
323
|
+
];
|
|
324
|
+
// 地支
|
|
325
|
+
static ZHI = [
|
|
326
|
+
"子",
|
|
327
|
+
"丑",
|
|
328
|
+
"寅",
|
|
329
|
+
"卯",
|
|
330
|
+
"辰",
|
|
331
|
+
"巳",
|
|
332
|
+
"午",
|
|
333
|
+
"未",
|
|
334
|
+
"申",
|
|
335
|
+
"酉",
|
|
336
|
+
"戌",
|
|
337
|
+
"亥"
|
|
338
|
+
];
|
|
339
|
+
// 生肖
|
|
340
|
+
static ZODIAC = [
|
|
341
|
+
"鼠",
|
|
342
|
+
"牛",
|
|
343
|
+
"虎",
|
|
344
|
+
"兔",
|
|
345
|
+
"龙",
|
|
346
|
+
"蛇",
|
|
347
|
+
"马",
|
|
348
|
+
"羊",
|
|
349
|
+
"猴",
|
|
350
|
+
"鸡",
|
|
351
|
+
"狗",
|
|
352
|
+
"猪"
|
|
353
|
+
];
|
|
354
|
+
// 中文数字
|
|
355
|
+
static CHINESE_NUMBERS = [
|
|
356
|
+
"零",
|
|
357
|
+
"一",
|
|
358
|
+
"二",
|
|
359
|
+
"三",
|
|
360
|
+
"四",
|
|
361
|
+
"五",
|
|
362
|
+
"六",
|
|
363
|
+
"七",
|
|
364
|
+
"八",
|
|
365
|
+
"九",
|
|
366
|
+
"十"
|
|
367
|
+
];
|
|
368
|
+
// 农历日中文表示
|
|
369
|
+
static CHINESE_DAY_NAMES = [
|
|
370
|
+
"初一",
|
|
371
|
+
"初二",
|
|
372
|
+
"初三",
|
|
373
|
+
"初四",
|
|
374
|
+
"初五",
|
|
375
|
+
"初六",
|
|
376
|
+
"初七",
|
|
377
|
+
"初八",
|
|
378
|
+
"初九",
|
|
379
|
+
"初十",
|
|
380
|
+
"十一",
|
|
381
|
+
"十二",
|
|
382
|
+
"十三",
|
|
383
|
+
"十四",
|
|
384
|
+
"十五",
|
|
385
|
+
"十六",
|
|
386
|
+
"十七",
|
|
387
|
+
"十八",
|
|
388
|
+
"十九",
|
|
389
|
+
"二十",
|
|
390
|
+
"廿一",
|
|
391
|
+
"廿二",
|
|
392
|
+
"廿三",
|
|
393
|
+
"廿四",
|
|
394
|
+
"廿五",
|
|
395
|
+
"廿六",
|
|
396
|
+
"廿七",
|
|
397
|
+
"廿八",
|
|
398
|
+
"廿九",
|
|
399
|
+
"三十"
|
|
400
|
+
];
|
|
401
|
+
// 农历月中文表示
|
|
402
|
+
static CHINESE_MONTH_NAMES = [
|
|
403
|
+
"正月",
|
|
404
|
+
"二月",
|
|
405
|
+
"三月",
|
|
406
|
+
"四月",
|
|
407
|
+
"五月",
|
|
408
|
+
"六月",
|
|
409
|
+
"七月",
|
|
410
|
+
"八月",
|
|
411
|
+
"九月",
|
|
412
|
+
"十月",
|
|
413
|
+
"十一月",
|
|
414
|
+
"腊月"
|
|
415
|
+
];
|
|
416
|
+
// 自定义节日存储
|
|
417
|
+
static customSolarHolidays = {};
|
|
418
|
+
static customLunarHolidays = {};
|
|
419
|
+
/**
|
|
420
|
+
* 添加自定义公历节日
|
|
421
|
+
* @param month 月份(1-12)
|
|
422
|
+
* @param day 日期
|
|
423
|
+
* @param name 节日名称
|
|
424
|
+
*/
|
|
425
|
+
static addCustomSolarHoliday(t, s, a) {
|
|
426
|
+
const o = `${t}-${s}`;
|
|
427
|
+
this.customSolarHolidays[o] = a;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* 添加自定义农历节日
|
|
431
|
+
* @param month 月份(1-12)
|
|
432
|
+
* @param day 日期
|
|
433
|
+
* @param name 节日名称
|
|
434
|
+
*/
|
|
435
|
+
static addCustomLunarHoliday(t, s, a) {
|
|
436
|
+
const o = `${t}-${s}`;
|
|
437
|
+
this.customLunarHolidays[o] = a;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* 移除自定义公历节日
|
|
441
|
+
* @param month 月份(1-12)
|
|
442
|
+
* @param day 日期
|
|
443
|
+
*/
|
|
444
|
+
static removeCustomSolarHoliday(t, s) {
|
|
445
|
+
const a = `${t}-${s}`;
|
|
446
|
+
delete this.customSolarHolidays[a];
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* 移除自定义农历节日
|
|
450
|
+
* @param month 月份(1-12)
|
|
451
|
+
* @param day 日期
|
|
452
|
+
*/
|
|
453
|
+
static removeCustomLunarHoliday(t, s) {
|
|
454
|
+
const a = `${t}-${s}`;
|
|
455
|
+
delete this.customLunarHolidays[a];
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* 公历转农历(主方法)
|
|
459
|
+
* @param year 公历年份
|
|
460
|
+
* @param month 公历月份(1-12)
|
|
461
|
+
* @param day 公历日期(1-31)
|
|
462
|
+
* @returns 农历日期对象
|
|
463
|
+
*/
|
|
464
|
+
static solarToLunar(t, s, a) {
|
|
465
|
+
if (t < f.MIN || t > f.MAX)
|
|
466
|
+
throw new Error("农历转换仅支持1900-2700年之间的日期");
|
|
467
|
+
const o = new Date(t, s - 1, a), e = new Date(f.MIN, 0, 31), r = Math.floor(
|
|
468
|
+
(o.getTime() - e.getTime()) / 864e5
|
|
469
|
+
);
|
|
470
|
+
let h = f.MIN, I = this.getLunarYearDays(h), l = 0;
|
|
471
|
+
for (; r >= l + I && h < f.MAX; )
|
|
472
|
+
l += I, h++, I = this.getLunarYearDays(h);
|
|
473
|
+
const c = this.getLunarMonthInfo(h);
|
|
474
|
+
let u = r - l, i = 1, n = !1;
|
|
475
|
+
for (const [N, M] of c) {
|
|
476
|
+
if (u < N) {
|
|
477
|
+
M && (n = !0);
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
u -= N, M || i++;
|
|
481
|
+
}
|
|
482
|
+
const d = u + 1, S = this.dayToChinese(d), A = this.monthToChinese(i, n), y = this.getSolarTerm(t, s, a), D = this.getFestivals(
|
|
483
|
+
t,
|
|
484
|
+
s,
|
|
485
|
+
a,
|
|
486
|
+
h,
|
|
487
|
+
i,
|
|
488
|
+
d,
|
|
489
|
+
n,
|
|
490
|
+
y
|
|
491
|
+
);
|
|
492
|
+
return {
|
|
493
|
+
year: h,
|
|
494
|
+
month: i,
|
|
495
|
+
day: d,
|
|
496
|
+
chineseMonth: A,
|
|
497
|
+
chineseDay: S,
|
|
498
|
+
isLeapMonth: n,
|
|
499
|
+
zodiac: this.getZodiac(h),
|
|
500
|
+
ganZhiYear: this.getGanZhi(h),
|
|
501
|
+
solarTerm: y,
|
|
502
|
+
festivals: D
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* 获取所有节日(农历、公历和自定义节日)
|
|
507
|
+
*/
|
|
508
|
+
static getFestivals(t, s, a, o, e, r, h, I) {
|
|
509
|
+
const l = [], c = /* @__PURE__ */ new Set(), u = `${s}-${a}`;
|
|
510
|
+
if (this.SOLAR_HOLIDAYS[u]) {
|
|
511
|
+
const i = this.SOLAR_HOLIDAYS[u];
|
|
512
|
+
c.has(i) || (l.push(i), c.add(i));
|
|
513
|
+
}
|
|
514
|
+
if (this.customSolarHolidays[u]) {
|
|
515
|
+
const i = this.customSolarHolidays[u];
|
|
516
|
+
c.has(i) || (l.push(i), c.add(i));
|
|
517
|
+
}
|
|
518
|
+
if (!h) {
|
|
519
|
+
const i = `${e}-${r}`;
|
|
520
|
+
if (this.LUNAR_HOLIDAYS[i]) {
|
|
521
|
+
const n = this.LUNAR_HOLIDAYS[i];
|
|
522
|
+
c.has(n) || (l.push(n), c.add(n));
|
|
523
|
+
}
|
|
524
|
+
if (this.customLunarHolidays[i]) {
|
|
525
|
+
const n = this.customLunarHolidays[i];
|
|
526
|
+
c.has(n) || (l.push(n), c.add(n));
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
if (I === "清明") {
|
|
530
|
+
const i = "清明节";
|
|
531
|
+
c.has(i) || (l.push(i), c.add(i));
|
|
532
|
+
}
|
|
533
|
+
if (e === 12) {
|
|
534
|
+
const i = this.getLunarMonthDays(o, 12);
|
|
535
|
+
if (r === i) {
|
|
536
|
+
const n = "除夕";
|
|
537
|
+
c.has(n) || (l.push(n), c.add(n));
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
for (const [i, n] of Object.entries(this.SPECIAL_HOLIDAYS)) {
|
|
541
|
+
const d = n(t);
|
|
542
|
+
s === d.month && a === d.day && (c.has(i) || (l.push(i), c.add(i)));
|
|
543
|
+
}
|
|
544
|
+
return l;
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* 获取农历年的总天数
|
|
548
|
+
*/
|
|
549
|
+
static getLunarYearDays(t) {
|
|
550
|
+
const s = this.LUNAR_INFO[t - f.MIN];
|
|
551
|
+
let a = 0;
|
|
552
|
+
for (let e = 32768; e > 8; e >>= 1)
|
|
553
|
+
a += s & e ? 30 : 29;
|
|
554
|
+
return this.getLeapMonth(t) > 0 && (a += s & 65536 ? 30 : 29), a;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* 获取农历每月的天数信息
|
|
558
|
+
*/
|
|
559
|
+
static getLunarMonthInfo(t) {
|
|
560
|
+
const s = this.LUNAR_INFO[t - f.MIN], a = this.getLeapMonth(t), o = [];
|
|
561
|
+
for (let e = 1; e <= 12; e++) {
|
|
562
|
+
const r = s & 32768 >> e - 1 ? 30 : 29;
|
|
563
|
+
if (o.push([r, !1]), e === a) {
|
|
564
|
+
const h = s & 65536 ? 30 : 29;
|
|
565
|
+
o.push([h, !0]);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
return o;
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* 获取闰月月份(没有闰月返回0)
|
|
572
|
+
*/
|
|
573
|
+
static getLeapMonth(t) {
|
|
574
|
+
return this.LUNAR_INFO[t - f.MIN] & 15;
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* 获取节气
|
|
578
|
+
*/
|
|
579
|
+
static getSolarTerm(t, s, a) {
|
|
580
|
+
const o = [
|
|
581
|
+
[6, "小寒"],
|
|
582
|
+
[20, "大寒"],
|
|
583
|
+
[4, "立春"],
|
|
584
|
+
[19, "雨水"],
|
|
585
|
+
[6, "惊蛰"],
|
|
586
|
+
[21, "春分"],
|
|
587
|
+
[5, "清明"],
|
|
588
|
+
[20, "谷雨"],
|
|
589
|
+
[6, "立夏"],
|
|
590
|
+
[21, "小满"],
|
|
591
|
+
[6, "芒种"],
|
|
592
|
+
[21, "夏至"],
|
|
593
|
+
[7, "小暑"],
|
|
594
|
+
[23, "大暑"],
|
|
595
|
+
[7, "立秋"],
|
|
596
|
+
[23, "处暑"],
|
|
597
|
+
[8, "白露"],
|
|
598
|
+
[23, "秋分"],
|
|
599
|
+
[8, "寒露"],
|
|
600
|
+
[24, "霜降"],
|
|
601
|
+
[7, "立冬"],
|
|
602
|
+
[22, "小雪"],
|
|
603
|
+
[7, "大雪"],
|
|
604
|
+
[22, "冬至"]
|
|
605
|
+
], e = (s - 1) * 2 + (a > 15 ? 1 : 0);
|
|
606
|
+
return e >= 0 && e < o.length && a === o[e][0] ? o[e][1] : null;
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* 获取农历月份的天数
|
|
610
|
+
*/
|
|
611
|
+
static getLunarMonthDays(t, s) {
|
|
612
|
+
return this.LUNAR_INFO[t - f.MIN] & 32768 >> s - 1 ? 30 : 29;
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* 数字日期转中文
|
|
616
|
+
*/
|
|
617
|
+
static dayToChinese(t) {
|
|
618
|
+
return t < 1 || t > 30 ? "未知" : this.CHINESE_DAY_NAMES[t - 1];
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* 数字月份转中文(处理闰月)
|
|
622
|
+
*/
|
|
623
|
+
static monthToChinese(t, s) {
|
|
624
|
+
return t < 1 || t > 12 ? "未知" : (s ? "闰" : "") + this.CHINESE_MONTH_NAMES[t - 1];
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* 获取生肖
|
|
628
|
+
*/
|
|
629
|
+
static getZodiac(t) {
|
|
630
|
+
return this.ZODIAC[(t - 4) % 12];
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* 获取天干地支
|
|
634
|
+
*/
|
|
635
|
+
static getGanZhi(t) {
|
|
636
|
+
return this.GAN[(t - 4) % 10] + this.ZHI[(t - 4) % 12];
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
export {
|
|
640
|
+
f as default
|
|
641
|
+
};
|
package/math.js
ADDED
package/md5.js
ADDED
package/mock.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MockWebSocket as o, WebSocketNative as c } from "./mock/MockWebSocket.js";
|
|
2
|
+
import { MockXMLHttpRequest as p, XMLHttpRequestNative as r } from "./mock/MockXMLHttpRequest.js";
|
|
3
|
+
export {
|
|
4
|
+
o as MockWebSocket,
|
|
5
|
+
p as MockXMLHttpRequest,
|
|
6
|
+
c as WebSocketNative,
|
|
7
|
+
r as XMLHttpRequestNative
|
|
8
|
+
};
|