mazey 3.3.10 → 3.3.12
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 +349 -120
- package/examples/index.ts +3 -1
- package/lib/index.cjs.js +2 -2
- package/lib/index.d.ts +358 -47
- package/lib/index.d.ts.map +1 -1
- package/lib/index.esm.js +2 -2
- package/lib/mazey.min.js +2 -2
- package/package.json +2 -1
- package/scripts/build-helper.js +42 -0
- package/scripts/dev.js +4 -3
- package/scripts/github-helper.js +16 -12
- package/src/index.ts +402 -53
package/lib/index.d.ts
CHANGED
|
@@ -1,37 +1,91 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* EN: Computes the longest common substring of two strings.
|
|
3
|
+
*
|
|
4
|
+
* ZH: 计算两个字符串的最长公共子串
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
*
|
|
8
|
+
* ```
|
|
9
|
+
* calLongestCommonSubstring('fish', 'finish');
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Output:
|
|
13
|
+
*
|
|
14
|
+
* ```
|
|
15
|
+
* 3
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
4
18
|
* @param {string} aStr String
|
|
5
19
|
* @param {string} bStr String
|
|
6
20
|
* @returns {number} Length
|
|
7
21
|
*/
|
|
8
22
|
export declare function calLongestCommonSubstring(aStr: string, bStr: string): number;
|
|
9
23
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
24
|
+
* EN: Computes the longest common subsequence of two strings.
|
|
25
|
+
*
|
|
26
|
+
* ZH: 计算两个字符串的最长公共子序列
|
|
27
|
+
*
|
|
28
|
+
* Usage:
|
|
29
|
+
*
|
|
30
|
+
* ```
|
|
31
|
+
* calLongestCommonSubsequence('fish', 'finish');
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* Output:
|
|
35
|
+
*
|
|
36
|
+
* ```
|
|
37
|
+
* 4
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
12
40
|
* @param {string} aStr 字符串
|
|
13
41
|
* @param {string} bStr 字符串
|
|
14
42
|
* @returns {number} 长度
|
|
15
43
|
*/
|
|
16
44
|
export declare function calLongestCommonSubsequence(aStr: string, bStr: string): number;
|
|
17
45
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
46
|
+
* Get the query param's value of the current Web URL(`location.search`).
|
|
47
|
+
*
|
|
48
|
+
* ```
|
|
49
|
+
* // http://example.com/?t1=1&t2=2&t3=3&t4=4#2333
|
|
50
|
+
* // ?t1=1&t2=2&t3=3&t4=4
|
|
51
|
+
* getQueryParam('t3'); // 3
|
|
52
|
+
* getQueryParam('t4'); // 4
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
20
55
|
* @param {string} param Query param.
|
|
21
56
|
* @returns {string} value
|
|
22
57
|
*/
|
|
23
58
|
export declare function getQueryParam(param: string): string;
|
|
24
59
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
60
|
+
* Get the query param's value of the input URL.
|
|
61
|
+
*
|
|
62
|
+
* ```
|
|
63
|
+
* getUrlParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't3'); // 3
|
|
64
|
+
* getUrlParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4'); // 4
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
27
67
|
* @param {string} url URL string.
|
|
28
68
|
* @param {string} param Query param.
|
|
29
69
|
* @returns {string} value
|
|
30
70
|
*/
|
|
31
71
|
export declare function getUrlParam(url: string, param: string): string | string[];
|
|
32
72
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
73
|
+
* Update the query param's value of the input URL.
|
|
74
|
+
*
|
|
75
|
+
* Usage:
|
|
76
|
+
*
|
|
77
|
+
* ```
|
|
78
|
+
* updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't3', 'three');
|
|
79
|
+
* updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4', 'four');
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* Output:
|
|
83
|
+
*
|
|
84
|
+
* ```
|
|
85
|
+
* http://example.com/?t1=1&t2=2&t3=three&t4=4
|
|
86
|
+
* http://example.com/?t1=1&t2=2&t3=3&t4=four
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
35
89
|
* @param {string} url URL string.
|
|
36
90
|
* @param {string} param Query param.
|
|
37
91
|
* @param {string} value Param's value.
|
|
@@ -39,36 +93,81 @@ export declare function getUrlParam(url: string, param: string): string | string
|
|
|
39
93
|
*/
|
|
40
94
|
export declare function updateQueryParam(url: string, param: string, value: string): string;
|
|
41
95
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
96
|
+
* Get the hash query param's value of the current Web URL(`location.hash`).
|
|
97
|
+
*
|
|
98
|
+
* Usage:
|
|
99
|
+
*
|
|
100
|
+
* ```
|
|
101
|
+
* // http://example.com/?#2333?t1=1&t2=2&t3=3&t4=4
|
|
102
|
+
* // #2333?t1=1&t2=2&t3=3&t4=4
|
|
103
|
+
* getHashQueryParam('t3');
|
|
104
|
+
* getHashQueryParam('t4');
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* Output:
|
|
108
|
+
*
|
|
109
|
+
* ```
|
|
110
|
+
* 3
|
|
111
|
+
* 4
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
44
114
|
* @param {string} param Query param.
|
|
45
115
|
* @returns {string} value
|
|
46
116
|
*/
|
|
47
117
|
export declare function getHashQueryParam(param: string): string;
|
|
48
118
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
119
|
+
* Get the domain of URL, and other params.
|
|
120
|
+
*
|
|
121
|
+
* Usage:
|
|
122
|
+
*
|
|
123
|
+
* ```
|
|
124
|
+
* getDomain('http://example.com/?t1=1&t2=2&t3=3&t4=4');
|
|
125
|
+
* getDomain('http://example.com/test/thanks?t1=1&t2=2&t3=3&t4=4', ['hostname', 'pathname']);
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* Output:
|
|
129
|
+
*
|
|
130
|
+
* ```
|
|
131
|
+
* example.com
|
|
132
|
+
* example.com/test/thanks
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
51
135
|
* @param {string} url
|
|
52
136
|
* @param {array} rules Object.keys(location), ['href', 'protocol', 'host', 'hostname', 'port', 'pathname', 'search', 'hash'], ['hostname', 'pathname'] = 'km.mazey.net/plugins/servlet/mobile'
|
|
53
137
|
*/
|
|
54
138
|
export declare function getDomain(url: string, rules?: string[]): string;
|
|
55
139
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
140
|
+
* Transfer CamelCase to KebabCase.
|
|
141
|
+
*
|
|
142
|
+
* ```
|
|
143
|
+
* camelCaseToKebabCase('ABC'); // a-b-c
|
|
144
|
+
* camelCaseToKebabCase('aBC'); // a-b-c
|
|
145
|
+
* ```
|
|
146
|
+
*
|
|
58
147
|
* @param {string} camelCase 'aBC' or 'ABC'
|
|
59
148
|
* @returns {string} 'a-b-c'
|
|
60
149
|
*/
|
|
61
150
|
export declare function camelCaseToKebabCase(camelCase: string): string;
|
|
62
151
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
152
|
+
* Transfer CamelCase to Underscore.
|
|
153
|
+
*
|
|
154
|
+
* ```
|
|
155
|
+
* camelCase2Underscore('ABC'); // a_b_c
|
|
156
|
+
* camelCase2Underscore('aBC'); // a_b_c
|
|
157
|
+
* ```
|
|
158
|
+
*
|
|
65
159
|
* @param {string} camelCase 'aBC' or 'ABC'
|
|
66
160
|
* @returns {string} 'a_b_c'
|
|
67
161
|
*/
|
|
68
162
|
export declare function camelCase2Underscore(camelCase: string): string;
|
|
69
163
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
164
|
+
* Remove leading and trailing whitespace or specified characters from string.
|
|
165
|
+
*
|
|
166
|
+
* ```
|
|
167
|
+
* mTrim(' 1 2 3 '); // '1 2 3'
|
|
168
|
+
* mTrim('abc '); // 'abc'
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
72
171
|
* @param {string} str The string to trim.
|
|
73
172
|
* @returns {string} Trimmed string.
|
|
74
173
|
*/
|
|
@@ -81,17 +180,42 @@ export declare function mTrim(str: string): string;
|
|
|
81
180
|
*/
|
|
82
181
|
export declare function newLine(str: string): string;
|
|
83
182
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
183
|
+
* Clone Object deeply.
|
|
184
|
+
*
|
|
185
|
+
* Usage:
|
|
186
|
+
*
|
|
187
|
+
* ```
|
|
188
|
+
* deepCopyObject(['a', 'b', 'c']);
|
|
189
|
+
* deepCopyObject('abc');
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* Output:
|
|
193
|
+
*
|
|
194
|
+
* ```
|
|
195
|
+
* ['a', 'b', 'c']
|
|
196
|
+
* 'abc'
|
|
197
|
+
* ```
|
|
198
|
+
*
|
|
86
199
|
* @param {object} obj The value to clone.
|
|
87
200
|
* @returns {object} Returns the deep cloned value.
|
|
88
201
|
*/
|
|
89
202
|
export declare function deepCopyObject(obj: any): any;
|
|
90
203
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
204
|
+
* Check whether it is a valid JSON string.
|
|
205
|
+
*
|
|
206
|
+
* Usage:
|
|
207
|
+
*
|
|
208
|
+
* ```
|
|
209
|
+
* isJsonString(`['a', 'b', 'c']`);
|
|
210
|
+
* isJsonString(`["a", "b", "c"]`);
|
|
211
|
+
* ```
|
|
212
|
+
*
|
|
213
|
+
* Output:
|
|
214
|
+
*
|
|
215
|
+
* ```
|
|
216
|
+
* false
|
|
217
|
+
* true
|
|
218
|
+
* ```
|
|
95
219
|
*/
|
|
96
220
|
export declare function isJsonString(str: string): boolean;
|
|
97
221
|
/**
|
|
@@ -141,6 +265,12 @@ export declare function removeClass(obj: any, cls: string): void;
|
|
|
141
265
|
*
|
|
142
266
|
* ZH: 节流
|
|
143
267
|
*
|
|
268
|
+
* ```
|
|
269
|
+
* const foo = throttle(() => {
|
|
270
|
+
* console.log('The function will be invoked at most once per every wait 1000 milliseconds.');
|
|
271
|
+
* }, 1000, { leading: true });
|
|
272
|
+
* ```
|
|
273
|
+
*
|
|
144
274
|
* Reference: [Lodash](https://lodash.com/docs/4.17.15#throttle)
|
|
145
275
|
*/
|
|
146
276
|
export declare function throttle(func: any, wait: number, options?: {
|
|
@@ -152,8 +282,6 @@ export declare function throttle(func: any, wait: number, options?: {
|
|
|
152
282
|
*
|
|
153
283
|
* ZH: 去抖
|
|
154
284
|
*
|
|
155
|
-
* Usage:
|
|
156
|
-
*
|
|
157
285
|
* ```
|
|
158
286
|
* const foo = debounce(() => {
|
|
159
287
|
* console.log('The debounced function will only be invoked in 1000 milliseconds, the other invoking will disappear during the wait time.');
|
|
@@ -173,8 +301,20 @@ export declare function friendlyInterval(start?: number, end?: number, options?:
|
|
|
173
301
|
type?: string;
|
|
174
302
|
}): number | string;
|
|
175
303
|
/**
|
|
176
|
-
*
|
|
177
|
-
*
|
|
304
|
+
* EN: Check whether it is a right number.
|
|
305
|
+
*
|
|
306
|
+
* ZH: 判断是否有效数字
|
|
307
|
+
*
|
|
308
|
+
* ```
|
|
309
|
+
* isNumber(123); // true
|
|
310
|
+
* isNumber('123'); // false
|
|
311
|
+
* // Default: NaN, Infinity is not Number
|
|
312
|
+
* isNumber(Infinity); // false
|
|
313
|
+
* isNumber(Infinity, { isUnFiniteAsNumber: true }); // true
|
|
314
|
+
* isNumber(NaN); // false
|
|
315
|
+
* isNumber(NaN, { isNaNAsNumber: true, isUnFiniteAsNumber: true }); // true
|
|
316
|
+
* ```
|
|
317
|
+
*
|
|
178
318
|
* @param {*} num 被判断的值
|
|
179
319
|
* @param {boolean} options.isNaNAsNumber 是否 NaN 算数字(默认不算)
|
|
180
320
|
* @param {boolean} options.isUnFiniteAsNumber 是否 无限 算数字(默认不算)
|
|
@@ -219,8 +359,29 @@ export declare function setLocalStorage(key: string, value?: any): void;
|
|
|
219
359
|
*/
|
|
220
360
|
export declare function getLocalStorage(key: string): any;
|
|
221
361
|
/**
|
|
222
|
-
*
|
|
223
|
-
*
|
|
362
|
+
* EN: Load a CSS file from the server.
|
|
363
|
+
*
|
|
364
|
+
* ZH: 动态加载 CSS 文件
|
|
365
|
+
*
|
|
366
|
+
* ```
|
|
367
|
+
* loadCSS(
|
|
368
|
+
* 'http://example.com/css/mazey-base.css',
|
|
369
|
+
* {
|
|
370
|
+
* id: 'iamid', // Optional, link ID, default none
|
|
371
|
+
* }
|
|
372
|
+
* )
|
|
373
|
+
* .then(
|
|
374
|
+
* res => {
|
|
375
|
+
* console.log(`Load CSS Success: ${res}`);
|
|
376
|
+
* }
|
|
377
|
+
* )
|
|
378
|
+
* .catch(
|
|
379
|
+
* err => {
|
|
380
|
+
* console.error(`Load CSS Fail: ${err.message}`)
|
|
381
|
+
* }
|
|
382
|
+
* );
|
|
383
|
+
* ```
|
|
384
|
+
*
|
|
224
385
|
* @param {string} url -- css资源路径
|
|
225
386
|
* @param {string} options.id -- link标签id
|
|
226
387
|
* @returns {Promise<boolean>} true -- 加载成功
|
|
@@ -229,9 +390,32 @@ export declare function loadCSS(url: string, options?: {
|
|
|
229
390
|
id?: string;
|
|
230
391
|
}): Promise<boolean | Error | any>;
|
|
231
392
|
/**
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
393
|
+
* EN: Load a JavaScript file from the server and execute it.
|
|
394
|
+
*
|
|
395
|
+
* ZH: 动态加载 JavaScript 文件
|
|
396
|
+
*
|
|
397
|
+
* ```
|
|
398
|
+
* loadScript(
|
|
399
|
+
* 'http://example.com/static/js/plugin-2.1.1.min.js',
|
|
400
|
+
* {
|
|
401
|
+
* id: 'iamid', // (Optional) script ID, default none
|
|
402
|
+
* timeout: 5000, // (Optional) timeout, default `5000`
|
|
403
|
+
* isDefer: false, // (Optional) defer, default `false`
|
|
404
|
+
* }
|
|
405
|
+
* )
|
|
406
|
+
* .then(
|
|
407
|
+
* res => {
|
|
408
|
+
* console.log(`Load JavaScript script: ${res}`);
|
|
409
|
+
* }
|
|
410
|
+
* )
|
|
411
|
+
* .catch(
|
|
412
|
+
* err => {
|
|
413
|
+
* console.error(`Load JavaScript script: ${err.message}`)
|
|
414
|
+
* }
|
|
415
|
+
* );
|
|
416
|
+
* ```
|
|
417
|
+
*
|
|
418
|
+
* @param {string} url -- JavaScript 资源路径
|
|
235
419
|
* @param {string} options.id -- DOM ID
|
|
236
420
|
* @param {function} options.callback -- 加载后回调函数
|
|
237
421
|
* @param {number} options.timeout -- 超时时长
|
|
@@ -263,22 +447,102 @@ interface WebPerformance {
|
|
|
263
447
|
[key: string]: string | number;
|
|
264
448
|
}
|
|
265
449
|
/**
|
|
266
|
-
*
|
|
267
|
-
*
|
|
450
|
+
* EN: Get page load time(PerformanceTiming).
|
|
451
|
+
*
|
|
452
|
+
* ZH: 获取页面加载相关的各项数据
|
|
453
|
+
*
|
|
454
|
+
* Usage:
|
|
455
|
+
*
|
|
456
|
+
* ```
|
|
457
|
+
* // `camelCase:true`(Default) Return hump data.
|
|
458
|
+
* // `camelCase:false` Return underline data.
|
|
459
|
+
* getPerformance(true)
|
|
460
|
+
* .then(res => {
|
|
461
|
+
* console.log(JSON.stringify(res));
|
|
462
|
+
* })
|
|
463
|
+
* .catch(console.error);
|
|
464
|
+
* ```
|
|
465
|
+
*
|
|
466
|
+
* Output:
|
|
467
|
+
*
|
|
468
|
+
* ```
|
|
469
|
+
* {"deviceType":"pc","network":"3g","unloadTime":0,"redirectTime":0,"dnsTime":0,"tcpTime":0,"responseTime":65,"downloadTime":1,"domreadyTime":369,"onloadTime":441,"whiteTime":94,"renderTime":441,"decodedBodySize":210,"encodedBodySize":210}
|
|
470
|
+
* ```
|
|
471
|
+
*
|
|
472
|
+
* Results:
|
|
473
|
+
*
|
|
474
|
+
* | Index | Field | Description |
|
|
475
|
+
* | --- | --- | --- |
|
|
476
|
+
* | DNS lookup | dns_time | domainLookupEnd - domainLookupStart |
|
|
477
|
+
* | Connection negotiation | tcp_time | connectEnd - connectStart |
|
|
478
|
+
* | Requests and responses | response_time | responseStart - requestStart |
|
|
479
|
+
* | White screen | white_time | responseStart - navigationStart |
|
|
480
|
+
* | DomReady | domready_time | domContentLoadedEventStart - navigationStart |
|
|
481
|
+
* | Onload | onload_time | loadEventStart - navigationStart |
|
|
482
|
+
* | EventEnd | render_time | loadEventEnd -navigationStart |
|
|
483
|
+
* | Unload | unload_time | (Optional) unloadEventEnd - unloadEventStart |
|
|
484
|
+
* | Redirect | redirect_time | (Optional) redirectEnd - redirectStart |
|
|
485
|
+
* | SSL | ssl_time | (Optional) connectEnd - secureConnectionStart |
|
|
486
|
+
* | Download | download_time | (Optional) responseEnd - responseStart |
|
|
487
|
+
*
|
|
268
488
|
* @param {boolean} camelCase -- true(默认) 以驼峰形式返回数据 false 以下划线形式返回数据
|
|
269
489
|
* @returns {Promise<object>} 加载数据
|
|
270
490
|
*/
|
|
271
491
|
export declare function getPerformance(camelCase?: boolean): Promise<WebPerformance | Error>;
|
|
272
492
|
/**
|
|
273
|
-
*
|
|
274
|
-
*
|
|
493
|
+
* EN: Hit probability (1% ~ 100%).
|
|
494
|
+
*
|
|
495
|
+
* ZH: 百分位概率
|
|
496
|
+
*
|
|
497
|
+
* Usage:
|
|
498
|
+
*
|
|
499
|
+
* ```
|
|
500
|
+
* inRate(0.5); // 0.01 ~ 1 true/false
|
|
501
|
+
* ```
|
|
502
|
+
*
|
|
503
|
+
* Output:
|
|
504
|
+
*
|
|
505
|
+
* ```
|
|
506
|
+
* true
|
|
507
|
+
* ```
|
|
508
|
+
*
|
|
509
|
+
* Example: Test the precision.
|
|
510
|
+
*
|
|
511
|
+
* ```
|
|
512
|
+
* // Test
|
|
513
|
+
* let trueCount = 0;
|
|
514
|
+
* let falseCount = 0;
|
|
515
|
+
* new Array(1000000).fill(0).forEach(() => {
|
|
516
|
+
* if (inRate(0.5)) {
|
|
517
|
+
* trueCount++;
|
|
518
|
+
* } else {
|
|
519
|
+
* falseCount++;
|
|
520
|
+
* }
|
|
521
|
+
* });
|
|
522
|
+
* console.log(trueCount, falseCount); // 499994 500006
|
|
523
|
+
* ```
|
|
524
|
+
*
|
|
275
525
|
* @param {number} rate -- 0.1 ~ 1 => 1% ~ 100%
|
|
276
526
|
* @returns {boolean} true 命中
|
|
277
527
|
*/
|
|
278
528
|
export declare function inRate(rate: number): boolean;
|
|
279
529
|
/**
|
|
280
|
-
*
|
|
281
|
-
*
|
|
530
|
+
* EN: Determine if it is a secure PWA environment that it can run.
|
|
531
|
+
*
|
|
532
|
+
* ZH: 判断是否是安全的 PWA 环境
|
|
533
|
+
*
|
|
534
|
+
* Usage:
|
|
535
|
+
*
|
|
536
|
+
* ```
|
|
537
|
+
* isSafePWAEnv();
|
|
538
|
+
* ```
|
|
539
|
+
*
|
|
540
|
+
* Output:
|
|
541
|
+
*
|
|
542
|
+
* ```
|
|
543
|
+
* true
|
|
544
|
+
* ```
|
|
545
|
+
*
|
|
282
546
|
* @returns {boolean} true 是
|
|
283
547
|
*/
|
|
284
548
|
export declare function isSafePWAEnv(): boolean;
|
|
@@ -287,10 +551,20 @@ export declare function isSafePWAEnv(): boolean;
|
|
|
287
551
|
*
|
|
288
552
|
* ZH: 返回浏览器信息 https://github.com/JowayYoung/juejin-code/blob/master/browser-type.js
|
|
289
553
|
*
|
|
554
|
+
* Usage:
|
|
555
|
+
*
|
|
556
|
+
* ```
|
|
557
|
+
* getBrowserInfo();
|
|
558
|
+
* ```
|
|
559
|
+
*
|
|
560
|
+
* Output:
|
|
561
|
+
*
|
|
290
562
|
* ```
|
|
291
|
-
*
|
|
563
|
+
* {"engine":"webkit","engineVs":"537.36","platform":"desktop","supporter":"chrome","supporterVs":"85.0.4183.121","system":"windows","systemVs":"10"}
|
|
292
564
|
* ```
|
|
293
565
|
*
|
|
566
|
+
* Results:
|
|
567
|
+
*
|
|
294
568
|
* | Index | Field | Description |
|
|
295
569
|
* | --- | --- | --- |
|
|
296
570
|
* | System | system | android, ios, windows, macos, linux |
|
|
@@ -301,7 +575,7 @@ export declare function isSafePWAEnv(): boolean;
|
|
|
301
575
|
* | Supporter | supporter | edge, opera, chrome, safari, firefox, iexplore |
|
|
302
576
|
* | Supporter version | supporterVs | - |
|
|
303
577
|
* | Shell | shell | (Optional) wechat, qq_browser, qq_app, uc, 360, 2345, sougou, liebao, maxthon, bilibili |
|
|
304
|
-
* | Shell version | shellVs | (Optional) |
|
|
578
|
+
* | Shell version | shellVs | (Optional) 20/... |
|
|
305
579
|
* | Apple device type | appleType | (Optional) iphone, ipad, ipod, iwatch |
|
|
306
580
|
*
|
|
307
581
|
* Example: Determine the environment of the mobile QQ.
|
|
@@ -342,8 +616,20 @@ export declare function clearHtml(str: string): string;
|
|
|
342
616
|
*/
|
|
343
617
|
export declare function cutCHSString(str: string, len: number, hasDot?: boolean): string;
|
|
344
618
|
/**
|
|
345
|
-
*
|
|
346
|
-
*
|
|
619
|
+
* EN: Check whether the page is loaded successfully (Keepe the compatibility in case that browser's `load` event has been triggered).
|
|
620
|
+
*
|
|
621
|
+
* ZH: 页面加载完成
|
|
622
|
+
*
|
|
623
|
+
* ```
|
|
624
|
+
* windowLoaded(30) // second
|
|
625
|
+
* .then(res => {
|
|
626
|
+
* console.log(`Load Success: ${res}`); // Load Success: load
|
|
627
|
+
* })
|
|
628
|
+
* .catch(err => {
|
|
629
|
+
* console.log(`Load Timeout or Fail: ${err.message}`);
|
|
630
|
+
* });
|
|
631
|
+
* ```
|
|
632
|
+
*
|
|
347
633
|
* @param {number} timeout 超时时间 / 单位:秒
|
|
348
634
|
* @returns {Promise<string>} document is loaded? 'complete' 'load' / 'timeout'
|
|
349
635
|
*/
|
|
@@ -398,15 +684,40 @@ export declare function addStyle(style: string, options?: {
|
|
|
398
684
|
id?: string;
|
|
399
685
|
}): boolean;
|
|
400
686
|
/**
|
|
401
|
-
*
|
|
687
|
+
* EN: Custom console printing (`console`).
|
|
688
|
+
*
|
|
689
|
+
* ZH: 生成自定义控制台打印
|
|
690
|
+
*
|
|
691
|
+
* Usage:
|
|
692
|
+
*
|
|
693
|
+
* ```
|
|
694
|
+
* const myConsole = genCustomConsole('MazeyLog:');
|
|
695
|
+
* myConsole.log('I am string.');
|
|
696
|
+
* myConsole.info('I am boolean.', true);
|
|
697
|
+
* myConsole.info('I am number.', 123, 456);
|
|
698
|
+
* myConsole.info('I am object.', { a: 123, b: 456});
|
|
699
|
+
* ```
|
|
700
|
+
*
|
|
701
|
+
* Output:
|
|
702
|
+
*
|
|
703
|
+
* ```
|
|
704
|
+
* MazeyLog: I am string.
|
|
705
|
+
* MazeyLog: I am boolean. true
|
|
706
|
+
* MazeyLog: I am number. 123 456
|
|
707
|
+
* MazeyLog: I am object. {a: 123, b: 456}
|
|
708
|
+
* ```
|
|
402
709
|
*
|
|
403
710
|
* @param {string} prefix 前缀
|
|
404
|
-
* @param {
|
|
711
|
+
* @param {string} locales A locale string.
|
|
712
|
+
* @param {function} logFn The function with Log.
|
|
713
|
+
* @param {function} errorFn The function with Error.
|
|
405
714
|
* @returns {object} 新实例
|
|
406
715
|
*/
|
|
407
716
|
export declare function genCustomConsole(prefix?: string, options?: {
|
|
408
717
|
isClosed?: boolean;
|
|
409
718
|
showWrap?: boolean;
|
|
719
|
+
showDate?: boolean;
|
|
720
|
+
locales?: string;
|
|
410
721
|
logFn?: () => void;
|
|
411
722
|
errorFn?: () => void;
|
|
412
723
|
}): Console;
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MA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