tools-min-ns 1.5.2
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/README.md +85 -0
- package/esm/array/ArrayUtil.d.ts +109 -0
- package/esm/array/ArrayUtil.js +242 -0
- package/esm/array/TreeUtil.d.ts +151 -0
- package/esm/array/TreeUtil.js +412 -0
- package/esm/base/BaseUtil.d.ts +91 -0
- package/esm/base/BaseUtil.js +148 -0
- package/esm/browser/BrowserUtil.d.ts +57 -0
- package/esm/browser/BrowserUtil.js +337 -0
- package/esm/browser/fingerprint.d.ts +120 -0
- package/esm/browser/fingerprint.js +1469 -0
- package/esm/check/CheckUtil.d.ts +110 -0
- package/esm/check/CheckUtil.js +465 -0
- package/esm/common.d.ts +43 -0
- package/esm/common.js +44 -0
- package/esm/config.d.ts +7 -0
- package/esm/config.js +7 -0
- package/esm/cookie/CookieUtil.d.ts +56 -0
- package/esm/cookie/CookieUtil.js +12 -0
- package/esm/cookie/cookie.d.ts +2 -0
- package/esm/cookie/cookie.js +104 -0
- package/esm/date/DateUtil.d.ts +261 -0
- package/esm/date/DateUtil.js +763 -0
- package/esm/env/EnvUtil.d.ts +27 -0
- package/esm/env/EnvUtil.js +29 -0
- package/esm/env/env.d.ts +41 -0
- package/esm/env/env.js +106 -0
- package/esm/func/FunctionUtil.d.ts +77 -0
- package/esm/func/FunctionUtil.js +215 -0
- package/esm/index.d.ts +19 -0
- package/esm/index.js +19 -0
- package/esm/number/NumberUtil.d.ts +96 -0
- package/esm/number/NumberUtil.js +256 -0
- package/esm/object/ObjectUtil.d.ts +41 -0
- package/esm/object/ObjectUtil.js +158 -0
- package/esm/pwd/PasswordUtil.d.ts +33 -0
- package/esm/pwd/PasswordUtil.js +68 -0
- package/esm/pwd/crypto.d.ts +6 -0
- package/esm/pwd/crypto.js +1824 -0
- package/esm/request/RequestUtil.d.ts +52 -0
- package/esm/request/RequestUtil.js +53 -0
- package/esm/request/jsonp.d.ts +18 -0
- package/esm/request/jsonp.js +73 -0
- package/esm/request/mgop/env.d.ts +7 -0
- package/esm/request/mgop/env.js +15 -0
- package/esm/request/mgop/index.d.ts +3 -0
- package/esm/request/mgop/index.js +276 -0
- package/esm/request/mgop/responseCode.d.ts +20 -0
- package/esm/request/mgop/responseCode.js +37 -0
- package/esm/request/mgop/type.d.ts +34 -0
- package/esm/request/mgop/type.js +1 -0
- package/esm/request/uniRquest/index.d.ts +2 -0
- package/esm/request/uniRquest/index.js +66 -0
- package/esm/request/uniRquest/miniapp/index.d.ts +2 -0
- package/esm/request/uniRquest/miniapp/index.js +29 -0
- package/esm/request/uniRquest/miniapp-bytedance/index.d.ts +2 -0
- package/esm/request/uniRquest/miniapp-bytedance/index.js +41 -0
- package/esm/request/uniRquest/types.d.ts +65 -0
- package/esm/request/uniRquest/types.js +36 -0
- package/esm/request/uniRquest/utils.d.ts +9 -0
- package/esm/request/uniRquest/utils.js +69 -0
- package/esm/request/uniRquest/web/index.d.ts +2 -0
- package/esm/request/uniRquest/web/index.js +85 -0
- package/esm/request/uniRquest/wechat-miniprogram/index.d.ts +2 -0
- package/esm/request/uniRquest/wechat-miniprogram/index.js +41 -0
- package/esm/request/uniRquest/weex/index.d.ts +14 -0
- package/esm/request/uniRquest/weex/index.js +59 -0
- package/esm/storage/StorageUtil.d.ts +19 -0
- package/esm/storage/StorageUtil.js +75 -0
- package/esm/string/StringUtil.d.ts +392 -0
- package/esm/string/StringUtil.js +556 -0
- package/esm/system/SystemUtil.d.ts +46 -0
- package/esm/system/SystemUtil.js +122 -0
- package/esm/transfer/MapTransferUtil.d.ts +54 -0
- package/esm/transfer/MapTransferUtil.js +160 -0
- package/esm/transfer/TransferUtil.d.ts +98 -0
- package/esm/transfer/TransferUtil.js +323 -0
- package/esm/types.d.ts +25 -0
- package/esm/types.js +1 -0
- package/esm/url/UrlUtil.d.ts +30 -0
- package/esm/url/UrlUtil.js +85 -0
- package/lib/array/ArrayUtil.d.ts +109 -0
- package/lib/array/ArrayUtil.js +252 -0
- package/lib/array/TreeUtil.d.ts +151 -0
- package/lib/array/TreeUtil.js +422 -0
- package/lib/base/BaseUtil.d.ts +91 -0
- package/lib/base/BaseUtil.js +153 -0
- package/lib/browser/BrowserUtil.d.ts +57 -0
- package/lib/browser/BrowserUtil.js +347 -0
- package/lib/browser/fingerprint.d.ts +120 -0
- package/lib/browser/fingerprint.js +1500 -0
- package/lib/check/CheckUtil.d.ts +110 -0
- package/lib/check/CheckUtil.js +475 -0
- package/lib/common.d.ts +43 -0
- package/lib/common.js +50 -0
- package/lib/config.d.ts +7 -0
- package/lib/config.js +12 -0
- package/lib/cookie/CookieUtil.d.ts +56 -0
- package/lib/cookie/CookieUtil.js +22 -0
- package/lib/cookie/cookie.d.ts +2 -0
- package/lib/cookie/cookie.js +109 -0
- package/lib/date/DateUtil.d.ts +261 -0
- package/lib/date/DateUtil.js +773 -0
- package/lib/env/EnvUtil.d.ts +27 -0
- package/lib/env/EnvUtil.js +39 -0
- package/lib/env/env.d.ts +41 -0
- package/lib/env/env.js +112 -0
- package/lib/func/FunctionUtil.d.ts +77 -0
- package/lib/func/FunctionUtil.js +225 -0
- package/lib/index.d.ts +19 -0
- package/lib/index.js +144 -0
- package/lib/number/NumberUtil.d.ts +96 -0
- package/lib/number/NumberUtil.js +266 -0
- package/lib/object/ObjectUtil.d.ts +41 -0
- package/lib/object/ObjectUtil.js +168 -0
- package/lib/pwd/PasswordUtil.d.ts +33 -0
- package/lib/pwd/PasswordUtil.js +78 -0
- package/lib/pwd/crypto.d.ts +6 -0
- package/lib/pwd/crypto.js +1829 -0
- package/lib/request/RequestUtil.d.ts +52 -0
- package/lib/request/RequestUtil.js +94 -0
- package/lib/request/jsonp.d.ts +18 -0
- package/lib/request/jsonp.js +80 -0
- package/lib/request/mgop/env.d.ts +7 -0
- package/lib/request/mgop/env.js +21 -0
- package/lib/request/mgop/index.d.ts +3 -0
- package/lib/request/mgop/index.js +289 -0
- package/lib/request/mgop/responseCode.d.ts +20 -0
- package/lib/request/mgop/responseCode.js +42 -0
- package/lib/request/mgop/type.d.ts +34 -0
- package/lib/request/mgop/type.js +5 -0
- package/lib/request/uniRquest/index.d.ts +2 -0
- package/lib/request/uniRquest/index.js +77 -0
- package/lib/request/uniRquest/miniapp/index.d.ts +2 -0
- package/lib/request/uniRquest/miniapp/index.js +35 -0
- package/lib/request/uniRquest/miniapp-bytedance/index.d.ts +2 -0
- package/lib/request/uniRquest/miniapp-bytedance/index.js +47 -0
- package/lib/request/uniRquest/types.d.ts +65 -0
- package/lib/request/uniRquest/types.js +42 -0
- package/lib/request/uniRquest/utils.d.ts +9 -0
- package/lib/request/uniRquest/utils.js +83 -0
- package/lib/request/uniRquest/web/index.d.ts +2 -0
- package/lib/request/uniRquest/web/index.js +91 -0
- package/lib/request/uniRquest/wechat-miniprogram/index.d.ts +2 -0
- package/lib/request/uniRquest/wechat-miniprogram/index.js +47 -0
- package/lib/request/uniRquest/weex/index.d.ts +14 -0
- package/lib/request/uniRquest/weex/index.js +65 -0
- package/lib/storage/StorageUtil.d.ts +19 -0
- package/lib/storage/StorageUtil.js +85 -0
- package/lib/string/StringUtil.d.ts +392 -0
- package/lib/string/StringUtil.js +566 -0
- package/lib/system/SystemUtil.d.ts +46 -0
- package/lib/system/SystemUtil.js +132 -0
- package/lib/transfer/MapTransferUtil.d.ts +54 -0
- package/lib/transfer/MapTransferUtil.js +165 -0
- package/lib/transfer/TransferUtil.d.ts +98 -0
- package/lib/transfer/TransferUtil.js +333 -0
- package/lib/types.d.ts +25 -0
- package/lib/types.js +5 -0
- package/lib/url/UrlUtil.d.ts +30 -0
- package/lib/url/UrlUtil.js +95 -0
- package/package.json +56 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
type CookieAttributes = {
|
|
2
|
+
/**
|
|
3
|
+
* 定义删除cookie的时间。值可以是数字,将被解释为从创建时间开始的天数,或者是一个Date实例。如果省略,cookie将变为session cookie。
|
|
4
|
+
*/
|
|
5
|
+
expires?: number | Date | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* 定义cookie可访问的路径。默认值为'/'。
|
|
8
|
+
*/
|
|
9
|
+
path?: string | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* 定义 cookie 可访问的域名。默认值为创建 cookie 的页面所在域名
|
|
12
|
+
*/
|
|
13
|
+
domain?: string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* 一个布尔值,表示是否需要使用安全的传输协议(https)来发送 cookie。默认为 false
|
|
16
|
+
*/
|
|
17
|
+
secure?: boolean | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* 断定一个cookie不能和跨域请求一起发送,这可以在一定程度上防止跨站请求伪造(CSRF)攻击
|
|
20
|
+
*/
|
|
21
|
+
sameSite?: 'strict' | 'Strict' | 'lax' | 'Lax' | 'none' | 'None' | undefined;
|
|
22
|
+
[property: string]: any;
|
|
23
|
+
};
|
|
24
|
+
type CookiesStatic = {
|
|
25
|
+
readonly attributes: CookieAttributes;
|
|
26
|
+
readonly converter: Required<Converter<string>>;
|
|
27
|
+
set(name: string, value: string, options?: CookieAttributes): string | undefined;
|
|
28
|
+
get(name: string): string | undefined;
|
|
29
|
+
get(): {
|
|
30
|
+
[key: string]: string;
|
|
31
|
+
};
|
|
32
|
+
remove(name: string, options?: CookieAttributes): void;
|
|
33
|
+
withAttributes(attributes: CookieAttributes): CookiesStatic;
|
|
34
|
+
withConverter<TConv = string>(converter: Converter<TConv>): CookiesStatic;
|
|
35
|
+
};
|
|
36
|
+
type Converter<TConv> = {
|
|
37
|
+
write?: CookieWriteConverter<TConv> | undefined;
|
|
38
|
+
read?: CookieReadConverter<TConv> | undefined;
|
|
39
|
+
};
|
|
40
|
+
type CookieWriteConverter<T> = (value: string | T, name: string) => string;
|
|
41
|
+
type CookieReadConverter<T> = (value: string, name: string) => string | T;
|
|
42
|
+
declare namespace CookieUtil {
|
|
43
|
+
const set: (name: string, value: string, options?: CookieAttributes | undefined) => string | undefined;
|
|
44
|
+
const get: {
|
|
45
|
+
(name: string): string | undefined;
|
|
46
|
+
(): {
|
|
47
|
+
[key: string]: string;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
const remove: (name: string, options?: CookieAttributes | undefined) => void;
|
|
51
|
+
const withAttributes: (attributes: CookieAttributes) => CookiesStatic;
|
|
52
|
+
const withConverter: <TConv = string>(converter: Converter<TConv>) => CookiesStatic;
|
|
53
|
+
const attributes: CookieAttributes;
|
|
54
|
+
const converter: Required<Converter<string>>;
|
|
55
|
+
}
|
|
56
|
+
export default CookieUtil;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import api from './cookie';
|
|
2
|
+
var CookieUtil;
|
|
3
|
+
(function (CookieUtil) {
|
|
4
|
+
CookieUtil.set = api.set;
|
|
5
|
+
CookieUtil.get = api.get;
|
|
6
|
+
CookieUtil.remove = api.remove;
|
|
7
|
+
CookieUtil.withAttributes = api.withAttributes;
|
|
8
|
+
CookieUtil.withConverter = api.withConverter;
|
|
9
|
+
CookieUtil.attributes = api.attributes;
|
|
10
|
+
CookieUtil.converter = api.converter;
|
|
11
|
+
})(CookieUtil || (CookieUtil = {}));
|
|
12
|
+
export default CookieUtil;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
function init(converter, defaultAttributes) {
|
|
2
|
+
function set(name, value, attributes) {
|
|
3
|
+
var _a;
|
|
4
|
+
if (typeof document === 'undefined') {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
attributes = assign({}, defaultAttributes, attributes);
|
|
8
|
+
if (typeof attributes.expires === 'number') {
|
|
9
|
+
attributes.expires = new Date(Date.now() + attributes.expires * 864e5);
|
|
10
|
+
}
|
|
11
|
+
if (attributes.expires) {
|
|
12
|
+
attributes.expires = attributes.expires.toUTCString();
|
|
13
|
+
}
|
|
14
|
+
name = encodeURIComponent(name).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/[()]/g, escape);
|
|
15
|
+
var stringifiedAttributes = '';
|
|
16
|
+
for (var attributeName in attributes) {
|
|
17
|
+
if (!attributes[attributeName]) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
stringifiedAttributes += '; ' + attributeName;
|
|
21
|
+
if (attributes[attributeName] === true) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
// Considers RFC 6265 section 5.2:
|
|
25
|
+
// ...
|
|
26
|
+
// 3. If the remaining unparsed-attributes contains a %x3B (";")
|
|
27
|
+
// character:
|
|
28
|
+
// Consume the characters of the unparsed-attributes up to,
|
|
29
|
+
// not including, the first %x3B (";") character.
|
|
30
|
+
// ...
|
|
31
|
+
stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
|
|
32
|
+
}
|
|
33
|
+
return document.cookie = name + '=' + ((_a = converter.write) === null || _a === void 0 ? void 0 : _a.call(converter, value, name)) + stringifiedAttributes;
|
|
34
|
+
}
|
|
35
|
+
function get(name) {
|
|
36
|
+
var _a;
|
|
37
|
+
if (typeof document === 'undefined' || arguments.length && !name) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// To prevent the for loop in the first place assign an empty array
|
|
41
|
+
// in case there are no cookies at all.
|
|
42
|
+
var cookies = document.cookie ? document.cookie.split('; ') : [];
|
|
43
|
+
var jar = {};
|
|
44
|
+
for (var i = 0; i < cookies.length; i++) {
|
|
45
|
+
var parts = cookies[i].split('=');
|
|
46
|
+
var value = parts.slice(1).join('=');
|
|
47
|
+
try {
|
|
48
|
+
var found = decodeURIComponent(parts[0]);
|
|
49
|
+
if (!(found in jar)) jar[found] = (_a = converter.read) === null || _a === void 0 ? void 0 : _a.call(converter, value, found);
|
|
50
|
+
if (name === found) {
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
} catch (e) {
|
|
54
|
+
// Do nothing...
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return name ? jar[name] : jar;
|
|
58
|
+
}
|
|
59
|
+
return Object.create({
|
|
60
|
+
set: set,
|
|
61
|
+
get: get,
|
|
62
|
+
remove: function remove(name, attributes) {
|
|
63
|
+
set(name, '', assign({}, attributes, {
|
|
64
|
+
expires: -1
|
|
65
|
+
}));
|
|
66
|
+
},
|
|
67
|
+
withAttributes: function withAttributes(attributes) {
|
|
68
|
+
return init(this.converter, assign({}, this.attributes, attributes));
|
|
69
|
+
},
|
|
70
|
+
withConverter: function withConverter(converter) {
|
|
71
|
+
return init(assign({}, this.converter, converter), this.attributes);
|
|
72
|
+
}
|
|
73
|
+
}, {
|
|
74
|
+
attributes: {
|
|
75
|
+
value: Object.freeze(defaultAttributes)
|
|
76
|
+
},
|
|
77
|
+
converter: {
|
|
78
|
+
value: Object.freeze(converter)
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
var defaultConverter = {
|
|
83
|
+
read: function read(value) {
|
|
84
|
+
if (value[0] === '"') {
|
|
85
|
+
value = value.slice(1, -1);
|
|
86
|
+
}
|
|
87
|
+
return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
|
|
88
|
+
},
|
|
89
|
+
write: function write(value) {
|
|
90
|
+
return encodeURIComponent(value).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g, decodeURIComponent);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
export default init(defaultConverter, {
|
|
94
|
+
path: '/'
|
|
95
|
+
});
|
|
96
|
+
function assign(target) {
|
|
97
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
98
|
+
var source = arguments[i];
|
|
99
|
+
for (var key in source) {
|
|
100
|
+
target[key] = source[key];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return target;
|
|
104
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
export type IDateDiff = {
|
|
2
|
+
year?: number;
|
|
3
|
+
month?: number;
|
|
4
|
+
week?: number;
|
|
5
|
+
day?: number;
|
|
6
|
+
hour?: number;
|
|
7
|
+
minute?: number;
|
|
8
|
+
second?: number;
|
|
9
|
+
millsecond?: number;
|
|
10
|
+
};
|
|
11
|
+
export type DiffDirection = 'BEFORE' | 'AFTER';
|
|
12
|
+
export type TimeDimension = 'YEAR' | 'MONTH' | 'WEEK' | 'DATE' | 'HOUR' | 'MINUTE' | 'SECOND';
|
|
13
|
+
export type IDatePart = {
|
|
14
|
+
Year: number;
|
|
15
|
+
Month: number;
|
|
16
|
+
Date: number;
|
|
17
|
+
Day: number;
|
|
18
|
+
Hour: number;
|
|
19
|
+
Minute: number;
|
|
20
|
+
Second: number;
|
|
21
|
+
Millsecond: number;
|
|
22
|
+
};
|
|
23
|
+
declare namespace DateUtil {
|
|
24
|
+
/**
|
|
25
|
+
* 将 字符串/时间戳 解析成日期对象
|
|
26
|
+
* @param {Date | String | Number} date 输入的日期字符串,如'2014-09-13',或者时间戳
|
|
27
|
+
* @param {String} format 字符串格式,默认'yyyy-MM-dd',支持如下:y、M、d、H、m、s、S
|
|
28
|
+
* @returns {Date} 解析后的Date对象
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* parseDate('2018-11-26'); => new Date(2018, 10, 26)
|
|
32
|
+
* parseDate('11/26/2018', 'MM/dd/yyyy') => new Date(2018, 10, 26)
|
|
33
|
+
* parseDate('2018-11-26 13:28:43', 'yyyy-MM-dd HH:mm:ss') => new Date(2018, 10, 26, 13, 28, 43)
|
|
34
|
+
* parseDate('2018年11月26日', 'yyyy年MM月dd日') => new Date(2018, 10, 26)
|
|
35
|
+
* parseDate('2018年11月26日 11时40分', 'yyyy年MM月dd日 HH时mm分') => new Date(2018, 10, 26, 11, 40)
|
|
36
|
+
*/
|
|
37
|
+
const parseDate: (date: Date | string | number, format?: string) => Date;
|
|
38
|
+
/**
|
|
39
|
+
* 将日期格式化成指定格式的字符串
|
|
40
|
+
* @param {Date | Number | String} date 要格式化的日期,不传时默认当前时间,也可以是一个时间戳/字符串
|
|
41
|
+
* @param {String} format 目标字符串格式,支持的字符有:y,M,d,q,w,H,h,m,S,默认:yyyy-MM-dd HH:mm:ss
|
|
42
|
+
* @returns {String} 返回格式化后的日期字符串,日期不合法时返回字符串 'invalid date'
|
|
43
|
+
* @example
|
|
44
|
+
* formatDate(); => 2016-09-02 13:17:13
|
|
45
|
+
* formatDate('2016-09-02','yyyy年MM月dd日'); => 2016年09月02日
|
|
46
|
+
* formatDate(new Date(), 'yyyy-MM-dd'); => 2016-09-02
|
|
47
|
+
* formatDate(new Date(), 'yyyy-MM-dd 第q季度 www HH:mm:ss:SSS'); => 2016-09-02 第3季度 星期五 13:19:15:792
|
|
48
|
+
* formatDate(1472793615764); => 2016-09-02 13:20:15
|
|
49
|
+
*/
|
|
50
|
+
const formatDate: (date?: Date | number | string, format?: string) => string;
|
|
51
|
+
/**
|
|
52
|
+
* 将一个日期格式化成友好格式,比如,1分钟以内的返回“刚刚”,
|
|
53
|
+
* 当天的返回时分,当年的返回月日,否则,返回年月日
|
|
54
|
+
* @param {Date | number | string} date 如: new Date('2017-11-11')
|
|
55
|
+
* @returns {string} 解析后的友好化日期格式
|
|
56
|
+
* @example
|
|
57
|
+
* formatDateToFriendly() => 刚刚
|
|
58
|
+
*/
|
|
59
|
+
const formatDateToFriendly: (date?: Date | number | string) => string;
|
|
60
|
+
/**
|
|
61
|
+
* 将一个日期格式化成友好格式,比如,当天返回时间,昨天返回 昨天 xx:xx ,本周返回 周x xx:xx 本年 xx月xx日 xx:xx 不是本年 xx年xx月xx日 xx:xx,
|
|
62
|
+
* @param {Date | number | string} date 如: new Date('2017-11-11')
|
|
63
|
+
* @returns {string} 解析后的友好化日期格式
|
|
64
|
+
* @example
|
|
65
|
+
* formatDateToFriendly2() => 2017年11月11日
|
|
66
|
+
*/
|
|
67
|
+
function formatDateToFriendly2(date?: Date | number | string): string;
|
|
68
|
+
/**
|
|
69
|
+
* 判断是否为本周
|
|
70
|
+
* @param date
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
function isCurrentWeek(date?: Date | number): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* 获取日期对应的时间戳
|
|
76
|
+
* @param {Date | String} date 日期对象/日期字符串
|
|
77
|
+
* @param {String} format 字符串模板(date参数为字符串时有效)
|
|
78
|
+
* @returns {Number} 时间戳(单位:毫秒) 如果date参数不合法,则返回-1
|
|
79
|
+
* @example
|
|
80
|
+
* timestamp() => 1610625880136
|
|
81
|
+
*/
|
|
82
|
+
const timestamp: (date?: Date | string, format?: string) => number;
|
|
83
|
+
/**
|
|
84
|
+
* 计算指定日期往前推指定时间
|
|
85
|
+
* @param {Date | string | number} date 初始日期,支持 Date 对象、日期字符串(需配合format参数)、时间戳
|
|
86
|
+
* @param {IDateDiff} diff 日期差值,支持年、月、日、周、时、分、秒、毫秒
|
|
87
|
+
* @param {string} format 日期格式字符串
|
|
88
|
+
* @example
|
|
89
|
+
* dateBefore(new Date(),{year:1}) => Tue Jan 14 2020 20:21:26 GMT+0800 (中国标准时间)
|
|
90
|
+
*/
|
|
91
|
+
const dateBefore: (date: Date | string | number, diff: IDateDiff, format?: string) => Date;
|
|
92
|
+
/**
|
|
93
|
+
* 计算指定日期往后推指定时间
|
|
94
|
+
* @param {Date | string | number} date 初始日期,支持 Date 对象、日期字符串(需配合format参数)、时间戳
|
|
95
|
+
* @param {IDateDiff} diff 日期差值,支持年、月、日、周、时、分、秒、毫秒
|
|
96
|
+
* @param {string} format 日期格式字符串
|
|
97
|
+
* @example
|
|
98
|
+
* dateAfter(new Date(),{year:1}) => Tue Jan 14 2022 20:21:26 GMT+0800 (中国标准时间)
|
|
99
|
+
*/
|
|
100
|
+
const dateAfter: (date: Date | string | number, diff: IDateDiff, format?: string) => Date;
|
|
101
|
+
/**
|
|
102
|
+
* 判断是否为闰年
|
|
103
|
+
* @param {Number} year 年份
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* isLeapYear(1900) = false
|
|
107
|
+
* isLeapYear(2000) = true
|
|
108
|
+
* isLeapYear(2001) = false
|
|
109
|
+
* isLeapYear(2004) = true
|
|
110
|
+
*/
|
|
111
|
+
const isLeapYear: (year: number) => boolean;
|
|
112
|
+
/**
|
|
113
|
+
* 计算在给定的年份中,给定的月份有多少天(会自动判断是否为闰年)
|
|
114
|
+
* @param {Number} year 年份
|
|
115
|
+
* @param {Number} month 月份 (0-11)
|
|
116
|
+
* @example
|
|
117
|
+
* getDaysInMonth(2012,2) => 31
|
|
118
|
+
*/
|
|
119
|
+
const getDaysInMonth: (year: number, month: number) => number;
|
|
120
|
+
/**
|
|
121
|
+
* 获取时间的开头
|
|
122
|
+
* @param date 日期
|
|
123
|
+
* @param mode 时间维度 可以使用 Year Month Day Week Hour Minute Second
|
|
124
|
+
* @param format 字符串模板
|
|
125
|
+
* @example
|
|
126
|
+
* getDateStart(new Date(),'YEAR') => Fri Jan 01 2021 00:00:00 GMT+0800 (中国标准时间)
|
|
127
|
+
*/
|
|
128
|
+
const getDateStart: (date: Date | string | number, mode: TimeDimension, format?: string) => Date;
|
|
129
|
+
/**
|
|
130
|
+
* 获取时间的结尾
|
|
131
|
+
* @param date 日期
|
|
132
|
+
* @param mode 时间维度 可以使用 Year Month Date Week Hour Minute Second
|
|
133
|
+
* @param format 字符串模板
|
|
134
|
+
* @example
|
|
135
|
+
* getDateEnd(new Date(),TimeDimension.Year) => Fri Dec 31 2021 23:59:59 GMT+0800 (中国标准时间)
|
|
136
|
+
*/
|
|
137
|
+
const getDateEnd: (date: Date | string | number, mode: TimeDimension, format?: string) => Date;
|
|
138
|
+
/**
|
|
139
|
+
* 获取给定日期所在当年有多少天
|
|
140
|
+
* @param {Date | String | Number} date 日期
|
|
141
|
+
* @param {String} format 字符串模板
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* getDayOfYear('2018-11-26') => 365
|
|
145
|
+
* getDayOfYear('12/20/2019', 'MM/dd/yyyy') => 365
|
|
146
|
+
* getDayOfYear('2020-12-20') => 366
|
|
147
|
+
*/
|
|
148
|
+
const getDayCountOfYear: (date: Date | string | number, format?: string) => number;
|
|
149
|
+
/**
|
|
150
|
+
* 获取给定日期在当年的第几天
|
|
151
|
+
* @param {Date | String | Number} date 日期
|
|
152
|
+
* @param {String} format 字符串模板
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* getDayIndexOfYear('2017-01-20') => 20
|
|
156
|
+
* getDayIndexOfYear('2018-05-20') => 140
|
|
157
|
+
*/
|
|
158
|
+
const getDayIndexOfYear: (date: Date | string | number, format?: string) => number;
|
|
159
|
+
/**
|
|
160
|
+
* 获取给定日期在当年的第几周
|
|
161
|
+
* @param {Date | String | Number} date 日期
|
|
162
|
+
* @param {String} format 字符串模板
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* getWeekIndexOfYear('2017-01-20') => 3
|
|
166
|
+
* getWeekIndexOfYear('2018-05-20') => 20
|
|
167
|
+
*/
|
|
168
|
+
const getWeekIndexOfYear: (date: Date | string | number, format?: string) => number;
|
|
169
|
+
/**
|
|
170
|
+
* 获取给定日期在当月的第几周
|
|
171
|
+
* @param {Date | String | Number} date 日期
|
|
172
|
+
* @param {String} format 字符串模板
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* getWeekIndexOfMonth('2017-01-20') => 3
|
|
176
|
+
* getWeekIndexOfMonth('2018-05-20') => 3
|
|
177
|
+
*/
|
|
178
|
+
const getWeekIndexOfMonth: (date: Date | string | number, format?: string) => number;
|
|
179
|
+
interface ITimeSpan {
|
|
180
|
+
Day: number;
|
|
181
|
+
Hour: number;
|
|
182
|
+
Minute: number;
|
|
183
|
+
Second: number;
|
|
184
|
+
Millsecond: number;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* 计算两个日期的差
|
|
188
|
+
* @param date1 日期1
|
|
189
|
+
* @param date2 日期2
|
|
190
|
+
* @param format 字符串模板
|
|
191
|
+
* @example
|
|
192
|
+
* getDateDiff('2020-12-12','2021-10-12') => {Day: 304, Hour: 0, Minute: 0, Second: 0, Millsecond: 0}
|
|
193
|
+
*/
|
|
194
|
+
const getDateDiff: (date1: Date | string | number, date2: Date | string | number, format?: string) => ITimeSpan;
|
|
195
|
+
/**
|
|
196
|
+
* 判断给定日期时间是否在某日期时间之前(默认当前日期时间)
|
|
197
|
+
* @param {Date | String | Number} date1 日期时间
|
|
198
|
+
* @param {Date | String | Number} date2 日期时间(默认当前日期时间)
|
|
199
|
+
* @param {String} format 字符串模板
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* isTimeBefore('2017-01-20') => true
|
|
203
|
+
* isTimeBefore('2018-05-20') => true
|
|
204
|
+
*/
|
|
205
|
+
const isTimeBefore: (date1: Date | string, date2?: Date | string, format?: string) => boolean;
|
|
206
|
+
/**
|
|
207
|
+
* 判断给定日期时间是否在某日期时间之后(默认当前日期时间)
|
|
208
|
+
* @param {Date | String | Number} date1 日期时间
|
|
209
|
+
* @param {Date | String | Number} date2 日期时间(默认当前日期时间)
|
|
210
|
+
* @param {String} format 字符串模板
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* isTimeAfter('2017-01-20') => false
|
|
214
|
+
* isTimeAfter('2018-05-20') => false
|
|
215
|
+
*/
|
|
216
|
+
const isTimeAfter: (date1: Date | string, date2?: Date | string, format?: string) => boolean;
|
|
217
|
+
/**
|
|
218
|
+
* 判断给定日期时间是否在时间段内(默认当前日期时间)
|
|
219
|
+
* @param { beginTime: Date | string; endTime: Date | string; time?: Date | string } options
|
|
220
|
+
* @param {String} format 字符串模板
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* const options = {beginTime:'2019-01-01',endTime:'2022-01-01',time:'2021-12-12'}
|
|
224
|
+
* isTimeExist(options) => true
|
|
225
|
+
*/
|
|
226
|
+
const isTimeExist: (options: {
|
|
227
|
+
beginTime: Date | string;
|
|
228
|
+
endTime: Date | string;
|
|
229
|
+
time?: string | Date | undefined;
|
|
230
|
+
}, format?: string) => boolean;
|
|
231
|
+
/**
|
|
232
|
+
* 补全日期区间数组
|
|
233
|
+
* @param {string} day1 '2022-01-01'
|
|
234
|
+
* @param {string} day2 '2022-01-03'
|
|
235
|
+
* @param {string} outFormat "yyyy-MM-dd" 输出的格式
|
|
236
|
+
* @returns ['2022-01-01','2022-01-02','2022-01-03']
|
|
237
|
+
*/
|
|
238
|
+
function getSectionDateList(day1: string, day2: string, outFormat?: string): string[];
|
|
239
|
+
/**
|
|
240
|
+
* 补全月份区间数组
|
|
241
|
+
* @param {string} day1 '2022-01'
|
|
242
|
+
* @param {string} day2 '2022-03'
|
|
243
|
+
* @param {string} outFormat "yyyy-MM" 输出的格式
|
|
244
|
+
* @returns ['2022-01','2022-02','2022-03']
|
|
245
|
+
*/
|
|
246
|
+
const getSectionMonthList: (day1: string, day2: string, outFormat?: string) => string[];
|
|
247
|
+
/**
|
|
248
|
+
* 补全年份区间数组
|
|
249
|
+
* @param {string} day1 '2022'
|
|
250
|
+
* @param {string} day2 '2024'
|
|
251
|
+
* @returns ['2022','2023','2024']
|
|
252
|
+
*/
|
|
253
|
+
const getSectionYearList: (day1: string, day2: string) => string[];
|
|
254
|
+
/**
|
|
255
|
+
* 后端给的时间修复
|
|
256
|
+
* @param t
|
|
257
|
+
* @returns
|
|
258
|
+
*/
|
|
259
|
+
const timeFix: (t?: string) => string | undefined;
|
|
260
|
+
}
|
|
261
|
+
export default DateUtil;
|