ph-utils 0.2.23 → 0.3.1
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/LICENSE +21 -0
- package/README.md +11 -11
- package/lib/date.d.ts +55 -34
- package/lib/date.js +203 -126
- package/lib/dom.d.ts +92 -92
- package/lib/dom.js +190 -190
- package/lib/file.d.ts +31 -34
- package/lib/file.js +96 -99
- package/lib/index.d.ts +97 -61
- package/lib/index.js +171 -96
- package/lib/server.d.ts +32 -39
- package/lib/server.js +77 -93
- package/lib/validator.d.ts +47 -47
- package/lib/validator.js +212 -215
- package/lib/web.d.ts +13 -55
- package/lib/web.js +57 -141
- package/package.json +10 -9
- package/lib/date_m.d.ts +0 -34
- package/lib/date_m.js +0 -119
- package/lib/index_m.d.ts +0 -61
- package/lib/index_m.js +0 -82
- package/lib/validator_m.d.ts +0 -47
- package/lib/validator_m.js +0 -210
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 Tenny
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
## ph-utils
|
2
|
-
|
3
|
-
整理了 js 前后端开发(web + nodejs)时常用的一些工具;[详细文档](https://gitee.com/towardly/ph/wikis/Home?sort_id=4035190)
|
4
|
-
|
5
|
-
### 后端(node server)
|
6
|
-
|
7
|
-
包含了一些 node 后端开发(web server) 时常用的工具类,包括 `index` 基础工具类(这个类里面的函数同样也适用于前端)、`date` 跟日期相关的工具类、`file` 文件操作相关工具类、`server` 一些只适用于后端的工具(使用了后端的 API 列表)、`validator` 数据验证
|
8
|
-
|
9
|
-
### 前端(web)
|
10
|
-
|
11
|
-
包含了一些前端网站开发时常用的工具类,包括 `index` 基础工具类(这个类里面的函数同样也适用于前端)、`date` 跟日期相关的工具类、`dom` 浏览器节点操作相关、`web` 一些只适用于前端相关的工具、`validator` 数据验证
|
1
|
+
## ph-utils
|
2
|
+
|
3
|
+
整理了 js 前后端开发(web + nodejs)时常用的一些工具;[详细文档](https://gitee.com/towardly/ph/wikis/Home?sort_id=4035190)
|
4
|
+
|
5
|
+
### 后端(node server)
|
6
|
+
|
7
|
+
包含了一些 node 后端开发(web server) 时常用的工具类,包括 `index` 基础工具类(这个类里面的函数同样也适用于前端)、`date` 跟日期相关的工具类、`file` 文件操作相关工具类、`server` 一些只适用于后端的工具(使用了后端的 API 列表)、`validator` 数据验证
|
8
|
+
|
9
|
+
### 前端(web)
|
10
|
+
|
11
|
+
包含了一些前端网站开发时常用的工具类,包括 `index` 基础工具类(这个类里面的函数同样也适用于前端)、`date` 跟日期相关的工具类、`dom` 浏览器节点操作相关、`web` 一些只适用于前端相关的工具、`validator` 数据验证
|
package/lib/date.d.ts
CHANGED
@@ -1,34 +1,55 @@
|
|
1
|
-
/**
|
2
|
-
* 将日期格式化为指定形式的字符串
|
3
|
-
* @param date 日期
|
4
|
-
* @param pattern 格式化字符串 yyyy - 年, mm - 月, dd - 日, HH - 小时, MM - 分钟, ss - 秒
|
5
|
-
*/
|
6
|
-
export declare function format(date?: Date | string | number, pattern?: string): string;
|
7
|
-
/**
|
8
|
-
* 将指定的参数解析为日期对象(Date)
|
9
|
-
* 参考 dayjs 实现, 也可以参考 https://github.com/nomiddlename/date-format
|
10
|
-
* @param date 待解析的日期参数
|
11
|
-
*/
|
12
|
-
export declare function parse(date?: Date | string | number): Date;
|
13
|
-
/**
|
14
|
-
* 设置日期的开始或者结束的点
|
15
|
-
* @param {Object} date 日期,能够被 parse 解析的日期
|
16
|
-
* @param {String} unit 单位,
|
17
|
-
* @param {Boolean} isEnd true则为 endOf
|
18
|
-
*/
|
19
|
-
export declare function
|
20
|
-
/**
|
21
|
-
*
|
22
|
-
* @param date
|
23
|
-
* @param
|
24
|
-
* @
|
25
|
-
*/
|
26
|
-
export declare function
|
27
|
-
/**
|
28
|
-
*
|
29
|
-
* @param date
|
30
|
-
* @param
|
31
|
-
* @
|
32
|
-
|
33
|
-
|
34
|
-
|
1
|
+
/**
|
2
|
+
* 将日期格式化为指定形式的字符串
|
3
|
+
* @param date 日期
|
4
|
+
* @param pattern 格式化字符串 yyyy - 年, mm - 月, dd - 日, HH - 小时, MM - 分钟, ss - 秒
|
5
|
+
*/
|
6
|
+
export declare function format(date?: Date | string | number, pattern?: string): string;
|
7
|
+
/**
|
8
|
+
* 将指定的参数解析为日期对象(Date)
|
9
|
+
* 参考 dayjs 实现, 也可以参考 https://github.com/nomiddlename/date-format
|
10
|
+
* @param date 待解析的日期参数
|
11
|
+
*/
|
12
|
+
export declare function parse(date?: Date | string | number): Date;
|
13
|
+
/**
|
14
|
+
* 设置日期的开始或者结束的点
|
15
|
+
* @param {Object} date 日期,能够被 parse 解析的日期
|
16
|
+
* @param {String} unit 单位,Date|date, 默认为 Date
|
17
|
+
* @param {Boolean} isEnd true则为 endOf
|
18
|
+
*/
|
19
|
+
export declare function dateOf(date?: Date | string | number, unit?: string, isEnd?: boolean): Date;
|
20
|
+
/**
|
21
|
+
* 设置日期的开始的点
|
22
|
+
* @param date 日期,能够被 parse 解析的日期
|
23
|
+
* @param unit 单位,Date|date, 默认为 Date
|
24
|
+
* @returns
|
25
|
+
*/
|
26
|
+
export declare function startOf(date?: Date | string | number, unit?: string): Date;
|
27
|
+
/**
|
28
|
+
* 设置日期的结束点
|
29
|
+
* @param date 日期,能够被 parse 解析的日期
|
30
|
+
* @param unit 单位,Date|date, 默认为 Date
|
31
|
+
* @returns
|
32
|
+
*/
|
33
|
+
export declare function endOf(date?: Date | string | number, unit?: string): Date;
|
34
|
+
/**
|
35
|
+
* 获取时间戳
|
36
|
+
* @param ctime 时间
|
37
|
+
* @param unit 时间戳长度
|
38
|
+
* @returns
|
39
|
+
*/
|
40
|
+
export declare function timeStamp(ctime?: Date | string | number, unit?: 's' | 'ms'): number;
|
41
|
+
/**
|
42
|
+
* 日期加上指定时间后的日期
|
43
|
+
* @param date 指定的日期
|
44
|
+
* @param num 需要添加的数字, 如果这个参数传递一个小于0的数字,则就是日期减去相应的数字
|
45
|
+
* @param unit 需要添加的单位,date - 加减天数
|
46
|
+
*/
|
47
|
+
export declare function add(date: Date | string | number | null, num: number, unit: string): Date;
|
48
|
+
/**
|
49
|
+
* 日期加上指定时间后的日期
|
50
|
+
* @param date 指定的日期, 传递为 null ,则表示为当前日期
|
51
|
+
* @param num 需要添加的数字, 如果这个参数传递一个小于0的数字,则就是日期减去相应的数字
|
52
|
+
* @param unit 需要添加的单位,date - 加减天数
|
53
|
+
* @param fmt 如果传递了格式化的单位,则返回格式化后的日期, 格式化字符串 yyyy - 年, mm - 月, dd - 日, HH - 小时, MM - 分钟, ss - 秒
|
54
|
+
*/
|
55
|
+
export declare function add(date: Date | string | number | null, num: number, unit: string, fmt: string): string;
|
package/lib/date.js
CHANGED
@@ -1,126 +1,203 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
const
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
let
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
*
|
68
|
-
* @param date
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
*
|
106
|
-
*
|
107
|
-
* @
|
108
|
-
*/
|
109
|
-
function
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
1
|
+
/**
|
2
|
+
* node 和 web 端日期处理工具类
|
3
|
+
*/
|
4
|
+
// 配置日期格式的正则表达式
|
5
|
+
const REGEX_FORMAT = /yy(?:yy)?|([HMmds])\1?/g;
|
6
|
+
// 由于 Date.parse() 不能正确解析 yyyy-dd-mm 格式的日期, 所以匹配手动解析
|
7
|
+
const REGEX_PARSE = /^(\d{4})-?(\d{1,2})-?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?.?(\d{1,3})?$/;
|
8
|
+
const ofArgs = {
|
9
|
+
start: [0, 0, 1, 0, 0, 0, 0],
|
10
|
+
end: [0, 11, -2, 23, 59, 59, 999],
|
11
|
+
};
|
12
|
+
const units = {
|
13
|
+
Date: ['date', 'Date', 'day', 'Day', 'D', 'd'],
|
14
|
+
Month: ['Month', 'month', 'm'],
|
15
|
+
Year: ['Year', 'year', 'y'],
|
16
|
+
Hours: ['Hours', 'hours', 'H'],
|
17
|
+
Minutes: ['Minutes', 'Minute', 'minute', 'minutes', 'M'],
|
18
|
+
Seconds: ['Seconds', 'seconds', 'Second', 'second', 's'],
|
19
|
+
Milliseconds: ['Milliseconds', 'Millisecond', 'milliseconds', 'illisecond', 'S'],
|
20
|
+
};
|
21
|
+
/**
|
22
|
+
* 不足位数, 前位补 0
|
23
|
+
* @param s 日期数字
|
24
|
+
* @param l 截取位数
|
25
|
+
* @returns {string} 补0后的日期数字
|
26
|
+
*/
|
27
|
+
function p(s, l = 2) {
|
28
|
+
/*
|
29
|
+
* 由于年份最多为4为,所以前面先添3个0
|
30
|
+
* slice() 从后开始提前字符串
|
31
|
+
*/
|
32
|
+
return ('000' + s).slice(l * -1);
|
33
|
+
}
|
34
|
+
/**
|
35
|
+
* 将单位转换为首字母大写, 例如:hours -> Hours
|
36
|
+
* @param unit hours
|
37
|
+
* @returns
|
38
|
+
*/
|
39
|
+
function getUnit(unit) {
|
40
|
+
let period = null;
|
41
|
+
for (let [key, value] of Object.entries(units)) {
|
42
|
+
if (value.includes(unit)) {
|
43
|
+
period = key;
|
44
|
+
break;
|
45
|
+
}
|
46
|
+
}
|
47
|
+
if (period == null) {
|
48
|
+
throw new Error(`Invalid unit: ${unit}`);
|
49
|
+
}
|
50
|
+
return period;
|
51
|
+
}
|
52
|
+
/**
|
53
|
+
* 获取指定日期某个月的最后一天
|
54
|
+
* @param date 日期
|
55
|
+
* @param month 月份, 如果不传, 则当前月的最后一天
|
56
|
+
* @returns
|
57
|
+
*/
|
58
|
+
function getLastDayOfYear(date, month) {
|
59
|
+
// 获取下个月的第一天
|
60
|
+
const lastDate = new Date(date.getFullYear(), (month || date.getMonth()) + 1, 1);
|
61
|
+
// 将下个月的第一天的日期减去一天,得到当前月的最后一天
|
62
|
+
lastDate.setDate(lastDate.getDate() - 1);
|
63
|
+
// 返回最后一天的日期
|
64
|
+
return lastDate.getDate();
|
65
|
+
}
|
66
|
+
/**
|
67
|
+
* 将日期格式化为指定形式的字符串
|
68
|
+
* @param date 日期
|
69
|
+
* @param pattern 格式化字符串 yyyy - 年, mm - 月, dd - 日, HH - 小时, MM - 分钟, ss - 秒
|
70
|
+
*/
|
71
|
+
export function format(date, pattern = 'yyyy-mm-dd HH:MM') {
|
72
|
+
// eslint-disable-next-line
|
73
|
+
date = parse(date);
|
74
|
+
let d = date.getDate();
|
75
|
+
let y = date.getFullYear();
|
76
|
+
let m = date.getMonth();
|
77
|
+
let H = date.getHours();
|
78
|
+
let M = date.getMinutes();
|
79
|
+
let s = date.getSeconds();
|
80
|
+
let flags = {
|
81
|
+
yy: p(y),
|
82
|
+
yyyy: y,
|
83
|
+
m: m + 1,
|
84
|
+
mm: p(m + 1),
|
85
|
+
d: d,
|
86
|
+
dd: p(d),
|
87
|
+
H: H,
|
88
|
+
HH: p(H),
|
89
|
+
M: M,
|
90
|
+
MM: p(M),
|
91
|
+
s: s,
|
92
|
+
ss: p(s),
|
93
|
+
};
|
94
|
+
if (pattern != null) {
|
95
|
+
return pattern.replace(REGEX_FORMAT, (flag) => {
|
96
|
+
if (flag in flags) {
|
97
|
+
return flags[flag];
|
98
|
+
}
|
99
|
+
return flag;
|
100
|
+
});
|
101
|
+
}
|
102
|
+
return String(date.getTime());
|
103
|
+
}
|
104
|
+
/**
|
105
|
+
* 将指定的参数解析为日期对象(Date)
|
106
|
+
* 参考 dayjs 实现, 也可以参考 https://github.com/nomiddlename/date-format
|
107
|
+
* @param date 待解析的日期参数
|
108
|
+
*/
|
109
|
+
export function parse(date) {
|
110
|
+
if (date == null)
|
111
|
+
return new Date();
|
112
|
+
if (date instanceof Date)
|
113
|
+
return date;
|
114
|
+
if (typeof date === 'string' && !/Z$/i.test(date)) {
|
115
|
+
const d = date.match(REGEX_PARSE);
|
116
|
+
if (d) {
|
117
|
+
return new Date(d[1], d[2] - 1, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, d[7] || 0);
|
118
|
+
}
|
119
|
+
}
|
120
|
+
if (typeof date === 'number') {
|
121
|
+
return new Date(date <= 9999999999 ? date * 1000 : date);
|
122
|
+
}
|
123
|
+
return new Date();
|
124
|
+
}
|
125
|
+
/**
|
126
|
+
* 设置日期的开始或者结束的点
|
127
|
+
* @param {Object} date 日期,能够被 parse 解析的日期
|
128
|
+
* @param {String} unit 单位,Date|date, 默认为 Date
|
129
|
+
* @param {Boolean} isEnd true则为 endOf
|
130
|
+
*/
|
131
|
+
export function dateOf(date, unit, isEnd = false) {
|
132
|
+
/* 如果是设置某一天的开始时刻, 就需要将时、分、秒、毫秒设置为0,依次类推设置 */
|
133
|
+
const periods = ['Year', 'Month', 'Date', 'Hours', 'Minutes', 'Seconds', 'Milliseconds'];
|
134
|
+
let index = periods.indexOf(getUnit(unit || 'Date'));
|
135
|
+
const clone = parse(date);
|
136
|
+
index++;
|
137
|
+
const setValues = ofArgs[isEnd === true ? 'end' : 'start'];
|
138
|
+
for (const len = periods.length; index < len; index++) {
|
139
|
+
let value = setValues[index];
|
140
|
+
if (value === -2) {
|
141
|
+
// 设置为某个月的最后一天的日期
|
142
|
+
value = getLastDayOfYear(clone);
|
143
|
+
}
|
144
|
+
Date.prototype['set' + periods[index]].apply(clone, [setValues[index]]);
|
145
|
+
}
|
146
|
+
return clone;
|
147
|
+
}
|
148
|
+
/**
|
149
|
+
* 设置日期的开始的点
|
150
|
+
* @param date 日期,能够被 parse 解析的日期
|
151
|
+
* @param unit 单位,Date|date, 默认为 Date
|
152
|
+
* @returns
|
153
|
+
*/
|
154
|
+
export function startOf(date, unit) {
|
155
|
+
return dateOf(date, unit);
|
156
|
+
}
|
157
|
+
/**
|
158
|
+
* 设置日期的结束点
|
159
|
+
* @param date 日期,能够被 parse 解析的日期
|
160
|
+
* @param unit 单位,Date|date, 默认为 Date
|
161
|
+
* @returns
|
162
|
+
*/
|
163
|
+
export function endOf(date, unit) {
|
164
|
+
return dateOf(date, unit, true);
|
165
|
+
}
|
166
|
+
/**
|
167
|
+
* 获取时间戳
|
168
|
+
* @param ctime 时间
|
169
|
+
* @param unit 时间戳长度
|
170
|
+
* @returns
|
171
|
+
*/
|
172
|
+
export function timeStamp(ctime, unit = 's') {
|
173
|
+
let tm = parse(ctime).getTime();
|
174
|
+
return unit === 's' ? Math.floor(tm / 1000) : tm;
|
175
|
+
}
|
176
|
+
/**
|
177
|
+
* 日期加上指定时间后的日期
|
178
|
+
* @param date 指定的日期
|
179
|
+
* @param num 需要添加的数字, 如果这个参数传递一个小于0的数字,则就是日期减去相应的数字
|
180
|
+
* @param unit 需要添加的单位,date - 加减天数
|
181
|
+
* @param fmt 可选参数,如果传递了格式化的单位,则返回格式化后的日期, 格式化字符串 yyyy - 年, mm - 月, dd - 日, HH - 小时, MM - 分钟, ss - 秒
|
182
|
+
* @returns {Date | string} 如果传递了 fmt 参数,则返回 string,否则返回 Date
|
183
|
+
*/
|
184
|
+
export function add(date, num, unit, fmt) {
|
185
|
+
let sdate = new Date();
|
186
|
+
if (date != null) {
|
187
|
+
sdate = parse(date);
|
188
|
+
}
|
189
|
+
// eslint-disable-next-line
|
190
|
+
unit = getUnit(unit);
|
191
|
+
let fn = 'set' + unit;
|
192
|
+
let gn = 'get' + unit;
|
193
|
+
// @ts-ignore
|
194
|
+
let oldValue = Date.prototype[gn].apply(sdate);
|
195
|
+
// @ts-ignore
|
196
|
+
Date.prototype[fn].apply(sdate, [oldValue + num]);
|
197
|
+
if (typeof fmt === 'string') {
|
198
|
+
return format(sdate, fmt);
|
199
|
+
}
|
200
|
+
else {
|
201
|
+
return sdate;
|
202
|
+
}
|
203
|
+
}
|
package/lib/dom.d.ts
CHANGED
@@ -1,92 +1,92 @@
|
|
1
|
-
/**
|
2
|
-
* 根据选择器获取节点
|
3
|
-
* @param {string} selector 选择器
|
4
|
-
*/
|
5
|
-
export declare function elem(selector: string | HTMLElement, dom?: HTMLElement): NodeListOf<HTMLElement> | HTMLElement[];
|
6
|
-
/**
|
7
|
-
* 为节点添加 class
|
8
|
-
* @param {HTMLElement} elem 待添加 class 的节点
|
9
|
-
* @param {string} clazz 需要添加的 class
|
10
|
-
*/
|
11
|
-
export declare function addClass(elem: HTMLElement, clazz: string): void;
|
12
|
-
/**
|
13
|
-
* 节点移除 class
|
14
|
-
* @param {HTMLElement} elem 待移除 class 的节点
|
15
|
-
* @param {string} clazz 需要移除的 class
|
16
|
-
*/
|
17
|
-
export declare function removeClass(elem: HTMLElement, clazz: string): void;
|
18
|
-
/**
|
19
|
-
* 判断节点是否包含某个 class
|
20
|
-
* @param elem 待判断 class 的节点
|
21
|
-
* @param clazz 待判断的 class
|
22
|
-
* @returns
|
23
|
-
*/
|
24
|
-
export declare function hasClass(elem: HTMLElement, clazz: string): boolean;
|
25
|
-
/**
|
26
|
-
* 为节点添加 transition 属性,包括浏览器前缀
|
27
|
-
* @param {HTMLElement} element 需要添加 css Transition 属性的节点
|
28
|
-
* @param {string} value css transition 值
|
29
|
-
*/
|
30
|
-
export declare function transition(element: HTMLElement, value: string): void;
|
31
|
-
/**
|
32
|
-
* 为节点添加 transform 属性,包括浏览器前缀
|
33
|
-
* @param {HTMLElement} element 需要添加 css transform 属性的节点
|
34
|
-
* @param {string} value css transform 值
|
35
|
-
*/
|
36
|
-
export declare function transform(element: HTMLElement, value: string): void;
|
37
|
-
/**
|
38
|
-
* 为节点添加事件处理
|
39
|
-
* @param {HTMLElement} element 添加事件的节点
|
40
|
-
* @param {string} listener 事件名称
|
41
|
-
* @param {function} event 事件处理函数
|
42
|
-
* @param {boolean} onceOrConfig 是否是只运行一次的处理函数或者配置,其中 eventFlag 为 string,如果配置该项,则表明为委托事件
|
43
|
-
*/
|
44
|
-
export declare function on<T extends Event>(element: HTMLElement, listener: string, fn: (e: T, target?: HTMLElement, flag?: string) => void, once?: boolean | {
|
45
|
-
once?: boolean;
|
46
|
-
eventFlag?: string;
|
47
|
-
eventStop?: boolean;
|
48
|
-
}): void;
|
49
|
-
/**
|
50
|
-
* 设置或获取节点的 innerHTML 属性
|
51
|
-
* @param element
|
52
|
-
* @param htmlstr 可选,如果传递该参数,则表示设置;否则表示获取
|
53
|
-
* @returns
|
54
|
-
*/
|
55
|
-
export declare function html(element: HTMLElement, htmlstr?: string): string;
|
56
|
-
/**
|
57
|
-
* 设置或获取节点的 textContent 属性
|
58
|
-
* @param element
|
59
|
-
* @param textstr 可选,如果传递该参数,则表示设置;否则表示获取
|
60
|
-
* @returns
|
61
|
-
*/
|
62
|
-
export declare function text(element: HTMLElement, textstr?: string): string;
|
63
|
-
/**
|
64
|
-
* 节点列表遍历
|
65
|
-
* @param elems
|
66
|
-
* @param fn 遍历到节点时的回调,回调第一个参数为遍历到的节点,第2个参数为 index;如果回调函数返回 true,则会终止遍历(break)
|
67
|
-
*/
|
68
|
-
export declare function iterate(elems: NodeList | HTMLElement[], fn: (el: HTMLElement, index: number) => any): void;
|
69
|
-
/**
|
70
|
-
* 设置或获取节点 data-* 属性
|
71
|
-
* @param elem
|
72
|
-
* @param key data- 后面跟随的值
|
73
|
-
* @param value 如果传递该值表示获取;否则表示设置
|
74
|
-
* @returns
|
75
|
-
*/
|
76
|
-
export declare function attr(elem: HTMLElement, key: string, value?: string): string;
|
77
|
-
/**
|
78
|
-
* 获取指定节点的父节点
|
79
|
-
* @param el
|
80
|
-
* @returns
|
81
|
-
*/
|
82
|
-
export declare function parent(el: HTMLElement): HTMLElement;
|
83
|
-
/**
|
84
|
-
* 获取隐藏节点的尺寸
|
85
|
-
* @param {string | HTMLElement} hideNode - The node to hide.
|
86
|
-
* @param parent - 添加临时节点的父节点,默认为: body.
|
87
|
-
* @returns The DOMRect of the element.
|
88
|
-
*/
|
89
|
-
export declare function queryHideNodeSize(hideNode: string | HTMLElement, parent?: HTMLElement): {
|
90
|
-
width: number;
|
91
|
-
height: number;
|
92
|
-
};
|
1
|
+
/**
|
2
|
+
* 根据选择器获取节点
|
3
|
+
* @param {string} selector 选择器
|
4
|
+
*/
|
5
|
+
export declare function elem(selector: string | HTMLElement, dom?: HTMLElement): NodeListOf<HTMLElement> | HTMLElement[];
|
6
|
+
/**
|
7
|
+
* 为节点添加 class
|
8
|
+
* @param {HTMLElement} elem 待添加 class 的节点
|
9
|
+
* @param {string} clazz 需要添加的 class
|
10
|
+
*/
|
11
|
+
export declare function addClass(elem: HTMLElement, clazz: string): void;
|
12
|
+
/**
|
13
|
+
* 节点移除 class
|
14
|
+
* @param {HTMLElement} elem 待移除 class 的节点
|
15
|
+
* @param {string} clazz 需要移除的 class
|
16
|
+
*/
|
17
|
+
export declare function removeClass(elem: HTMLElement, clazz: string): void;
|
18
|
+
/**
|
19
|
+
* 判断节点是否包含某个 class
|
20
|
+
* @param elem 待判断 class 的节点
|
21
|
+
* @param clazz 待判断的 class
|
22
|
+
* @returns
|
23
|
+
*/
|
24
|
+
export declare function hasClass(elem: HTMLElement, clazz: string): boolean;
|
25
|
+
/**
|
26
|
+
* 为节点添加 transition 属性,包括浏览器前缀
|
27
|
+
* @param {HTMLElement} element 需要添加 css Transition 属性的节点
|
28
|
+
* @param {string} value css transition 值
|
29
|
+
*/
|
30
|
+
export declare function transition(element: HTMLElement, value: string): void;
|
31
|
+
/**
|
32
|
+
* 为节点添加 transform 属性,包括浏览器前缀
|
33
|
+
* @param {HTMLElement} element 需要添加 css transform 属性的节点
|
34
|
+
* @param {string} value css transform 值
|
35
|
+
*/
|
36
|
+
export declare function transform(element: HTMLElement, value: string): void;
|
37
|
+
/**
|
38
|
+
* 为节点添加事件处理
|
39
|
+
* @param {HTMLElement} element 添加事件的节点
|
40
|
+
* @param {string} listener 事件名称
|
41
|
+
* @param {function} event 事件处理函数
|
42
|
+
* @param {boolean} onceOrConfig 是否是只运行一次的处理函数或者配置,其中 eventFlag 为 string,如果配置该项,则表明为委托事件
|
43
|
+
*/
|
44
|
+
export declare function on<T extends Event>(element: HTMLElement, listener: string, fn: (e: T, target?: HTMLElement, flag?: string) => void, once?: boolean | {
|
45
|
+
once?: boolean;
|
46
|
+
eventFlag?: string;
|
47
|
+
eventStop?: boolean;
|
48
|
+
}): void;
|
49
|
+
/**
|
50
|
+
* 设置或获取节点的 innerHTML 属性
|
51
|
+
* @param element
|
52
|
+
* @param htmlstr 可选,如果传递该参数,则表示设置;否则表示获取
|
53
|
+
* @returns
|
54
|
+
*/
|
55
|
+
export declare function html(element: HTMLElement, htmlstr?: string): string | undefined;
|
56
|
+
/**
|
57
|
+
* 设置或获取节点的 textContent 属性
|
58
|
+
* @param element
|
59
|
+
* @param textstr 可选,如果传递该参数,则表示设置;否则表示获取
|
60
|
+
* @returns
|
61
|
+
*/
|
62
|
+
export declare function text(element: HTMLElement, textstr?: string): string | null | undefined;
|
63
|
+
/**
|
64
|
+
* 节点列表遍历
|
65
|
+
* @param elems
|
66
|
+
* @param fn 遍历到节点时的回调,回调第一个参数为遍历到的节点,第2个参数为 index;如果回调函数返回 true,则会终止遍历(break)
|
67
|
+
*/
|
68
|
+
export declare function iterate(elems: NodeList | HTMLElement[], fn: (el: HTMLElement, index: number) => any): void;
|
69
|
+
/**
|
70
|
+
* 设置或获取节点 data-* 属性
|
71
|
+
* @param elem
|
72
|
+
* @param key data- 后面跟随的值
|
73
|
+
* @param value 如果传递该值表示获取;否则表示设置
|
74
|
+
* @returns
|
75
|
+
*/
|
76
|
+
export declare function attr(elem: HTMLElement, key: string, value?: string): string | null | undefined;
|
77
|
+
/**
|
78
|
+
* 获取指定节点的父节点
|
79
|
+
* @param el
|
80
|
+
* @returns
|
81
|
+
*/
|
82
|
+
export declare function parent(el: HTMLElement): HTMLElement;
|
83
|
+
/**
|
84
|
+
* 获取隐藏节点的尺寸
|
85
|
+
* @param {string | HTMLElement} hideNode - The node to hide.
|
86
|
+
* @param parent - 添加临时节点的父节点,默认为: body.
|
87
|
+
* @returns The DOMRect of the element.
|
88
|
+
*/
|
89
|
+
export declare function queryHideNodeSize(hideNode: string | HTMLElement, parent?: HTMLElement): {
|
90
|
+
width: number;
|
91
|
+
height: number;
|
92
|
+
};
|