mazey 2.0.0 → 2.1.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/LICENSE +1 -1
- package/README.md +17 -4
- package/index.js +3 -0
- package/lib/index.cjs.js +1 -4786
- package/lib/index.d.ts +81 -81
- package/lib/index.d.ts.map +1 -1
- package/lib/index.esm.js +1 -4739
- package/lib/mazey.min.js +1 -0
- package/package.json +13 -15
- package/src/index.ts +112 -96
- package/tsconfig.json +2 -1
- package/typing.d.ts +3 -3
- package/lib/example.d.ts +0 -2
- package/lib/example.d.ts.map +0 -1
package/src/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/*
|
|
1
|
+
/* Mazey */
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @method calLongestCommonSubstring
|
|
5
|
-
* @description
|
|
6
|
-
* @param {
|
|
7
|
-
* @param {
|
|
8
|
-
* @return {
|
|
5
|
+
* @description Computes the longest common substring of two strings.
|
|
6
|
+
* @param {string} aStr String
|
|
7
|
+
* @param {string} bStr String
|
|
8
|
+
* @return {number} Length
|
|
9
9
|
*/
|
|
10
10
|
export function calLongestCommonSubstring(aStr = '', bStr = ''): number {
|
|
11
11
|
const aLen = aStr.length;
|
|
@@ -33,9 +33,9 @@ export function calLongestCommonSubstring(aStr = '', bStr = ''): number {
|
|
|
33
33
|
/**
|
|
34
34
|
* @method calLongestCommonSubsequence
|
|
35
35
|
* @description 计算两个字符串的最长公共子序列
|
|
36
|
-
* @param {
|
|
37
|
-
* @param {
|
|
38
|
-
* @return {
|
|
36
|
+
* @param {string} aStr 字符串
|
|
37
|
+
* @param {string} bStr 字符串
|
|
38
|
+
* @return {number} 长度
|
|
39
39
|
*/
|
|
40
40
|
export function calLongestCommonSubsequence(aStr = '', bStr = ''): number {
|
|
41
41
|
const aLen = aStr.length;
|
|
@@ -72,8 +72,8 @@ export function calLongestCommonSubsequence(aStr = '', bStr = ''): number {
|
|
|
72
72
|
/**
|
|
73
73
|
* @method getQueryParam
|
|
74
74
|
* @description Get the query param's value of the current Web URL(`location.search`).
|
|
75
|
-
* @param {
|
|
76
|
-
* @return {
|
|
75
|
+
* @param {string} param Query param.
|
|
76
|
+
* @return {string} value
|
|
77
77
|
* */
|
|
78
78
|
export function getQueryParam(param = ''): string {
|
|
79
79
|
const reg = new RegExp('(^|&)' + param + '=([^&]*)(&|$)');
|
|
@@ -87,9 +87,9 @@ export function getQueryParam(param = ''): string {
|
|
|
87
87
|
/**
|
|
88
88
|
* @method getUrlParam
|
|
89
89
|
* @description Get the query param's value of the input URL.
|
|
90
|
-
* @param {
|
|
91
|
-
* @param {
|
|
92
|
-
* @return {
|
|
90
|
+
* @param {string} url URL string.
|
|
91
|
+
* @param {string} param Query param.
|
|
92
|
+
* @return {string} value
|
|
93
93
|
* */
|
|
94
94
|
export function getUrlParam(url = '', param = ''): string {
|
|
95
95
|
const result: any = {};
|
|
@@ -113,10 +113,10 @@ export function getUrlParam(url = '', param = ''): string {
|
|
|
113
113
|
/**
|
|
114
114
|
* @method updateQueryParam
|
|
115
115
|
* @description Update the query param's value of the input URL.
|
|
116
|
-
* @param {
|
|
117
|
-
* @param {
|
|
118
|
-
* @param {
|
|
119
|
-
* @return {
|
|
116
|
+
* @param {string} url URL string.
|
|
117
|
+
* @param {string} param Query param.
|
|
118
|
+
* @param {string} value Param's value.
|
|
119
|
+
* @return {string} URL.
|
|
120
120
|
* */
|
|
121
121
|
export function updateQueryParam(url = '', param = '', value = ''): string {
|
|
122
122
|
const re = new RegExp('([?&])' + param + '=.*?(&|$)', 'i');
|
|
@@ -131,8 +131,8 @@ export function getUrlParam(url = '', param = ''): string {
|
|
|
131
131
|
/**
|
|
132
132
|
* @method getHashQueryParam
|
|
133
133
|
* @description Get the hash query param's value of the current Web URL(`location.hash`).
|
|
134
|
-
* @param {
|
|
135
|
-
* @return {
|
|
134
|
+
* @param {string} param Query param.
|
|
135
|
+
* @return {string} value
|
|
136
136
|
*/
|
|
137
137
|
export function getHashQueryParam(param = ''): string {
|
|
138
138
|
const hashs = location.hash.split('?');
|
|
@@ -147,8 +147,8 @@ export function getHashQueryParam(param = ''): string {
|
|
|
147
147
|
/**
|
|
148
148
|
* @method getDomain
|
|
149
149
|
* @description Get the domain of URL, and other params.
|
|
150
|
-
* @param {
|
|
151
|
-
* @param {
|
|
150
|
+
* @param {string} url
|
|
151
|
+
* @param {array} rules Object.keys(location), ['href', 'protocol', 'host', 'hostname', 'port', 'pathname', 'search', 'hash'], ['hostname', 'pathname'] = 'km.mazey.net/plugins/servlet/mobile'
|
|
152
152
|
* */
|
|
153
153
|
export function getDomain(url = '', rules = ['hostname']): string {
|
|
154
154
|
const aEl: any = document.createElement('a');
|
|
@@ -162,8 +162,8 @@ export function getDomain(url = '', rules = ['hostname']): string {
|
|
|
162
162
|
/**
|
|
163
163
|
* @method camelCaseToKebabCase
|
|
164
164
|
* @description Transfer CamelCase to KebabCase.
|
|
165
|
-
* @param {
|
|
166
|
-
* @return {
|
|
165
|
+
* @param {string} camelCase 'aBC' or 'ABC'
|
|
166
|
+
* @return {string} 'a-b-c'
|
|
167
167
|
* */
|
|
168
168
|
export function camelCaseToKebabCase(camelCase = ''): string {
|
|
169
169
|
const kebabCase = camelCase.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
@@ -173,8 +173,8 @@ export function camelCaseToKebabCase(camelCase = ''): string {
|
|
|
173
173
|
/**
|
|
174
174
|
* @method camelCase2Underscore
|
|
175
175
|
* @description Transfer CamelCase to Underscore.
|
|
176
|
-
* @param {
|
|
177
|
-
* @return {
|
|
176
|
+
* @param {string} camelCase 'aBC' or 'ABC'
|
|
177
|
+
* @return {string} 'a_b_c'
|
|
178
178
|
* */
|
|
179
179
|
export function camelCase2Underscore(camelCase = ''): string {
|
|
180
180
|
const kebabCase = camelCase.replace(/([A-Z])/g, '_$1').toLowerCase();
|
|
@@ -184,8 +184,8 @@ export function camelCase2Underscore(camelCase = ''): string {
|
|
|
184
184
|
/**
|
|
185
185
|
* @method mTrim
|
|
186
186
|
* @description Remove leading and trailing whitespace or specified characters from string.
|
|
187
|
-
* @param {
|
|
188
|
-
* @return {
|
|
187
|
+
* @param {string} str The string to trim.
|
|
188
|
+
* @return {string} Trimmed string.
|
|
189
189
|
* */
|
|
190
190
|
export function mTrim(str = ''): string {
|
|
191
191
|
str = str.replace(/^\s+/, ''); // 去除头部空格
|
|
@@ -200,8 +200,8 @@ export function mTrim(str = ''): string {
|
|
|
200
200
|
/**
|
|
201
201
|
* @method newLine
|
|
202
202
|
* @description Make a newline of HTML.
|
|
203
|
-
* @param {
|
|
204
|
-
* @return {
|
|
203
|
+
* @param {string} str The string to make a newline.
|
|
204
|
+
* @return {string} A newline with `<br />`.
|
|
205
205
|
* */
|
|
206
206
|
export function newLine(str = ''): string {
|
|
207
207
|
if (!str) {
|
|
@@ -214,8 +214,8 @@ export function newLine(str = ''): string {
|
|
|
214
214
|
/**
|
|
215
215
|
* @method deepCopyObject
|
|
216
216
|
* @description Clone Object deeply.
|
|
217
|
-
* @param {
|
|
218
|
-
* @return {
|
|
217
|
+
* @param {object} obj The value to clone.
|
|
218
|
+
* @return {object} Returns the deep cloned value.
|
|
219
219
|
* */
|
|
220
220
|
export function deepCopyObject(obj: any): any {
|
|
221
221
|
return JSON.parse(JSON.stringify(obj));
|
|
@@ -224,8 +224,8 @@ export function deepCopyObject(obj: any): any {
|
|
|
224
224
|
/**
|
|
225
225
|
* @method isJsonString
|
|
226
226
|
* @description Check whether it is a valid JSON string.
|
|
227
|
-
* @param {
|
|
228
|
-
* @return {
|
|
227
|
+
* @param {string} str The string to check.
|
|
228
|
+
* @return {boolean} Return the result of checking.
|
|
229
229
|
* */
|
|
230
230
|
export function isJsonString(str = ''): boolean {
|
|
231
231
|
try {
|
|
@@ -241,8 +241,8 @@ export function isJsonString(str = ''): boolean {
|
|
|
241
241
|
/**
|
|
242
242
|
* @method generateRndNum
|
|
243
243
|
* @description Produce a random string of number, `generateRndNum(7)` => '7658495'.
|
|
244
|
-
* @param {
|
|
245
|
-
* @return {
|
|
244
|
+
* @param {number} n Length
|
|
245
|
+
* @return {string} Return the random string.
|
|
246
246
|
* */
|
|
247
247
|
export function generateRndNum(n = 5): string {
|
|
248
248
|
let ret = '';
|
|
@@ -255,7 +255,7 @@ export function generateRndNum(n = 5): string {
|
|
|
255
255
|
/**
|
|
256
256
|
* @method generateUniqueNum
|
|
257
257
|
* @description 根据时间生成唯一标志的数字 mGenerateUniqueNum() => 1538324722364123。
|
|
258
|
-
* @param {
|
|
258
|
+
* @param {number} n 随机数的长度
|
|
259
259
|
* */
|
|
260
260
|
export function generateUniqueNum(n = 3): string {
|
|
261
261
|
const [now, rnd] = [mNow(), generateRndNum(n || 3)];
|
|
@@ -265,8 +265,8 @@ export function generateUniqueNum(n = 3): string {
|
|
|
265
265
|
/**
|
|
266
266
|
* @method floatToPercent
|
|
267
267
|
* @description 浮点数转为百分比 0.2 => 20%。
|
|
268
|
-
* @param {
|
|
269
|
-
* @param {
|
|
268
|
+
* @param {number} num 浮点数
|
|
269
|
+
* @param {number} fixSize 保留几位浮点数
|
|
270
270
|
* */
|
|
271
271
|
export function floatToPercent(num = 0, fixSize = 0): string {
|
|
272
272
|
let ret = '';
|
|
@@ -432,10 +432,10 @@ export function debounce(func: any, wait: number, immediate: any): any {
|
|
|
432
432
|
/**
|
|
433
433
|
* @method friendlyInterval
|
|
434
434
|
* @description 获取间隔时间。
|
|
435
|
-
* @param {
|
|
436
|
-
* @param {
|
|
437
|
-
* @type {
|
|
438
|
-
* @return {String/
|
|
435
|
+
* @param {number/Date} start 开始时间戳 1585325367122
|
|
436
|
+
* @param {number/Date} end 结束时间戳 1585325367122
|
|
437
|
+
* @type {string} type 返回类型 d: 2(天) text: 2 天 4 时...
|
|
438
|
+
* @return {String/number} 取决于 type
|
|
439
439
|
* */
|
|
440
440
|
export function friendlyInterval({ start = 0, end = 0, type = 'd' } = {}): number | string {
|
|
441
441
|
if (!isNumber(start)) start = new Date(start).getTime();
|
|
@@ -470,9 +470,9 @@ export function friendlyInterval({ start = 0, end = 0, type = 'd' } = {}): numbe
|
|
|
470
470
|
* @method isNumber
|
|
471
471
|
* @description 判断是否有效数字
|
|
472
472
|
* @param {*} num 被判断的值
|
|
473
|
-
* @param {
|
|
474
|
-
* @param {
|
|
475
|
-
* @return {
|
|
473
|
+
* @param {boolean} isNaNAsNumber 是否 NaN 算数字(默认不算)
|
|
474
|
+
* @param {boolean} isUnFiniteAsNumber 是否 无限 算数字(默认不算)
|
|
475
|
+
* @return {boolean} true 是数字
|
|
476
476
|
*/
|
|
477
477
|
export function isNumber(num: any, { isNaNAsNumber = false, isUnFiniteAsNumber = false } = {}): boolean {
|
|
478
478
|
let ret = true;
|
|
@@ -496,7 +496,7 @@ export function isNumber(num: any, { isNaNAsNumber = false, isUnFiniteAsNumber =
|
|
|
496
496
|
/**
|
|
497
497
|
* @method doFn
|
|
498
498
|
* @description 执行有效函数
|
|
499
|
-
* @param {
|
|
499
|
+
* @param {function} fn 等待被执行的未知是否有效的函数
|
|
500
500
|
* */
|
|
501
501
|
export function doFn(fn: any, ...params: any[]): any {
|
|
502
502
|
let ret = null;
|
|
@@ -509,8 +509,8 @@ export function doFn(fn: any, ...params: any[]): any {
|
|
|
509
509
|
/**
|
|
510
510
|
* @method setSessionStorage
|
|
511
511
|
* @description 存储数据到 sessionStorage
|
|
512
|
-
* @param {
|
|
513
|
-
* @param {
|
|
512
|
+
* @param {string} key 键
|
|
513
|
+
* @param {string} value 值
|
|
514
514
|
* */
|
|
515
515
|
export function setSessionStorage(key: string, value: any = null): void {
|
|
516
516
|
if (key) {
|
|
@@ -521,7 +521,7 @@ export function setSessionStorage(key: string, value: any = null): void {
|
|
|
521
521
|
/**
|
|
522
522
|
* @method getSessionStorage
|
|
523
523
|
* @description 存储数据到 sessionStorage
|
|
524
|
-
* @param {
|
|
524
|
+
* @param {string} key 键
|
|
525
525
|
* @return {*} 返回值
|
|
526
526
|
* */
|
|
527
527
|
export function getSessionStorage(key: string): any {
|
|
@@ -538,8 +538,8 @@ export function getSessionStorage(key: string): any {
|
|
|
538
538
|
/**
|
|
539
539
|
* @method setLocalStorage
|
|
540
540
|
* @description 存储数据到 localStorage
|
|
541
|
-
* @param {
|
|
542
|
-
* @param {
|
|
541
|
+
* @param {string} key 键
|
|
542
|
+
* @param {string} value 值
|
|
543
543
|
* */
|
|
544
544
|
export function setLocalStorage(key: string, value: any = null): void {
|
|
545
545
|
if (key) {
|
|
@@ -550,7 +550,7 @@ export function setLocalStorage(key: string, value: any = null): void {
|
|
|
550
550
|
/**
|
|
551
551
|
* @method getLocalStorage
|
|
552
552
|
* @description 存储数据到 localStorage
|
|
553
|
-
* @param {
|
|
553
|
+
* @param {string} key 键
|
|
554
554
|
* @return {*} 返回值
|
|
555
555
|
* */
|
|
556
556
|
export function getLocalStorage(key: string): any {
|
|
@@ -567,9 +567,9 @@ export function getLocalStorage(key: string): any {
|
|
|
567
567
|
/**
|
|
568
568
|
* @method loadCSS
|
|
569
569
|
* @description 动态加载css文件
|
|
570
|
-
* @param {
|
|
571
|
-
* @param {
|
|
572
|
-
* @return {Promise<
|
|
570
|
+
* @param {string} url -- css资源路径
|
|
571
|
+
* @param {string} id -- link标签id
|
|
572
|
+
* @return {Promise<boolean>} true -- 加载成功
|
|
573
573
|
*/
|
|
574
574
|
export function loadCSS({ url = '', id = '' } = {}): Promise<any> {
|
|
575
575
|
let success: any = null;
|
|
@@ -688,12 +688,12 @@ export function loadCSS({ url = '', id = '' } = {}): Promise<any> {
|
|
|
688
688
|
/**
|
|
689
689
|
* @method loadScript
|
|
690
690
|
* @description 动态加载js文件
|
|
691
|
-
* @param {
|
|
692
|
-
* @param {
|
|
693
|
-
* @param {
|
|
694
|
-
* @param {
|
|
695
|
-
* @param {
|
|
696
|
-
* @return {Promise<
|
|
691
|
+
* @param {string} url -- js资源路径
|
|
692
|
+
* @param {string} id -- DOM ID
|
|
693
|
+
* @param {function} callback -- 加载后回调函数
|
|
694
|
+
* @param {number} timeout -- 超时时长
|
|
695
|
+
* @param {boolean} isDefer -- 是否添加 defer 标签
|
|
696
|
+
* @return {Promise<boolean>} -- true 成功
|
|
697
697
|
*/
|
|
698
698
|
export function loadScript({ url = '', id = '', callback = function () { /* pass */ }, timeout = 5000, isDefer = false } = {}): Promise<any> {
|
|
699
699
|
let success: any = null;
|
|
@@ -810,8 +810,8 @@ export function getCookie(name: string): string {
|
|
|
810
810
|
/**
|
|
811
811
|
* @method getPerformance
|
|
812
812
|
* @description 获取页面加载相关的各项数据
|
|
813
|
-
* @param {
|
|
814
|
-
* @return {Promise<
|
|
813
|
+
* @param {boolean} camelCase -- true(默认) 以驼峰形式返回数据 false 以下划线形式返回数据
|
|
814
|
+
* @return {Promise<object>} 加载数据
|
|
815
815
|
*/
|
|
816
816
|
export function getPerformance({ camelCase = true } = {}): Promise<any> {
|
|
817
817
|
let success: any;
|
|
@@ -1020,8 +1020,8 @@ export function getPerformance({ camelCase = true } = {}): Promise<any> {
|
|
|
1020
1020
|
/**
|
|
1021
1021
|
* @method inRate
|
|
1022
1022
|
* @description 百分位概率
|
|
1023
|
-
* @param {
|
|
1024
|
-
* @return {
|
|
1023
|
+
* @param {number} rate -- 0.1 ~ 1 => 1% ~ 100%
|
|
1024
|
+
* @return {boolean} true 命中
|
|
1025
1025
|
*/
|
|
1026
1026
|
export function inRate(rate: number): boolean {
|
|
1027
1027
|
if(Math.random() < rate) {
|
|
@@ -1033,7 +1033,7 @@ export function inRate(rate: number): boolean {
|
|
|
1033
1033
|
/**
|
|
1034
1034
|
* @method isSafePWAEnv
|
|
1035
1035
|
* @description 判断是否是安全的 PWA 环境
|
|
1036
|
-
* @return {
|
|
1036
|
+
* @return {boolean} true 是
|
|
1037
1037
|
*/
|
|
1038
1038
|
export function isSafePWAEnv(): boolean {
|
|
1039
1039
|
// 判断是否支持 async await
|
|
@@ -1060,7 +1060,7 @@ export function isSafePWAEnv(): boolean {
|
|
|
1060
1060
|
return false;
|
|
1061
1061
|
}
|
|
1062
1062
|
// 浏览器信息
|
|
1063
|
-
const BrowserType =
|
|
1063
|
+
const BrowserType = getBrowserInfo();
|
|
1064
1064
|
if (
|
|
1065
1065
|
('serviceWorker' in navigator) &&
|
|
1066
1066
|
isSupportAsyncAwait() &&
|
|
@@ -1076,11 +1076,11 @@ export function isSafePWAEnv(): boolean {
|
|
|
1076
1076
|
}
|
|
1077
1077
|
|
|
1078
1078
|
/**
|
|
1079
|
-
* @method
|
|
1079
|
+
* @method getBrowserInfo
|
|
1080
1080
|
* @description 返回浏览器信息 https://github.com/JowayYoung/juejin-code/blob/master/browser-type.js
|
|
1081
|
-
* @return {
|
|
1081
|
+
* @return {object} 浏览器信息
|
|
1082
1082
|
*/
|
|
1083
|
-
export function
|
|
1083
|
+
export function getBrowserInfo(): any {
|
|
1084
1084
|
try {
|
|
1085
1085
|
// 权重:系统 + 系统版本 > 平台 > 内核 + 载体 + 内核版本 + 载体版本 > 外壳 + 外壳版本
|
|
1086
1086
|
const ua: any = navigator.userAgent.toLowerCase();
|
|
@@ -1090,7 +1090,9 @@ export function getBrowserType(): any {
|
|
|
1090
1090
|
.replace(/[^0-9|_.]/g, "")
|
|
1091
1091
|
.replace(/_/g, ".");
|
|
1092
1092
|
// 系统
|
|
1093
|
-
let system =
|
|
1093
|
+
let system = '';
|
|
1094
|
+
// Apple device type.
|
|
1095
|
+
let appleType = '';
|
|
1094
1096
|
if (testUa(/windows|win32|win64|wow32|wow64/g)) {
|
|
1095
1097
|
system = "windows"; // windows系统
|
|
1096
1098
|
} else if (testUa(/macintosh|macintel/g)) {
|
|
@@ -1101,9 +1103,18 @@ export function getBrowserType(): any {
|
|
|
1101
1103
|
system = "android"; // android系统
|
|
1102
1104
|
} else if (testUa(/ios|iphone|ipad|ipod|iwatch/g)) {
|
|
1103
1105
|
system = "ios"; // ios系统
|
|
1106
|
+
if (testUa(/iphone/g)) {
|
|
1107
|
+
appleType = 'iphone';
|
|
1108
|
+
} else if (testUa(/ipad/g)) {
|
|
1109
|
+
appleType = 'ipad';
|
|
1110
|
+
} else if (testUa(/iwatch/g)) {
|
|
1111
|
+
appleType = 'iwatch';
|
|
1112
|
+
} else if (testUa(/ipod/g)) {
|
|
1113
|
+
appleType = 'ipod';
|
|
1114
|
+
}
|
|
1104
1115
|
}
|
|
1105
1116
|
// 系统版本
|
|
1106
|
-
let systemVs =
|
|
1117
|
+
let systemVs = '';
|
|
1107
1118
|
if (system === "windows") {
|
|
1108
1119
|
if (testUa(/windows nt 5.0|windows 2000/g)) {
|
|
1109
1120
|
systemVs = "2000";
|
|
@@ -1130,15 +1141,15 @@ export function getBrowserType(): any {
|
|
|
1130
1141
|
systemVs = testVs(/os [\d._]+/g);
|
|
1131
1142
|
}
|
|
1132
1143
|
// 平台
|
|
1133
|
-
let platform =
|
|
1144
|
+
let platform = '';
|
|
1134
1145
|
if (system === "windows" || system === "macos" || system === "linux") {
|
|
1135
1146
|
platform = "desktop"; // 桌面端
|
|
1136
1147
|
} else if (system === "android" || system === "ios" || testUa(/mobile/g)) {
|
|
1137
1148
|
platform = "mobile"; // 移动端
|
|
1138
1149
|
}
|
|
1139
1150
|
// 内核和载体
|
|
1140
|
-
let engine =
|
|
1141
|
-
let supporter =
|
|
1151
|
+
let engine = '';
|
|
1152
|
+
let supporter = '';
|
|
1142
1153
|
if (testUa(/applewebkit/g)) {
|
|
1143
1154
|
engine = "webkit"; // webkit内核
|
|
1144
1155
|
if (testUa(/edge/g)) {
|
|
@@ -1161,7 +1172,7 @@ export function getBrowserType(): any {
|
|
|
1161
1172
|
supporter = "iexplore"; // iexplore浏览器
|
|
1162
1173
|
}
|
|
1163
1174
|
// 内核版本
|
|
1164
|
-
let engineVs =
|
|
1175
|
+
let engineVs = '';
|
|
1165
1176
|
if (engine === "webkit") {
|
|
1166
1177
|
engineVs = testVs(/applewebkit\/[\d._]+/g);
|
|
1167
1178
|
} else if (engine === "gecko") {
|
|
@@ -1172,7 +1183,7 @@ export function getBrowserType(): any {
|
|
|
1172
1183
|
engineVs = testVs(/trident\/[\d._]+/g);
|
|
1173
1184
|
}
|
|
1174
1185
|
// 载体版本
|
|
1175
|
-
let supporterVs =
|
|
1186
|
+
let supporterVs = '';
|
|
1176
1187
|
if (supporter === "chrome") {
|
|
1177
1188
|
supporterVs = testVs(/chrome\/[\d._]+/g);
|
|
1178
1189
|
} else if (supporter === "safari") {
|
|
@@ -1187,14 +1198,16 @@ export function getBrowserType(): any {
|
|
|
1187
1198
|
supporterVs = testVs(/edge\/[\d._]+/g);
|
|
1188
1199
|
}
|
|
1189
1200
|
// 外壳和外壳版本
|
|
1190
|
-
let shell =
|
|
1191
|
-
let shellVs =
|
|
1201
|
+
let shell = '';
|
|
1202
|
+
let shellVs = '';
|
|
1192
1203
|
if (testUa(/micromessenger/g)) {
|
|
1193
1204
|
shell = "wechat"; // 微信浏览器
|
|
1194
1205
|
shellVs = testVs(/micromessenger\/[\d._]+/g);
|
|
1195
1206
|
} else if (testUa(/qqbrowser/g)) {
|
|
1196
|
-
shell = "
|
|
1207
|
+
shell = "qq_browser"; // QQ Browser
|
|
1197
1208
|
shellVs = testVs(/qqbrowser\/[\d._]+/g);
|
|
1209
|
+
} else if (testUa(/\sqq/g)) {
|
|
1210
|
+
shell = "qq_app"; // QQ APP
|
|
1198
1211
|
} else if (testUa(/ucbrowser/g)) {
|
|
1199
1212
|
shell = "uc"; // UC浏览器
|
|
1200
1213
|
shellVs = testVs(/ucbrowser\/[\d._]+/g);
|
|
@@ -1210,6 +1223,8 @@ export function getBrowserType(): any {
|
|
|
1210
1223
|
} else if (testUa(/maxthon/g)) {
|
|
1211
1224
|
shell = "maxthon"; // 遨游浏览器
|
|
1212
1225
|
shellVs = testVs(/maxthon\/[\d._]+/g);
|
|
1226
|
+
} else if (testUa(/biliapp/g)) {
|
|
1227
|
+
shell = "bilibili"; // 哔哩哔哩
|
|
1213
1228
|
}
|
|
1214
1229
|
return Object.assign({
|
|
1215
1230
|
engine, // webkit gecko presto trident
|
|
@@ -1218,10 +1233,11 @@ export function getBrowserType(): any {
|
|
|
1218
1233
|
supporter, // chrome safari firefox opera iexplore edge
|
|
1219
1234
|
supporterVs,
|
|
1220
1235
|
system, // windows macos linux android ios
|
|
1221
|
-
systemVs
|
|
1222
|
-
},
|
|
1236
|
+
systemVs,
|
|
1237
|
+
}, {
|
|
1223
1238
|
shell, // wechat qq uc 360 2345 sougou liebao maxthon
|
|
1224
|
-
shellVs
|
|
1239
|
+
shellVs,
|
|
1240
|
+
appleType,
|
|
1225
1241
|
});
|
|
1226
1242
|
} catch (err) {
|
|
1227
1243
|
return {};
|
|
@@ -1231,8 +1247,8 @@ export function getBrowserType(): any {
|
|
|
1231
1247
|
/**
|
|
1232
1248
|
* @method clearHtml
|
|
1233
1249
|
* @description 去除HTML标签
|
|
1234
|
-
* @param {
|
|
1235
|
-
* @return {
|
|
1250
|
+
* @param {string} string 带html标签的字符串
|
|
1251
|
+
* @return {string} 字符串
|
|
1236
1252
|
*/
|
|
1237
1253
|
export function clearHtml (string = ''): string {
|
|
1238
1254
|
return string.replace(/<\/?.+?>/g, '').replace(/[\r\n]/g, '');
|
|
@@ -1241,10 +1257,10 @@ export function clearHtml (string = ''): string {
|
|
|
1241
1257
|
/**
|
|
1242
1258
|
* @method cutCHSString
|
|
1243
1259
|
* @description 截取字符串,中文算2个字节
|
|
1244
|
-
* @param {
|
|
1245
|
-
* @param {
|
|
1246
|
-
* @param {
|
|
1247
|
-
* @returns {
|
|
1260
|
+
* @param {string} str 要截取的字符串
|
|
1261
|
+
* @param {number} len
|
|
1262
|
+
* @param {boolean} hasDot
|
|
1263
|
+
* @returns {string} 返回截取后的字符串
|
|
1248
1264
|
*/
|
|
1249
1265
|
export function cutCHSString(str = '', len = str.length, hasDot = false): string {
|
|
1250
1266
|
if (str == '' || !str) {
|
|
@@ -1279,7 +1295,7 @@ export function cutCHSString(str = '', len = str.length, hasDot = false): string
|
|
|
1279
1295
|
/**
|
|
1280
1296
|
* @method windowLoaded
|
|
1281
1297
|
* @description 页面加载完成
|
|
1282
|
-
* @param {
|
|
1298
|
+
* @param {number} timeout 超时时间 / 单位:秒
|
|
1283
1299
|
* @return {Promise<string>} document is loaded? 'complete' 'load' / 'timeout'
|
|
1284
1300
|
*/
|
|
1285
1301
|
export function windowLoaded({ timeout = 90 } = {}): Promise<string> {
|
|
@@ -1302,9 +1318,9 @@ export function windowLoaded({ timeout = 90 } = {}): Promise<string> {
|
|
|
1302
1318
|
/**
|
|
1303
1319
|
* @method addInlineStyle
|
|
1304
1320
|
* @description 添加内联样式
|
|
1305
|
-
* @param {
|
|
1306
|
-
* @param {
|
|
1307
|
-
* @return {
|
|
1321
|
+
* @param {string} inlineStyle 内联样式字符串
|
|
1322
|
+
* @param {string} id <style> 标签的 ID
|
|
1323
|
+
* @return {boolean} 添加成功/失败
|
|
1308
1324
|
*/
|
|
1309
1325
|
export function addInlineStyle({ inlineStyle = '', id = '' } = {}): boolean {
|
|
1310
1326
|
if (!inlineStyle) {
|
|
@@ -1340,9 +1356,9 @@ export function addInlineStyle({ inlineStyle = '', id = '' } = {}): boolean {
|
|
|
1340
1356
|
/**
|
|
1341
1357
|
* @method genCustomConsole
|
|
1342
1358
|
* @description 生成自定义控制台打印
|
|
1343
|
-
* @param {
|
|
1344
|
-
* @param {
|
|
1345
|
-
* @return {
|
|
1359
|
+
* @param {string} prefix 前缀
|
|
1360
|
+
* @param {function} allowFn 允许打印的判断函数
|
|
1361
|
+
* @return {object} 新实例
|
|
1346
1362
|
*/
|
|
1347
1363
|
export function genCustomConsole({ prefix = '' } = {}): any {
|
|
1348
1364
|
const methods = ['log', 'info', 'warn', 'error'];
|
package/tsconfig.json
CHANGED
package/typing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// declare const navigator any;
|
|
2
|
-
declare namespace navigator {
|
|
3
|
-
|
|
4
|
-
}
|
|
2
|
+
// declare namespace navigator {
|
|
3
|
+
// let connection: string;
|
|
4
|
+
// }
|
package/lib/example.d.ts
DELETED
package/lib/example.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"example.d.ts","sourceRoot":"","sources":["src/example.ts"],"names":[],"mappings":""}
|