amos-apptool 1.0.5 → 1.2.0
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/esm/index.js +3 -1
- package/esm/math/calendarUtils.js +118 -0
- package/esm/url/restfulUrl.js +36 -3
- package/index.d.ts +279 -0
- package/lib/index.js +22 -8
- package/lib/math/calendarUtils.js +141 -0
- package/lib/url/restfulUrl.js +35 -3
- package/package.json +1 -1
package/esm/index.js
CHANGED
|
@@ -68,6 +68,8 @@ export { default as accMul } from "./math/mul";
|
|
|
68
68
|
|
|
69
69
|
export { default as accDivide } from "./math/divide";
|
|
70
70
|
|
|
71
|
+
export * from "./math/calendarUtils";
|
|
72
|
+
|
|
71
73
|
export { default as encodeUrl } from "./url/encodeUrl";
|
|
72
74
|
|
|
73
|
-
export
|
|
75
|
+
export * from "./url/restfulUrl";
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
const DateHelper = {
|
|
2
|
+
isLeapYear: e => e % 4 == 0 && e % 100 != 0 || e % 400 == 0,
|
|
3
|
+
getWhatDay: (e, t, a) => [ "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" ][new Date(`${e}/${t}/${a}`).getDay()],
|
|
4
|
+
getMonthPreDay(e, t) {
|
|
5
|
+
let a = new Date(`${e}/${t}/01`).getDay();
|
|
6
|
+
return 0 === a && (a = 7), a;
|
|
7
|
+
},
|
|
8
|
+
getMonthDays: (e, t) => (/^0/.test(t) && (t = t.split("")[1]), [ 0, 31, DateHelper.isLeapYear(Number(e)) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ][t]),
|
|
9
|
+
getNumTwoBit: e => ((e = Number(e)) > 9 ? "" : "0") + e,
|
|
10
|
+
date2Str(e, t) {
|
|
11
|
+
t = t || "-";
|
|
12
|
+
return [ e.getFullYear(), DateHelper.getNumTwoBit(e.getMonth() + 1), DateHelper.getNumTwoBit(e.getDate()) ].join(t);
|
|
13
|
+
},
|
|
14
|
+
getDay(e) {
|
|
15
|
+
e = e || 0;
|
|
16
|
+
let t = new Date;
|
|
17
|
+
const a = 864e5 * e;
|
|
18
|
+
return t = new Date(t.getTime() + a), DateHelper.date2Str(t);
|
|
19
|
+
},
|
|
20
|
+
compareDate: (e, t) => !(new Date(e.replace("-", "/").replace("-", "/")) >= new Date(t.replace("-", "/").replace("-", "/"))),
|
|
21
|
+
isEqual: (e, t) => new Date((e || "").replace(/-/g, "/")).getTime() === new Date(t.replace(/-/g, "/")).getTime(),
|
|
22
|
+
getMonthWeek(e, t, a, r = 0) {
|
|
23
|
+
const n = new Date(Number(e), parseInt(t) - 1, Number(a));
|
|
24
|
+
let D = n.getDay();
|
|
25
|
+
const o = n.getDate();
|
|
26
|
+
let g = 6 - D;
|
|
27
|
+
return 0 !== r && (D = 0 === D ? 7 : D, g = 7 - D), Math.ceil((o + g) / 7);
|
|
28
|
+
},
|
|
29
|
+
getYearWeek(e, t, a, r = 0) {
|
|
30
|
+
const n = new Date(Number(e), parseInt(t) - 1, Number(a)), D = new Date(Number(e), 0, 1), o = Math.round((n.valueOf() - D.valueOf()) / 864e5);
|
|
31
|
+
return Math.ceil((o + (D.getDay() + 1 - 1)) / 7);
|
|
32
|
+
},
|
|
33
|
+
getWeekDate(e, t, a, r = 0) {
|
|
34
|
+
const n = new Date(Number(e), parseInt(t) - 1, Number(a)), D = n.getTime();
|
|
35
|
+
let o = n.getDay();
|
|
36
|
+
if (0 === r) {
|
|
37
|
+
const e = 864e5, t = D - o * e, a = D + (6 - o) * e;
|
|
38
|
+
return [ DateHelper.date2Str(new Date(t)), DateHelper.date2Str(new Date(a)) ];
|
|
39
|
+
}
|
|
40
|
+
o = 0 === o ? 7 : o;
|
|
41
|
+
const g = 864e5, l = D - (o - 1) * g, y = D + (7 - o) * g;
|
|
42
|
+
return [ DateHelper.date2Str(new Date(l)), DateHelper.date2Str(new Date(y)) ];
|
|
43
|
+
},
|
|
44
|
+
formatResultDate(e) {
|
|
45
|
+
const t = [ ...e.split("-") ];
|
|
46
|
+
return t[2] = DateHelper.getNumTwoBit(Number(t[2])), t[3] = `${t[0]}-${t[1]}-${t[2]}`,
|
|
47
|
+
t[4] = DateHelper.getWhatDay(+t[0], +t[1], +t[2]), t;
|
|
48
|
+
}
|
|
49
|
+
}, getCurrMonthData = (e, t, a) => {
|
|
50
|
+
switch (e) {
|
|
51
|
+
case "prev":
|
|
52
|
+
1 === a && (t -= 1), a = 1 === a ? 12 : --a;
|
|
53
|
+
break;
|
|
54
|
+
|
|
55
|
+
case "next":
|
|
56
|
+
12 === a && (t += 1), a = 12 === a ? 1 : ++a;
|
|
57
|
+
}
|
|
58
|
+
return [ t, DateHelper.getNumTwoBit(a), DateHelper.getMonthDays(String(t), String(a)) ];
|
|
59
|
+
}, getDaysStatus = (e, t, a) => {
|
|
60
|
+
let r = DateHelper.getMonthDays(`${t}`, `${a}`);
|
|
61
|
+
return "prev" === e && r >= 7 && (r -= 7), Array.from(Array(r), (r, n) => ({
|
|
62
|
+
day: n + 1,
|
|
63
|
+
type: e,
|
|
64
|
+
year: t,
|
|
65
|
+
month: a
|
|
66
|
+
}));
|
|
67
|
+
}, getPreMonthDates = (e, t, a, r) => {
|
|
68
|
+
let n = +a - 1, D = t;
|
|
69
|
+
n <= 0 && (n = 12, D += 1);
|
|
70
|
+
let o = DateHelper.getMonthPreDay(+t, +a);
|
|
71
|
+
o -= r, "prev" === e && o >= 7 && (o -= 7);
|
|
72
|
+
const g = DateHelper.getMonthDays(`${D}`, `${n}`);
|
|
73
|
+
return Array.from(Array(g), (t, a) => ({
|
|
74
|
+
day: a + 1,
|
|
75
|
+
type: e,
|
|
76
|
+
year: D,
|
|
77
|
+
month: n
|
|
78
|
+
})).slice(g - o);
|
|
79
|
+
}, convertDateToDay = e => e ? {
|
|
80
|
+
year: e.getFullYear(),
|
|
81
|
+
month: e.getMonth() + 1,
|
|
82
|
+
date: e.getDate()
|
|
83
|
+
} : null, convertDayToDate = e => e ? new Date(e.year, e.month - 1, e.date) : null, getPrevMonthDays = (e, t, a) => {
|
|
84
|
+
let r = t - 1, n = e;
|
|
85
|
+
r <= 0 && (r = 12, n -= 1);
|
|
86
|
+
let D = DateHelper.getMonthPreDay(e, t);
|
|
87
|
+
D -= a, D >= 7 && (D -= 7);
|
|
88
|
+
const o = DateHelper.getMonthDays(`${n}`, `${r}`);
|
|
89
|
+
return Array.from(Array(o), (e, t) => ({
|
|
90
|
+
type: "prev",
|
|
91
|
+
year: n,
|
|
92
|
+
month: r,
|
|
93
|
+
date: t + 1
|
|
94
|
+
})).slice(o - D);
|
|
95
|
+
}, getCurrentMonthDays = (e, t) => {
|
|
96
|
+
const a = DateHelper.getMonthDays(`${e}`, `${t}`);
|
|
97
|
+
return Array.from(Array(a), (a, r) => ({
|
|
98
|
+
type: "current",
|
|
99
|
+
year: e,
|
|
100
|
+
month: t,
|
|
101
|
+
date: r + 1
|
|
102
|
+
}));
|
|
103
|
+
}, getCurrentWeekDays = (e, t) => {
|
|
104
|
+
const a = new Date(e.year, e.month - 1, e.date), r = (a.getDay() + 7 - t) % 7;
|
|
105
|
+
return [ convertDateToDay(new Date(a.getTime() - 864e5 * r)), convertDateToDay(new Date(a.getTime() + 864e5 * (6 - r))) ];
|
|
106
|
+
}, CalendarUtils = {
|
|
107
|
+
DateHelper: DateHelper,
|
|
108
|
+
getCurrMonthData: getCurrMonthData,
|
|
109
|
+
getDaysStatus: getDaysStatus,
|
|
110
|
+
getPreMonthDates: getPreMonthDates,
|
|
111
|
+
convertDateToDay: convertDateToDay,
|
|
112
|
+
convertDayToDate: convertDayToDate,
|
|
113
|
+
getPrevMonthDays: getPrevMonthDays,
|
|
114
|
+
getCurrentMonthDays: getCurrentMonthDays,
|
|
115
|
+
getCurrentWeekDays: getCurrentWeekDays
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export { CalendarUtils };
|
package/esm/url/restfulUrl.js
CHANGED
|
@@ -1,7 +1,40 @@
|
|
|
1
1
|
import utils from "./../utils";
|
|
2
2
|
|
|
3
|
+
import parseText from "./../parseText";
|
|
4
|
+
|
|
5
|
+
import _trim from "./../_trim";
|
|
6
|
+
|
|
3
7
|
const _regex = /\{\s*([^\|\}]+?)\s*(?:\|([^\}]*))?\s*\}/g;
|
|
4
8
|
|
|
5
|
-
export
|
|
6
|
-
return
|
|
7
|
-
}
|
|
9
|
+
export function restfulUrl(t, r, e) {
|
|
10
|
+
return e || (e = _regex), t.replace ? t.replace(e, (t, e) => utils.isUndefined(r[e]) ? t : r[e]) : t;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const defaultRE = /\{((?:.|\n)+?)\}/g;
|
|
14
|
+
|
|
15
|
+
export function formatUrl(t, r = {}, e) {
|
|
16
|
+
return e || (e = defaultRE), parseText(t, r, e);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function changeParam(t, r) {
|
|
20
|
+
if (!t || utils.isEmpty(r)) return t;
|
|
21
|
+
let e = t;
|
|
22
|
+
return Object.keys(r).forEach(function(t) {
|
|
23
|
+
let i = r[t];
|
|
24
|
+
utils.isUndefined(i) ? i = "" : utils.isArray(i) || utils.isObject(i) && (i = JSON.stringify(i)),
|
|
25
|
+
e = function(t, r, e) {
|
|
26
|
+
const i = r + "=([^&]*)", n = r + "=" + e;
|
|
27
|
+
if (t.match(i)) {
|
|
28
|
+
const e = new RegExp(`(${r}=)([^&]*)`, "gi");
|
|
29
|
+
return t.replace(e, n);
|
|
30
|
+
}
|
|
31
|
+
return t.match("[?]") ? t + "&" + n : t + "?" + n;
|
|
32
|
+
}(e, t, i);
|
|
33
|
+
}), e;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const completePrefix = (t = "", r = "") => {
|
|
37
|
+
if (!t || "" === t) return r;
|
|
38
|
+
return t.endsWith("/") && (t = t.substring(0, t.length - 1)), t = _trim(t), r.startsWith("/") && (r = r.substring(1)),
|
|
39
|
+
[ t, r = (r = _trim(r)).replace(/\/\/+/g, "/") ].join("/");
|
|
40
|
+
};
|
package/index.d.ts
CHANGED
|
@@ -291,6 +291,58 @@ export function encodeUrl(url: string): string;
|
|
|
291
291
|
*/
|
|
292
292
|
export function restfulUrl(url: string, options: {}, regexps: RegExp): string;
|
|
293
293
|
|
|
294
|
+
/**
|
|
295
|
+
* 替换 url 参数。如果url中无指定的参数,则自动追加。
|
|
296
|
+
*
|
|
297
|
+
* 自动将对象中的 undefined 值,转化为 ''。null 值则直接返回 null 字符串。
|
|
298
|
+
*
|
|
299
|
+
* params 参数中的数据格式,建议调用处统一处理为 string 格式。内部仅统一处理 undefined 和 {} 格式。
|
|
300
|
+
* @param href 需要替换参数的 url。为空字符串则直接返回 href
|
|
301
|
+
* @param params 参数对象。为空对象,则直接返回 href。
|
|
302
|
+
* @example
|
|
303
|
+
* // 无参数,自动追加
|
|
304
|
+
* changeParam('a/b/d/g', { a: 1, b: 2, c: 3 }); // 'a/b/d/g?a=1&b=2&c=3'
|
|
305
|
+
* // 更新已有参数的值
|
|
306
|
+
* changeParam('a/b/d/g?a=aa&b=bb&c=cc', { a: 1, b: 2, c: 3 }); // 'a/b/d/g?a=1&b=2&c=3'
|
|
307
|
+
* // url 中无参数 d,自动追加参数
|
|
308
|
+
* changeParam('a/b/d/g?a=aa&b=bb&c=cc', { a: 1, b: 2, c: 3, d: 5 }); // 'a/b/d/g?a=1&b=2&c=3&d=5'
|
|
309
|
+
* // undefined 值转化为 ''
|
|
310
|
+
* changeParam('a/b/d/g', { a: 1, b: 2, c: undefined }); // 'a/b/d/g?a=1&b=2&c='
|
|
311
|
+
* // null 值转化为 'null'
|
|
312
|
+
* changeParam('a/b/d/g', { a: 1, b: null, c: undefined }); // 'a/b/d/g?a=1&b=null&c='
|
|
313
|
+
* // [] 和 {} 值。最好不要给参数中传入 {} 值
|
|
314
|
+
* changeParam('a/b/d/g', { a: { m: 3 }, b: [1,2] }); // a/b/d/g?a={"m":3}&b=1,2
|
|
315
|
+
* // 更换 token={token} 值,注意 原理并不是替换 {token} 值,而是更新 `token=xxx` 值,也就是目标是 `=` 左边的 `key` 与 params 中的 key 匹配
|
|
316
|
+
* changeParam('a/b/d/g?token={token}', { a: 'file', b: [1,2], token: 'mytoken' }); // a/b/d/g?token=mytoken&a=file&b=1,2
|
|
317
|
+
*/
|
|
318
|
+
export function changeParam(href: String, params: Object): String;
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* 格式化url
|
|
322
|
+
* @param {string} targetStr
|
|
323
|
+
* @param {object} dataObj
|
|
324
|
+
* @param {string|RegExp} regexps 可选, default: /\{(.*)\}/g);
|
|
325
|
+
* @example
|
|
326
|
+
* formatUrl('a/{b}/{c}/d',{a: 1, b:2}) // 返回: 'a/1/2/d'
|
|
327
|
+
* formatUrl('a/{{b}}/{{c}}/d',{a: 1, b:2}, /\{\{(.*)\}\}/g) // 返回: 'a/1/2/d'
|
|
328
|
+
*/
|
|
329
|
+
export function formatUrl(targetStr: string, dataObj: {}, regexps: string|RegExp): string;
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* 补全 url
|
|
333
|
+
* @param left 左边通用前缀
|
|
334
|
+
* @param right 右边具体的 url
|
|
335
|
+
* @return
|
|
336
|
+
* @example
|
|
337
|
+
* completePrefix('/aa/', 'b/c/d'); // '/aa/b/c/d'
|
|
338
|
+
* completePrefix('/aa /', ' b/c/d'); // '/aa/b/c/d'
|
|
339
|
+
* completePrefix('aa ', ' b c/d'); // 'aa/b c/d'
|
|
340
|
+
* completePrefix(' aa ', ' b c/d '); // 'aa/b c/d'
|
|
341
|
+
* // 注意,不会自动去除 url 内部的空格,会自动将 url 内部多余的 `/` 去掉
|
|
342
|
+
* completePrefix('// aa /', '/ b c///d /'); // '/ aa/b c/d /'
|
|
343
|
+
*/
|
|
344
|
+
export function completePrefix(left = '', right = ''): string;
|
|
345
|
+
|
|
294
346
|
/**
|
|
295
347
|
*
|
|
296
348
|
* @param str
|
|
@@ -473,6 +525,233 @@ export function accDivide(arg1: Number, arg2: Number, fix?: Number): number;
|
|
|
473
525
|
*/
|
|
474
526
|
export function coinFormat(num: number, precision: number, separator: string, sign: string, unit: string): string | '';
|
|
475
527
|
|
|
528
|
+
// --- 日历工具类
|
|
529
|
+
/**
|
|
530
|
+
* 日期辅助工具类
|
|
531
|
+
*/
|
|
532
|
+
interface DateHelper {
|
|
533
|
+
/**
|
|
534
|
+
* 是否为闰年
|
|
535
|
+
* @param y 年份
|
|
536
|
+
* @return {Boolean} true|false
|
|
537
|
+
*/
|
|
538
|
+
isLeapYear(y: number): boolean;
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* 返回星期数
|
|
542
|
+
* @param year 年
|
|
543
|
+
* @param month 月
|
|
544
|
+
* @param day 日
|
|
545
|
+
* @return {String} 星期名称(如:星期一)
|
|
546
|
+
*/
|
|
547
|
+
getWhatDay(year: number | string, month: number | string, day: number | string): string;
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* 返回上一个月在当前面板中的天数
|
|
551
|
+
* @param year 年
|
|
552
|
+
* @param month 月
|
|
553
|
+
* @return {Number} 天数
|
|
554
|
+
*/
|
|
555
|
+
getMonthPreDay(year: number | string, month: number | string): number;
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* 返回月份天数
|
|
559
|
+
* @param year 年
|
|
560
|
+
* @param month 月
|
|
561
|
+
* @return {Number} 该月份的总天数
|
|
562
|
+
*/
|
|
563
|
+
getMonthDays(year: number | string, month: number | string): number;
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* 补齐数字位数(小于10的数字前面补0)
|
|
567
|
+
* @param n 需要补齐的数字
|
|
568
|
+
* @return {string} 补齐后的两位数字符串
|
|
569
|
+
*/
|
|
570
|
+
getNumTwoBit(n: number | string): string;
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* 日期对象转成字符串
|
|
574
|
+
* @param date 日期对象
|
|
575
|
+
* @param split 分隔符,默认为 '-'
|
|
576
|
+
* @return {string} 格式化后的日期字符串
|
|
577
|
+
*/
|
|
578
|
+
date2Str(date: Date, split?: string): string;
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* 返回日期格式字符串
|
|
582
|
+
* @param i 0返回今天的日期、1返回明天的日期,2返回后天的日期,依次类推,默认0
|
|
583
|
+
* @return {string} '2014-12-31' 格式的日期字符串
|
|
584
|
+
*/
|
|
585
|
+
getDay(i?: number): string;
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* 时间比较(date1 是否早于 date2)
|
|
589
|
+
* @param date1 第一个日期字符串
|
|
590
|
+
* @param date2 第二个日期字符串
|
|
591
|
+
* @return {Boolean} date1 < date2 时返回 true,否则返回 false
|
|
592
|
+
*/
|
|
593
|
+
compareDate(date1: string, date2: string): boolean;
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* 时间是否相等
|
|
597
|
+
* @param date1 第一个日期字符串(可选)
|
|
598
|
+
* @param date2 第二个日期字符串
|
|
599
|
+
* @return {Boolean} 两个日期时间戳相等时返回 true,否则返回 false
|
|
600
|
+
*/
|
|
601
|
+
isEqual(date1?: string, date2: string): boolean;
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* 获取指定日期在当月的周数
|
|
605
|
+
* @param year 年
|
|
606
|
+
* @param month 月
|
|
607
|
+
* @param date 日
|
|
608
|
+
* @param firstDayOfWeek 一周的第一天(0表示周日,默认0)
|
|
609
|
+
* @return {number} 周数
|
|
610
|
+
*/
|
|
611
|
+
getMonthWeek(year: number | string, month: number | string, date: number | string, firstDayOfWeek?: number): number;
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* 获取指定日期在当年的周数
|
|
615
|
+
* @param year 年
|
|
616
|
+
* @param month 月
|
|
617
|
+
* @param date 日
|
|
618
|
+
* @param firstDayOfWeek 一周的第一天(0表示周日,默认0)
|
|
619
|
+
* @return {number} 周数
|
|
620
|
+
*/
|
|
621
|
+
getYearWeek(year: number | string, month: number | string, date: number | string, firstDayOfWeek?: number): number;
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* 获取指定日期所在周的起止日期
|
|
625
|
+
* @param year 年
|
|
626
|
+
* @param month 月
|
|
627
|
+
* @param date 日
|
|
628
|
+
* @param firstDayOfWeek 一周的第一天(0表示周日,默认0)
|
|
629
|
+
* @return {[string, string]} 周起始日期和结束日期组成的数组
|
|
630
|
+
*/
|
|
631
|
+
getWeekDate(year: number | string, month: number | string, date: number | string, firstDayOfWeek?: number): [string, string];
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* 格式化日期结果
|
|
635
|
+
* @param date 日期字符串(格式:yyyy-mm-dd)
|
|
636
|
+
* @return {string[]} 格式化后的日期数组 [年, 月, 日, 完整日期字符串, 星期名称]
|
|
637
|
+
*/
|
|
638
|
+
formatResultDate(date: string): string[];
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* 日期对象转换后的结构
|
|
643
|
+
*/
|
|
644
|
+
interface DayObject {
|
|
645
|
+
year: number;
|
|
646
|
+
month: number;
|
|
647
|
+
date: number;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* 日期状态对象
|
|
652
|
+
*/
|
|
653
|
+
interface DayStatus {
|
|
654
|
+
day: number;
|
|
655
|
+
type: string;
|
|
656
|
+
year: number;
|
|
657
|
+
month: number;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* 面板日期对象
|
|
662
|
+
*/
|
|
663
|
+
interface PanelDate {
|
|
664
|
+
type: string;
|
|
665
|
+
year: number;
|
|
666
|
+
month: number;
|
|
667
|
+
date: number;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* 获取当前月数据
|
|
672
|
+
* @param type 类型:prev(上月)、next(下月)、默认(当月)
|
|
673
|
+
* @param year 年
|
|
674
|
+
* @param month 月
|
|
675
|
+
* @returns [年, 两位数字的月, 该月天数]
|
|
676
|
+
*/
|
|
677
|
+
declare function getCurrMonthData(type: string, year: number, month: number): [number, string, number];
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* 获取日期状态
|
|
681
|
+
* @param type 类型:prev(上月)、next(下月)、current(当月)
|
|
682
|
+
* @param year 年
|
|
683
|
+
* @param month 月
|
|
684
|
+
* @returns 日期状态数组
|
|
685
|
+
*/
|
|
686
|
+
declare function getDaysStatus(type: string, year: number, month: number): DayStatus[];
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* 获取上一个月的最后一周天数,填充当月空白
|
|
690
|
+
* @param type 类型:prev
|
|
691
|
+
* @param year 年
|
|
692
|
+
* @param month 月
|
|
693
|
+
* @param firstDayOfWeek 一周的第一天(0表示周日)
|
|
694
|
+
* @returns 上月填充日期数组
|
|
695
|
+
*/
|
|
696
|
+
declare function getPreMonthDates(type: string, year: number, month: number, firstDayOfWeek: number): DayStatus[];
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* 将日期对象转换为年、月、日结构
|
|
700
|
+
* @param date 日期对象
|
|
701
|
+
* @returns 年、月、日结构对象,date为null时返回null
|
|
702
|
+
*/
|
|
703
|
+
declare function convertDateToDay(date: Date | null): DayObject | null;
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* 将年、月、日结构转换为日期对象
|
|
707
|
+
* @param day 年、月、日结构对象
|
|
708
|
+
* @returns 日期对象,day为null时返回null
|
|
709
|
+
*/
|
|
710
|
+
declare function convertDayToDate(day: DayObject | null): Date | null;
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* 获取当月面板中前一个月的日期数据
|
|
714
|
+
* @param year 年
|
|
715
|
+
* @param month 月
|
|
716
|
+
* @param firstDayOfWeek 一周的第一天(0表示周日)
|
|
717
|
+
* @returns 上月面板日期数组
|
|
718
|
+
*/
|
|
719
|
+
declare function getPrevMonthDays(year: number, month: number, firstDayOfWeek: number): PanelDate[];
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* 获取当前月的日期数据
|
|
723
|
+
* @param year 年
|
|
724
|
+
* @param month 月
|
|
725
|
+
* @returns 当月面板日期数组
|
|
726
|
+
*/
|
|
727
|
+
declare function getCurrentMonthDays(year: number, month: number): PanelDate[];
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* 根据日期获取当前周的起始日期
|
|
731
|
+
* @param day 年、月、日结构对象
|
|
732
|
+
* @param firstDayOfWeek 一周的第一天(0表示周日)
|
|
733
|
+
* @returns [周起始日期, 周结束日期]
|
|
734
|
+
*/
|
|
735
|
+
declare function getCurrentWeekDays(day: DayObject, firstDayOfWeek: number): [DayObject, DayObject];
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* 日历工具类
|
|
739
|
+
*/
|
|
740
|
+
declare const CalendarUtils: {
|
|
741
|
+
DateHelper: DateHelper;
|
|
742
|
+
getCurrMonthData: typeof getCurrMonthData;
|
|
743
|
+
getDaysStatus: typeof getDaysStatus;
|
|
744
|
+
getPreMonthDates: typeof getPreMonthDates;
|
|
745
|
+
convertDateToDay: typeof convertDateToDay;
|
|
746
|
+
convertDayToDate: typeof convertDayToDate;
|
|
747
|
+
getPrevMonthDays: typeof getPrevMonthDays;
|
|
748
|
+
getCurrentMonthDays: typeof getCurrentMonthDays;
|
|
749
|
+
getCurrentWeekDays: typeof getCurrentWeekDays;
|
|
750
|
+
};
|
|
751
|
+
|
|
752
|
+
export { CalendarUtils };
|
|
753
|
+
export type { DayObject, DayStatus, PanelDate, DateHelper };
|
|
754
|
+
|
|
476
755
|
/**
|
|
477
756
|
* dateTime
|
|
478
757
|
*/
|
package/lib/index.js
CHANGED
|
@@ -39,8 +39,7 @@ var _exportNames = {
|
|
|
39
39
|
subtraction: !0,
|
|
40
40
|
accMul: !0,
|
|
41
41
|
accDivide: !0,
|
|
42
|
-
encodeUrl: !0
|
|
43
|
-
restfulUrl: !0
|
|
42
|
+
encodeUrl: !0
|
|
44
43
|
};
|
|
45
44
|
|
|
46
45
|
Object.defineProperty(exports, "Base64", {
|
|
@@ -178,11 +177,6 @@ Object.defineProperty(exports, "Base64", {
|
|
|
178
177
|
get: function() {
|
|
179
178
|
return _randomColor.default;
|
|
180
179
|
}
|
|
181
|
-
}), Object.defineProperty(exports, "restfulUrl", {
|
|
182
|
-
enumerable: !0,
|
|
183
|
-
get: function() {
|
|
184
|
-
return _restfulUrl.default;
|
|
185
|
-
}
|
|
186
180
|
}), Object.defineProperty(exports, "shallowCopy", {
|
|
187
181
|
enumerable: !0,
|
|
188
182
|
get: function() {
|
|
@@ -248,4 +242,24 @@ Object.keys(_shallowEqual).forEach(function(e) {
|
|
|
248
242
|
}));
|
|
249
243
|
});
|
|
250
244
|
|
|
251
|
-
var _strUtils = _interopRequireDefault(require("./strUtils")), _utils = _interopRequireDefault(require("./utils")), _addition = _interopRequireDefault(require("./math/addition")), _amountCase = _interopRequireDefault(require("./math/amountCase")), _coinFormat = _interopRequireDefault(require("./math/coinFormat")), _colorUtil = _interopRequireDefault(require("./math/colorUtil")), _dateTime = _interopRequireDefault(require("./math/dateTime")), _pwdStrength = _interopRequireDefault(require("./math/pwdStrength")), _randomColor = _interopRequireDefault(require("./math/randomColor")), _subtraction = _interopRequireDefault(require("./math/subtraction")), _mul = _interopRequireDefault(require("./math/mul")), _divide = _interopRequireDefault(require("./math/divide")),
|
|
245
|
+
var _strUtils = _interopRequireDefault(require("./strUtils")), _utils = _interopRequireDefault(require("./utils")), _addition = _interopRequireDefault(require("./math/addition")), _amountCase = _interopRequireDefault(require("./math/amountCase")), _coinFormat = _interopRequireDefault(require("./math/coinFormat")), _colorUtil = _interopRequireDefault(require("./math/colorUtil")), _dateTime = _interopRequireDefault(require("./math/dateTime")), _pwdStrength = _interopRequireDefault(require("./math/pwdStrength")), _randomColor = _interopRequireDefault(require("./math/randomColor")), _subtraction = _interopRequireDefault(require("./math/subtraction")), _mul = _interopRequireDefault(require("./math/mul")), _divide = _interopRequireDefault(require("./math/divide")), _calendarUtils = require("./math/calendarUtils");
|
|
246
|
+
|
|
247
|
+
Object.keys(_calendarUtils).forEach(function(e) {
|
|
248
|
+
"default" !== e && "__esModule" !== e && (Object.prototype.hasOwnProperty.call(_exportNames, e) || e in exports && exports[e] === _calendarUtils[e] || Object.defineProperty(exports, e, {
|
|
249
|
+
enumerable: !0,
|
|
250
|
+
get: function() {
|
|
251
|
+
return _calendarUtils[e];
|
|
252
|
+
}
|
|
253
|
+
}));
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
var _encodeUrl = _interopRequireDefault(require("./url/encodeUrl")), _restfulUrl = require("./url/restfulUrl");
|
|
257
|
+
|
|
258
|
+
Object.keys(_restfulUrl).forEach(function(e) {
|
|
259
|
+
"default" !== e && "__esModule" !== e && (Object.prototype.hasOwnProperty.call(_exportNames, e) || e in exports && exports[e] === _restfulUrl[e] || Object.defineProperty(exports, e, {
|
|
260
|
+
enumerable: !0,
|
|
261
|
+
get: function() {
|
|
262
|
+
return _restfulUrl[e];
|
|
263
|
+
}
|
|
264
|
+
}));
|
|
265
|
+
});
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: !0
|
|
7
|
+
}), exports.CalendarUtils = void 0;
|
|
8
|
+
|
|
9
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")), DateHelper = {
|
|
10
|
+
isLeapYear: function(e) {
|
|
11
|
+
return e % 4 == 0 && e % 100 != 0 || e % 400 == 0;
|
|
12
|
+
},
|
|
13
|
+
getWhatDay: function(e, t, r) {
|
|
14
|
+
return [ "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" ][new Date("".concat(e, "/").concat(t, "/").concat(r)).getDay()];
|
|
15
|
+
},
|
|
16
|
+
getMonthPreDay: function(e, t) {
|
|
17
|
+
var r = new Date("".concat(e, "/").concat(t, "/01")).getDay();
|
|
18
|
+
return 0 === r && (r = 7), r;
|
|
19
|
+
},
|
|
20
|
+
getMonthDays: function(e, t) {
|
|
21
|
+
return /^0/.test(t) && (t = t.split("")[1]), [ 0, 31, DateHelper.isLeapYear(Number(e)) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ][t];
|
|
22
|
+
},
|
|
23
|
+
getNumTwoBit: function(e) {
|
|
24
|
+
return ((e = Number(e)) > 9 ? "" : "0") + e;
|
|
25
|
+
},
|
|
26
|
+
date2Str: function(e, t) {
|
|
27
|
+
return t = t || "-", [ e.getFullYear(), DateHelper.getNumTwoBit(e.getMonth() + 1), DateHelper.getNumTwoBit(e.getDate()) ].join(t);
|
|
28
|
+
},
|
|
29
|
+
getDay: function(e) {
|
|
30
|
+
e = e || 0;
|
|
31
|
+
var t = new Date, r = 864e5 * e;
|
|
32
|
+
return t = new Date(t.getTime() + r), DateHelper.date2Str(t);
|
|
33
|
+
},
|
|
34
|
+
compareDate: function(e, t) {
|
|
35
|
+
return !(new Date(e.replace("-", "/").replace("-", "/")) >= new Date(t.replace("-", "/").replace("-", "/")));
|
|
36
|
+
},
|
|
37
|
+
isEqual: function(e, t) {
|
|
38
|
+
return new Date((e || "").replace(/-/g, "/")).getTime() === new Date(t.replace(/-/g, "/")).getTime();
|
|
39
|
+
},
|
|
40
|
+
getMonthWeek: function(e, t, r) {
|
|
41
|
+
var a = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : 0, n = new Date(Number(e), parseInt(t) - 1, Number(r)), o = n.getDay(), u = n.getDate(), D = 6 - o;
|
|
42
|
+
return 0 !== a && (D = 7 - (o = 0 === o ? 7 : o)), Math.ceil((u + D) / 7);
|
|
43
|
+
},
|
|
44
|
+
getYearWeek: function(e, t, r) {
|
|
45
|
+
var a = new Date(Number(e), parseInt(t) - 1, Number(r)), n = new Date(Number(e), 0, 1), o = Math.round((a.valueOf() - n.valueOf()) / 864e5);
|
|
46
|
+
return Math.ceil((o + (n.getDay() + 1 - 1)) / 7);
|
|
47
|
+
},
|
|
48
|
+
getWeekDate: function(e, t, r) {
|
|
49
|
+
var a = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : 0, n = new Date(Number(e), parseInt(t) - 1, Number(r)), o = n.getTime(), u = n.getDay();
|
|
50
|
+
if (0 === a) {
|
|
51
|
+
var D = 864e5, c = o - u * D, i = o + (6 - u) * D;
|
|
52
|
+
return [ DateHelper.date2Str(new Date(c)), DateHelper.date2Str(new Date(i)) ];
|
|
53
|
+
}
|
|
54
|
+
var l = 864e5, g = o - ((u = 0 === u ? 7 : u) - 1) * l, y = o + (7 - u) * l;
|
|
55
|
+
return [ DateHelper.date2Str(new Date(g)), DateHelper.date2Str(new Date(y)) ];
|
|
56
|
+
},
|
|
57
|
+
formatResultDate: function(e) {
|
|
58
|
+
var t = (0, _toConsumableArray2.default)(e.split("-"));
|
|
59
|
+
return t[2] = DateHelper.getNumTwoBit(Number(t[2])), t[3] = "".concat(t[0], "-").concat(t[1], "-").concat(t[2]),
|
|
60
|
+
t[4] = DateHelper.getWhatDay(+t[0], +t[1], +t[2]), t;
|
|
61
|
+
}
|
|
62
|
+
}, getCurrMonthData = function(e, t, r) {
|
|
63
|
+
switch (e) {
|
|
64
|
+
case "prev":
|
|
65
|
+
1 === r && (t -= 1), r = 1 === r ? 12 : --r;
|
|
66
|
+
break;
|
|
67
|
+
|
|
68
|
+
case "next":
|
|
69
|
+
12 === r && (t += 1), r = 12 === r ? 1 : ++r;
|
|
70
|
+
}
|
|
71
|
+
return [ t, DateHelper.getNumTwoBit(r), DateHelper.getMonthDays(String(t), String(r)) ];
|
|
72
|
+
}, getDaysStatus = function(e, t, r) {
|
|
73
|
+
var a = DateHelper.getMonthDays("".concat(t), "".concat(r));
|
|
74
|
+
return "prev" === e && a >= 7 && (a -= 7), Array.from(Array(a), function(a, n) {
|
|
75
|
+
return {
|
|
76
|
+
day: n + 1,
|
|
77
|
+
type: e,
|
|
78
|
+
year: t,
|
|
79
|
+
month: r
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
}, getPreMonthDates = function(e, t, r, a) {
|
|
83
|
+
var n = +r - 1, o = t;
|
|
84
|
+
n <= 0 && (n = 12, o += 1);
|
|
85
|
+
var u = DateHelper.getMonthPreDay(+t, +r);
|
|
86
|
+
u -= a, "prev" === e && u >= 7 && (u -= 7);
|
|
87
|
+
var D = DateHelper.getMonthDays("".concat(o), "".concat(n));
|
|
88
|
+
return Array.from(Array(D), function(t, r) {
|
|
89
|
+
return {
|
|
90
|
+
day: r + 1,
|
|
91
|
+
type: e,
|
|
92
|
+
year: o,
|
|
93
|
+
month: n
|
|
94
|
+
};
|
|
95
|
+
}).slice(D - u);
|
|
96
|
+
}, convertDateToDay = function(e) {
|
|
97
|
+
return e ? {
|
|
98
|
+
year: e.getFullYear(),
|
|
99
|
+
month: e.getMonth() + 1,
|
|
100
|
+
date: e.getDate()
|
|
101
|
+
} : null;
|
|
102
|
+
}, convertDayToDate = function(e) {
|
|
103
|
+
return e ? new Date(e.year, e.month - 1, e.date) : null;
|
|
104
|
+
}, getPrevMonthDays = function(e, t, r) {
|
|
105
|
+
var a = t - 1, n = e;
|
|
106
|
+
a <= 0 && (a = 12, n -= 1);
|
|
107
|
+
var o = DateHelper.getMonthPreDay(e, t);
|
|
108
|
+
(o -= r) >= 7 && (o -= 7);
|
|
109
|
+
var u = DateHelper.getMonthDays("".concat(n), "".concat(a));
|
|
110
|
+
return Array.from(Array(u), function(e, t) {
|
|
111
|
+
return {
|
|
112
|
+
type: "prev",
|
|
113
|
+
year: n,
|
|
114
|
+
month: a,
|
|
115
|
+
date: t + 1
|
|
116
|
+
};
|
|
117
|
+
}).slice(u - o);
|
|
118
|
+
}, getCurrentMonthDays = function(e, t) {
|
|
119
|
+
var r = DateHelper.getMonthDays("".concat(e), "".concat(t));
|
|
120
|
+
return Array.from(Array(r), function(r, a) {
|
|
121
|
+
return {
|
|
122
|
+
type: "current",
|
|
123
|
+
year: e,
|
|
124
|
+
month: t,
|
|
125
|
+
date: a + 1
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
}, getCurrentWeekDays = function(e, t) {
|
|
129
|
+
var r = new Date(e.year, e.month - 1, e.date), a = (r.getDay() + 7 - t) % 7;
|
|
130
|
+
return [ convertDateToDay(new Date(r.getTime() - 864e5 * a)), convertDateToDay(new Date(r.getTime() + 864e5 * (6 - a))) ];
|
|
131
|
+
}, CalendarUtils = exports.CalendarUtils = {
|
|
132
|
+
DateHelper: DateHelper,
|
|
133
|
+
getCurrMonthData: getCurrMonthData,
|
|
134
|
+
getDaysStatus: getDaysStatus,
|
|
135
|
+
getPreMonthDates: getPreMonthDates,
|
|
136
|
+
convertDateToDay: convertDateToDay,
|
|
137
|
+
convertDayToDate: convertDayToDate,
|
|
138
|
+
getPrevMonthDays: getPrevMonthDays,
|
|
139
|
+
getCurrentMonthDays: getCurrentMonthDays,
|
|
140
|
+
getCurrentWeekDays: getCurrentWeekDays
|
|
141
|
+
};
|
package/lib/url/restfulUrl.js
CHANGED
|
@@ -4,12 +4,44 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: !0
|
|
7
|
-
}), exports.
|
|
7
|
+
}), exports.changeParam = changeParam, exports.completePrefix = void 0, exports.formatUrl = formatUrl,
|
|
8
|
+
exports.restfulUrl = restfulUrl;
|
|
8
9
|
|
|
9
|
-
var _utils = _interopRequireDefault(require("./../utils")), _regex = /\{\s*([^\|\}]+?)\s*(?:\|([^\}]*))?\s*\}/g;
|
|
10
|
+
var _utils = _interopRequireDefault(require("./../utils")), _parseText = _interopRequireDefault(require("./../parseText")), _trim2 = _interopRequireDefault(require("./../_trim")), _regex = /\{\s*([^\|\}]+?)\s*(?:\|([^\}]*))?\s*\}/g;
|
|
10
11
|
|
|
11
12
|
function restfulUrl(e, r, t) {
|
|
12
13
|
return t || (t = _regex), e.replace ? e.replace(t, function(e, t) {
|
|
13
14
|
return _utils.default.isUndefined(r[t]) ? e : r[t];
|
|
14
15
|
}) : e;
|
|
15
|
-
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var defaultRE = /\{((?:.|\n)+?)\}/g;
|
|
19
|
+
|
|
20
|
+
function formatUrl(e) {
|
|
21
|
+
var r = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, t = arguments.length > 2 ? arguments[2] : void 0;
|
|
22
|
+
return t || (t = defaultRE), (0, _parseText.default)(e, r, t);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function changeParam(e, r) {
|
|
26
|
+
if (!e || _utils.default.isEmpty(r)) return e;
|
|
27
|
+
var t = e;
|
|
28
|
+
return Object.keys(r).forEach(function(e) {
|
|
29
|
+
var i = r[e];
|
|
30
|
+
_utils.default.isUndefined(i) ? i = "" : _utils.default.isArray(i) || _utils.default.isObject(i) && (i = JSON.stringify(i)),
|
|
31
|
+
t = function(e, r, t) {
|
|
32
|
+
var i = r + "=([^&]*)", u = r + "=" + t;
|
|
33
|
+
if (e.match(i)) {
|
|
34
|
+
var a = new RegExp("(".concat(r, "=)([^&]*)"), "gi");
|
|
35
|
+
return e.replace(a, u);
|
|
36
|
+
}
|
|
37
|
+
return e.match("[?]") ? e + "&" + u : e + "?" + u;
|
|
38
|
+
}(t, e, i);
|
|
39
|
+
}), t;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var completePrefix = exports.completePrefix = function() {
|
|
43
|
+
var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : "", r = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : "";
|
|
44
|
+
return e && "" !== e ? (e.endsWith("/") && (e = e.substring(0, e.length - 1)), e = (0,
|
|
45
|
+
_trim2.default)(e), r.startsWith("/") && (r = r.substring(1)), [ e, r = (r = (0,
|
|
46
|
+
_trim2.default)(r)).replace(/\/\/+/g, "/") ].join("/")) : r;
|
|
47
|
+
};
|