mazey 1.4.23 → 1.4.27
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 +2 -2
- package/lib/index.cjs.js +274 -181
- package/lib/index.d.ts +74 -27
- package/lib/index.d.ts.map +1 -1
- package/lib/index.esm.js +273 -182
- package/package.json +1 -1
- package/src/index.ts +229 -165
- package/src/js/data-structure/MSet.js +34 -34
- package/src/js/service/common.js +2 -2
- package/src/test.ts +7 -6
- package/.babelrc +0 -27
- package/.eslintrc +0 -15
package/README.md
CHANGED
|
@@ -174,9 +174,9 @@ console.log(trueCount, falseCount); // 499994 500006
|
|
|
174
174
|
### 浏览器信息
|
|
175
175
|
|
|
176
176
|
```
|
|
177
|
-
import {
|
|
177
|
+
import { getBrowserType } from 'mazey';
|
|
178
178
|
|
|
179
|
-
|
|
179
|
+
getBrowserType(); // {"engine":"webkit","engineVs":"537.36","platform":"desktop","supporter":"chrome","supporterVs":"85.0.4183.121","system":"windows","systemVs":"10"}
|
|
180
180
|
// 外壳和外壳版本 { shell: 'wechat', shellVs: '20' } shell: wechat qq uc 360 2345 sougou liebao maxthon
|
|
181
181
|
```
|
|
182
182
|
|
package/lib/index.cjs.js
CHANGED
|
@@ -3301,12 +3301,17 @@ function resetForm() {
|
|
|
3301
3301
|
/**
|
|
3302
3302
|
* @method floatToPercent
|
|
3303
3303
|
* @description 浮点数转为百分比 0.2 => 20%。
|
|
3304
|
-
* @param {Number}
|
|
3304
|
+
* @param {Number} num 浮点数
|
|
3305
|
+
* @param {Number} fixSize 保留几位浮点数
|
|
3305
3306
|
* */
|
|
3306
3307
|
|
|
3307
|
-
function floatToPercent(num,
|
|
3308
|
-
if (
|
|
3309
|
-
|
|
3308
|
+
function floatToPercent(num, fixSize) {
|
|
3309
|
+
if (fixSize === void 0) {
|
|
3310
|
+
fixSize = 0;
|
|
3311
|
+
}
|
|
3312
|
+
|
|
3313
|
+
if (fixSize) {
|
|
3314
|
+
num = (num * 100).toFixed(fixSize);
|
|
3310
3315
|
} else {
|
|
3311
3316
|
num = Math.floor(num * 100);
|
|
3312
3317
|
}
|
|
@@ -3760,7 +3765,7 @@ function getLocalStorage(key) {
|
|
|
3760
3765
|
|
|
3761
3766
|
return ret;
|
|
3762
3767
|
}
|
|
3763
|
-
|
|
3768
|
+
/**
|
|
3764
3769
|
* @method loadCSS
|
|
3765
3770
|
* @description 动态加载css文件
|
|
3766
3771
|
* @param {String} url -- css资源路径
|
|
@@ -3889,13 +3894,14 @@ function loadCSS(_a) {
|
|
|
3889
3894
|
|
|
3890
3895
|
return status;
|
|
3891
3896
|
}
|
|
3892
|
-
|
|
3897
|
+
/**
|
|
3893
3898
|
* @method loadScript
|
|
3894
3899
|
* @description 动态加载js文件
|
|
3895
3900
|
* @param {String} url -- js资源路径
|
|
3896
3901
|
* @param {String} id -- DOM ID
|
|
3897
3902
|
* @param {Function} callback -- 加载后回调函数
|
|
3898
3903
|
* @param {Number} timeout -- 超时时长
|
|
3904
|
+
* @param {Boolean} isDefer -- 是否添加 defer 标签
|
|
3899
3905
|
* @return {Promise<Boolean>} -- true 成功
|
|
3900
3906
|
*/
|
|
3901
3907
|
|
|
@@ -3908,7 +3914,9 @@ function loadScript(_a) {
|
|
|
3908
3914
|
_e = _b.callback,
|
|
3909
3915
|
callback = _e === void 0 ? function () {} : _e,
|
|
3910
3916
|
_f = _b.timeout,
|
|
3911
|
-
timeout = _f === void 0 ? 5000 : _f
|
|
3917
|
+
timeout = _f === void 0 ? 5000 : _f,
|
|
3918
|
+
_g = _b.isDefer,
|
|
3919
|
+
isDefer = _g === void 0 ? false : _g;
|
|
3912
3920
|
|
|
3913
3921
|
var success = null;
|
|
3914
3922
|
var fail = null;
|
|
@@ -3917,6 +3925,10 @@ function loadScript(_a) {
|
|
|
3917
3925
|
var firstScript = document.getElementsByTagName('script')[0];
|
|
3918
3926
|
script.type = 'text/javascript';
|
|
3919
3927
|
|
|
3928
|
+
if (isDefer) {
|
|
3929
|
+
script.defer = 'defer';
|
|
3930
|
+
}
|
|
3931
|
+
|
|
3920
3932
|
if (id) {
|
|
3921
3933
|
script.id = id;
|
|
3922
3934
|
}
|
|
@@ -3950,7 +3962,7 @@ function loadScript(_a) {
|
|
|
3950
3962
|
}
|
|
3951
3963
|
});
|
|
3952
3964
|
}
|
|
3953
|
-
|
|
3965
|
+
/**
|
|
3954
3966
|
* @method mNow
|
|
3955
3967
|
* @description 获取时间戳
|
|
3956
3968
|
*/
|
|
@@ -3966,7 +3978,7 @@ function mNow() {
|
|
|
3966
3978
|
|
|
3967
3979
|
return ret;
|
|
3968
3980
|
}
|
|
3969
|
-
|
|
3981
|
+
/**
|
|
3970
3982
|
* @method setCookie
|
|
3971
3983
|
* @description 设置 Cookie
|
|
3972
3984
|
*/
|
|
@@ -4011,7 +4023,7 @@ function setCookie(name, value, days, domain) {
|
|
|
4011
4023
|
}
|
|
4012
4024
|
}
|
|
4013
4025
|
}
|
|
4014
|
-
|
|
4026
|
+
/**
|
|
4015
4027
|
* @method getCookie
|
|
4016
4028
|
* @description 获取 Cookie
|
|
4017
4029
|
*/
|
|
@@ -4032,7 +4044,7 @@ function getCookie(name) {
|
|
|
4032
4044
|
|
|
4033
4045
|
return null;
|
|
4034
4046
|
}
|
|
4035
|
-
|
|
4047
|
+
/**
|
|
4036
4048
|
* @method getPerformance
|
|
4037
4049
|
* @description 获取页面加载相关的各项数据
|
|
4038
4050
|
* @param {Boolean} camelCase -- true(默认) 以驼峰形式返回数据 false 以下划线形式返回数据
|
|
@@ -4111,13 +4123,18 @@ function getPerformance(_a) {
|
|
|
4111
4123
|
renderTime: timing.loadEventEnd - startTime || 0,
|
|
4112
4124
|
decodedBodySize: performanceNavigationTiming.decodedBodySize || '',
|
|
4113
4125
|
encodedBodySize: performanceNavigationTiming.encodedBodySize || ''
|
|
4114
|
-
}; //
|
|
4126
|
+
}; // 过滤异常数据
|
|
4115
4127
|
|
|
4116
4128
|
Object.keys(data_1).forEach(function (k) {
|
|
4129
|
+
// 过滤掉 <0 的数据
|
|
4117
4130
|
if (isNumber(data_1[k]) && data_1[k] < 0) {
|
|
4118
4131
|
data_1[k] = 0;
|
|
4119
4132
|
}
|
|
4120
|
-
});
|
|
4133
|
+
}); // 过滤掉白屏时间 > onload 的数据
|
|
4134
|
+
|
|
4135
|
+
if (isNumber(data_1.whiteTime) && data_1.whiteTime > data_1.onloadTime) {
|
|
4136
|
+
data_1.whiteTime = 0;
|
|
4137
|
+
}
|
|
4121
4138
|
|
|
4122
4139
|
if (startTime > 0) {
|
|
4123
4140
|
var Underscore_1;
|
|
@@ -4274,7 +4291,7 @@ function getPerformance(_a) {
|
|
|
4274
4291
|
|
|
4275
4292
|
return status;
|
|
4276
4293
|
}
|
|
4277
|
-
|
|
4294
|
+
/**
|
|
4278
4295
|
* @method inRate
|
|
4279
4296
|
* @description 百分位概率
|
|
4280
4297
|
* @param {Number} rate -- 0.1 ~ 1 => 1% ~ 100%
|
|
@@ -4288,7 +4305,7 @@ function inRate(rate) {
|
|
|
4288
4305
|
|
|
4289
4306
|
return false;
|
|
4290
4307
|
}
|
|
4291
|
-
|
|
4308
|
+
/**
|
|
4292
4309
|
* @method isSafePWAEnv
|
|
4293
4310
|
* @description 判断是否是安全的 PWA 环境
|
|
4294
4311
|
* @return {Boolean} true 是
|
|
@@ -4297,19 +4314,20 @@ function inRate(rate) {
|
|
|
4297
4314
|
function isSafePWAEnv() {
|
|
4298
4315
|
// 判断是否支持 async await
|
|
4299
4316
|
function isSupportAsyncAwait() {
|
|
4300
|
-
var
|
|
4317
|
+
var isSupportAsyncAwaitFunc;
|
|
4301
4318
|
|
|
4302
4319
|
try {
|
|
4303
4320
|
// eval("func = async function(){};");
|
|
4304
|
-
new Function("
|
|
4321
|
+
var fn = new Function("return async function(){};");
|
|
4322
|
+
isSupportAsyncAwaitFunc = fn(); // console.log('isSupportAsyncAwaitFunc', isSupportAsyncAwaitFunc);
|
|
4323
|
+
// 由于async函数的构造器不是全局对象,所以我们需要由下面代码来获取async函数的构造器
|
|
4324
|
+
// 具体可以查看以下MDN上有关于AsyncFunction的说明,
|
|
4325
|
+
// 地址:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncFunction
|
|
4326
|
+
|
|
4327
|
+
return Object.getPrototypeOf(isSupportAsyncAwaitFunc).constructor != null;
|
|
4305
4328
|
} catch (e) {
|
|
4306
4329
|
return false;
|
|
4307
|
-
}
|
|
4308
|
-
// 具体可以查看以下MDN上有关于AsyncFunction的说明,
|
|
4309
|
-
// 地址:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncFunction
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
return Object.getPrototypeOf(func).constructor != null;
|
|
4330
|
+
}
|
|
4313
4331
|
} // 判断是否支持 Promise
|
|
4314
4332
|
|
|
4315
4333
|
|
|
@@ -4330,181 +4348,254 @@ function isSafePWAEnv() {
|
|
|
4330
4348
|
|
|
4331
4349
|
return false;
|
|
4332
4350
|
}
|
|
4333
|
-
|
|
4334
|
-
* @method
|
|
4351
|
+
/**
|
|
4352
|
+
* @method getBrowserType
|
|
4335
4353
|
* @description 返回浏览器信息 https://github.com/JowayYoung/juejin-code/blob/master/browser-type.js
|
|
4336
4354
|
* @return {Object} 浏览器信息
|
|
4337
4355
|
*/
|
|
4338
4356
|
|
|
4339
4357
|
function getBrowserType() {
|
|
4340
|
-
|
|
4341
|
-
|
|
4358
|
+
try {
|
|
4359
|
+
// 权重:系统 + 系统版本 > 平台 > 内核 + 载体 + 内核版本 + 载体版本 > 外壳 + 外壳版本
|
|
4360
|
+
var ua_1 = navigator.userAgent.toLowerCase();
|
|
4342
4361
|
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4362
|
+
var testUa = function testUa(regexp) {
|
|
4363
|
+
return regexp.test(ua_1);
|
|
4364
|
+
};
|
|
4365
|
+
|
|
4366
|
+
var testVs = function testVs(regexp) {
|
|
4367
|
+
return ua_1.match(regexp).toString().replace(/[^0-9|_.]/g, "").replace(/_/g, ".");
|
|
4368
|
+
}; // 系统
|
|
4369
|
+
|
|
4370
|
+
|
|
4371
|
+
var system = "unknow";
|
|
4372
|
+
|
|
4373
|
+
if (testUa(/windows|win32|win64|wow32|wow64/g)) {
|
|
4374
|
+
system = "windows"; // windows系统
|
|
4375
|
+
} else if (testUa(/macintosh|macintel/g)) {
|
|
4376
|
+
system = "macos"; // macos系统
|
|
4377
|
+
} else if (testUa(/x11/g)) {
|
|
4378
|
+
system = "linux"; // linux系统
|
|
4379
|
+
} else if (testUa(/android|adr/g)) {
|
|
4380
|
+
system = "android"; // android系统
|
|
4381
|
+
} else if (testUa(/ios|iphone|ipad|ipod|iwatch/g)) {
|
|
4382
|
+
system = "ios"; // ios系统
|
|
4383
|
+
} // 系统版本
|
|
4384
|
+
|
|
4385
|
+
|
|
4386
|
+
var systemVs = "unknow";
|
|
4387
|
+
|
|
4388
|
+
if (system === "windows") {
|
|
4389
|
+
if (testUa(/windows nt 5.0|windows 2000/g)) {
|
|
4390
|
+
systemVs = "2000";
|
|
4391
|
+
} else if (testUa(/windows nt 5.1|windows xp/g)) {
|
|
4392
|
+
systemVs = "xp";
|
|
4393
|
+
} else if (testUa(/windows nt 5.2|windows 2003/g)) {
|
|
4394
|
+
systemVs = "2003";
|
|
4395
|
+
} else if (testUa(/windows nt 6.0|windows vista/g)) {
|
|
4396
|
+
systemVs = "vista";
|
|
4397
|
+
} else if (testUa(/windows nt 6.1|windows 7/g)) {
|
|
4398
|
+
systemVs = "7";
|
|
4399
|
+
} else if (testUa(/windows nt 6.2|windows 8/g)) {
|
|
4400
|
+
systemVs = "8";
|
|
4401
|
+
} else if (testUa(/windows nt 6.3|windows 8.1/g)) {
|
|
4402
|
+
systemVs = "8.1";
|
|
4403
|
+
} else if (testUa(/windows nt 10.0|windows 10/g)) {
|
|
4404
|
+
systemVs = "10";
|
|
4405
|
+
}
|
|
4406
|
+
} else if (system === "macos") {
|
|
4407
|
+
systemVs = testVs(/os x [\d._]+/g);
|
|
4408
|
+
} else if (system === "android") {
|
|
4409
|
+
systemVs = testVs(/android [\d._]+/g);
|
|
4410
|
+
} else if (system === "ios") {
|
|
4411
|
+
systemVs = testVs(/os [\d._]+/g);
|
|
4412
|
+
} // 平台
|
|
4413
|
+
|
|
4414
|
+
|
|
4415
|
+
var platform = "unknow";
|
|
4416
|
+
|
|
4417
|
+
if (system === "windows" || system === "macos" || system === "linux") {
|
|
4418
|
+
platform = "desktop"; // 桌面端
|
|
4419
|
+
} else if (system === "android" || system === "ios" || testUa(/mobile/g)) {
|
|
4420
|
+
platform = "mobile"; // 移动端
|
|
4421
|
+
} // 内核和载体
|
|
4422
|
+
|
|
4423
|
+
|
|
4424
|
+
var engine = "unknow";
|
|
4425
|
+
var supporter = "unknow";
|
|
4426
|
+
|
|
4427
|
+
if (testUa(/applewebkit/g)) {
|
|
4428
|
+
engine = "webkit"; // webkit内核
|
|
4429
|
+
|
|
4430
|
+
if (testUa(/edge/g)) {
|
|
4431
|
+
supporter = "edge"; // edge浏览器
|
|
4432
|
+
} else if (testUa(/opr/g)) {
|
|
4433
|
+
supporter = "opera"; // opera浏览器
|
|
4434
|
+
} else if (testUa(/chrome/g)) {
|
|
4435
|
+
supporter = "chrome"; // chrome浏览器
|
|
4436
|
+
} else if (testUa(/safari/g)) {
|
|
4437
|
+
supporter = "safari"; // safari浏览器
|
|
4438
|
+
}
|
|
4439
|
+
} else if (testUa(/gecko/g) && testUa(/firefox/g)) {
|
|
4440
|
+
engine = "gecko"; // gecko内核
|
|
4346
4441
|
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
} else if (
|
|
4377
|
-
|
|
4378
|
-
} else if (
|
|
4379
|
-
|
|
4380
|
-
} else if (
|
|
4381
|
-
|
|
4382
|
-
} else if (
|
|
4383
|
-
|
|
4384
|
-
} else if (
|
|
4385
|
-
|
|
4442
|
+
supporter = "firefox"; // firefox浏览器
|
|
4443
|
+
} else if (testUa(/presto/g)) {
|
|
4444
|
+
engine = "presto"; // presto内核
|
|
4445
|
+
|
|
4446
|
+
supporter = "opera"; // opera浏览器
|
|
4447
|
+
} else if (testUa(/trident|compatible|msie/g)) {
|
|
4448
|
+
engine = "trident"; // trident内核
|
|
4449
|
+
|
|
4450
|
+
supporter = "iexplore"; // iexplore浏览器
|
|
4451
|
+
} // 内核版本
|
|
4452
|
+
|
|
4453
|
+
|
|
4454
|
+
var engineVs = "unknow";
|
|
4455
|
+
|
|
4456
|
+
if (engine === "webkit") {
|
|
4457
|
+
engineVs = testVs(/applewebkit\/[\d._]+/g);
|
|
4458
|
+
} else if (engine === "gecko") {
|
|
4459
|
+
engineVs = testVs(/gecko\/[\d._]+/g);
|
|
4460
|
+
} else if (engine === "presto") {
|
|
4461
|
+
engineVs = testVs(/presto\/[\d._]+/g);
|
|
4462
|
+
} else if (engine === "trident") {
|
|
4463
|
+
engineVs = testVs(/trident\/[\d._]+/g);
|
|
4464
|
+
} // 载体版本
|
|
4465
|
+
|
|
4466
|
+
|
|
4467
|
+
var supporterVs = "unknow";
|
|
4468
|
+
|
|
4469
|
+
if (supporter === "chrome") {
|
|
4470
|
+
supporterVs = testVs(/chrome\/[\d._]+/g);
|
|
4471
|
+
} else if (supporter === "safari") {
|
|
4472
|
+
supporterVs = testVs(/version\/[\d._]+/g);
|
|
4473
|
+
} else if (supporter === "firefox") {
|
|
4474
|
+
supporterVs = testVs(/firefox\/[\d._]+/g);
|
|
4475
|
+
} else if (supporter === "opera") {
|
|
4476
|
+
supporterVs = testVs(/opr\/[\d._]+/g);
|
|
4477
|
+
} else if (supporter === "iexplore") {
|
|
4478
|
+
supporterVs = testVs(/(msie [\d._]+)|(rv:[\d._]+)/g);
|
|
4479
|
+
} else if (supporter === "edge") {
|
|
4480
|
+
supporterVs = testVs(/edge\/[\d._]+/g);
|
|
4481
|
+
} // 外壳和外壳版本
|
|
4482
|
+
|
|
4483
|
+
|
|
4484
|
+
var shell = "none";
|
|
4485
|
+
var shellVs = "unknow";
|
|
4486
|
+
|
|
4487
|
+
if (testUa(/micromessenger/g)) {
|
|
4488
|
+
shell = "wechat"; // 微信浏览器
|
|
4489
|
+
|
|
4490
|
+
shellVs = testVs(/micromessenger\/[\d._]+/g);
|
|
4491
|
+
} else if (testUa(/qqbrowser/g)) {
|
|
4492
|
+
shell = "qq"; // QQ浏览器
|
|
4493
|
+
|
|
4494
|
+
shellVs = testVs(/qqbrowser\/[\d._]+/g);
|
|
4495
|
+
} else if (testUa(/ucbrowser/g)) {
|
|
4496
|
+
shell = "uc"; // UC浏览器
|
|
4497
|
+
|
|
4498
|
+
shellVs = testVs(/ucbrowser\/[\d._]+/g);
|
|
4499
|
+
} else if (testUa(/qihu 360se/g)) {
|
|
4500
|
+
shell = "360"; // 360浏览器(无版本)
|
|
4501
|
+
} else if (testUa(/2345explorer/g)) {
|
|
4502
|
+
shell = "2345"; // 2345浏览器
|
|
4503
|
+
|
|
4504
|
+
shellVs = testVs(/2345explorer\/[\d._]+/g);
|
|
4505
|
+
} else if (testUa(/metasr/g)) {
|
|
4506
|
+
shell = "sougou"; // 搜狗浏览器(无版本)
|
|
4507
|
+
} else if (testUa(/lbbrowser/g)) {
|
|
4508
|
+
shell = "liebao"; // 猎豹浏览器(无版本)
|
|
4509
|
+
} else if (testUa(/maxthon/g)) {
|
|
4510
|
+
shell = "maxthon"; // 遨游浏览器
|
|
4511
|
+
|
|
4512
|
+
shellVs = testVs(/maxthon\/[\d._]+/g);
|
|
4386
4513
|
}
|
|
4387
|
-
} else if (system === "macos") {
|
|
4388
|
-
systemVs = testVs(/os x [\d._]+/g);
|
|
4389
|
-
} else if (system === "android") {
|
|
4390
|
-
systemVs = testVs(/android [\d._]+/g);
|
|
4391
|
-
} else if (system === "ios") {
|
|
4392
|
-
systemVs = testVs(/os [\d._]+/g);
|
|
4393
|
-
} // 平台
|
|
4394
4514
|
|
|
4515
|
+
return Object.assign({
|
|
4516
|
+
engine: engine,
|
|
4517
|
+
engineVs: engineVs,
|
|
4518
|
+
platform: platform,
|
|
4519
|
+
supporter: supporter,
|
|
4520
|
+
supporterVs: supporterVs,
|
|
4521
|
+
system: system,
|
|
4522
|
+
systemVs: systemVs
|
|
4523
|
+
}, shell === "none" ? {} : {
|
|
4524
|
+
shell: shell,
|
|
4525
|
+
shellVs: shellVs
|
|
4526
|
+
});
|
|
4527
|
+
} catch (err) {
|
|
4528
|
+
return {};
|
|
4529
|
+
}
|
|
4530
|
+
}
|
|
4531
|
+
/**
|
|
4532
|
+
* @method clearHtml
|
|
4533
|
+
* @description 去除HTML标签
|
|
4534
|
+
* @param {String} string 带html标签的字符串
|
|
4535
|
+
* @return {String} 字符串
|
|
4536
|
+
*/
|
|
4395
4537
|
|
|
4396
|
-
|
|
4538
|
+
function clearHtml(string) {
|
|
4539
|
+
if (string === void 0) {
|
|
4540
|
+
string = '';
|
|
4541
|
+
}
|
|
4397
4542
|
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4543
|
+
return string.replace(/<\/?.+?>/g, '').replace(/[\r\n]/g, '');
|
|
4544
|
+
}
|
|
4545
|
+
/**
|
|
4546
|
+
* @method cutCHSString
|
|
4547
|
+
* @description 截取字符串,中文算2个字节
|
|
4548
|
+
* @param {String} str 要截取的字符串
|
|
4549
|
+
* @param {Number} len
|
|
4550
|
+
* @param {Boolean} hasDot
|
|
4551
|
+
* @returns {String} 返回截取后的字符串
|
|
4552
|
+
*/
|
|
4403
4553
|
|
|
4554
|
+
function cutCHSString(str, len, hasDot) {
|
|
4555
|
+
if (str === void 0) {
|
|
4556
|
+
str = '';
|
|
4557
|
+
}
|
|
4404
4558
|
|
|
4405
|
-
|
|
4406
|
-
|
|
4559
|
+
if (len === void 0) {
|
|
4560
|
+
len = str.length;
|
|
4561
|
+
}
|
|
4407
4562
|
|
|
4408
|
-
if (
|
|
4409
|
-
|
|
4563
|
+
if (hasDot === void 0) {
|
|
4564
|
+
hasDot = false;
|
|
4565
|
+
}
|
|
4410
4566
|
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4567
|
+
if (str == '' || !str) {
|
|
4568
|
+
return '';
|
|
4569
|
+
} else {
|
|
4570
|
+
var newLength = 0;
|
|
4571
|
+
var newStr = ''; // eslint-disable-next-line no-control-regex
|
|
4572
|
+
|
|
4573
|
+
var chineseRegex = /[^\x00-\xff]/g;
|
|
4574
|
+
var singleChar = '';
|
|
4575
|
+
var strLength = str.replace(chineseRegex, '**').length;
|
|
4576
|
+
|
|
4577
|
+
for (var i = 0; i < strLength; i++) {
|
|
4578
|
+
singleChar = str.charAt(i).toString();
|
|
4579
|
+
|
|
4580
|
+
if (singleChar.match(chineseRegex) != null) {
|
|
4581
|
+
newLength += 2;
|
|
4582
|
+
} else {
|
|
4583
|
+
newLength++;
|
|
4584
|
+
}
|
|
4585
|
+
|
|
4586
|
+
if (newLength > len) {
|
|
4587
|
+
break;
|
|
4588
|
+
}
|
|
4589
|
+
|
|
4590
|
+
newStr += singleChar;
|
|
4419
4591
|
}
|
|
4420
|
-
} else if (testUa(/gecko/g) && testUa(/firefox/g)) {
|
|
4421
|
-
engine = "gecko"; // gecko内核
|
|
4422
|
-
|
|
4423
|
-
supporter = "firefox"; // firefox浏览器
|
|
4424
|
-
} else if (testUa(/presto/g)) {
|
|
4425
|
-
engine = "presto"; // presto内核
|
|
4426
|
-
|
|
4427
|
-
supporter = "opera"; // opera浏览器
|
|
4428
|
-
} else if (testUa(/trident|compatible|msie/g)) {
|
|
4429
|
-
engine = "trident"; // trident内核
|
|
4430
|
-
|
|
4431
|
-
supporter = "iexplore"; // iexplore浏览器
|
|
4432
|
-
} // 内核版本
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
var engineVs = "unknow";
|
|
4436
|
-
|
|
4437
|
-
if (engine === "webkit") {
|
|
4438
|
-
engineVs = testVs(/applewebkit\/[\d._]+/g);
|
|
4439
|
-
} else if (engine === "gecko") {
|
|
4440
|
-
engineVs = testVs(/gecko\/[\d._]+/g);
|
|
4441
|
-
} else if (engine === "presto") {
|
|
4442
|
-
engineVs = testVs(/presto\/[\d._]+/g);
|
|
4443
|
-
} else if (engine === "trident") {
|
|
4444
|
-
engineVs = testVs(/trident\/[\d._]+/g);
|
|
4445
|
-
} // 载体版本
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
var supporterVs = "unknow";
|
|
4449
|
-
|
|
4450
|
-
if (supporter === "chrome") {
|
|
4451
|
-
supporterVs = testVs(/chrome\/[\d._]+/g);
|
|
4452
|
-
} else if (supporter === "safari") {
|
|
4453
|
-
supporterVs = testVs(/version\/[\d._]+/g);
|
|
4454
|
-
} else if (supporter === "firefox") {
|
|
4455
|
-
supporterVs = testVs(/firefox\/[\d._]+/g);
|
|
4456
|
-
} else if (supporter === "opera") {
|
|
4457
|
-
supporterVs = testVs(/opr\/[\d._]+/g);
|
|
4458
|
-
} else if (supporter === "iexplore") {
|
|
4459
|
-
supporterVs = testVs(/(msie [\d._]+)|(rv:[\d._]+)/g);
|
|
4460
|
-
} else if (supporter === "edge") {
|
|
4461
|
-
supporterVs = testVs(/edge\/[\d._]+/g);
|
|
4462
|
-
} // 外壳和外壳版本
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
var shell = "none";
|
|
4466
|
-
var shellVs = "unknow";
|
|
4467
|
-
|
|
4468
|
-
if (testUa(/micromessenger/g)) {
|
|
4469
|
-
shell = "wechat"; // 微信浏览器
|
|
4470
|
-
|
|
4471
|
-
shellVs = testVs(/micromessenger\/[\d._]+/g);
|
|
4472
|
-
} else if (testUa(/qqbrowser/g)) {
|
|
4473
|
-
shell = "qq"; // QQ浏览器
|
|
4474
|
-
|
|
4475
|
-
shellVs = testVs(/qqbrowser\/[\d._]+/g);
|
|
4476
|
-
} else if (testUa(/ucbrowser/g)) {
|
|
4477
|
-
shell = "uc"; // UC浏览器
|
|
4478
|
-
|
|
4479
|
-
shellVs = testVs(/ucbrowser\/[\d._]+/g);
|
|
4480
|
-
} else if (testUa(/qihu 360se/g)) {
|
|
4481
|
-
shell = "360"; // 360浏览器(无版本)
|
|
4482
|
-
} else if (testUa(/2345explorer/g)) {
|
|
4483
|
-
shell = "2345"; // 2345浏览器
|
|
4484
|
-
|
|
4485
|
-
shellVs = testVs(/2345explorer\/[\d._]+/g);
|
|
4486
|
-
} else if (testUa(/metasr/g)) {
|
|
4487
|
-
shell = "sougou"; // 搜狗浏览器(无版本)
|
|
4488
|
-
} else if (testUa(/lbbrowser/g)) {
|
|
4489
|
-
shell = "liebao"; // 猎豹浏览器(无版本)
|
|
4490
|
-
} else if (testUa(/maxthon/g)) {
|
|
4491
|
-
shell = "maxthon"; // 遨游浏览器
|
|
4492
|
-
|
|
4493
|
-
shellVs = testVs(/maxthon\/[\d._]+/g);
|
|
4494
|
-
}
|
|
4495
4592
|
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
system: system,
|
|
4503
|
-
systemVs: systemVs
|
|
4504
|
-
}, shell === "none" ? {} : {
|
|
4505
|
-
shell: shell,
|
|
4506
|
-
shellVs: shellVs
|
|
4507
|
-
});
|
|
4593
|
+
if (hasDot && strLength > len) {
|
|
4594
|
+
newStr += '...';
|
|
4595
|
+
}
|
|
4596
|
+
|
|
4597
|
+
return newStr;
|
|
4598
|
+
}
|
|
4508
4599
|
}
|
|
4509
4600
|
|
|
4510
4601
|
exports.addClass = addClass;
|
|
@@ -4513,7 +4604,9 @@ exports.calLongestCommonSubstring = calLongestCommonSubstring;
|
|
|
4513
4604
|
exports.camelCase2Underscore = camelCase2Underscore;
|
|
4514
4605
|
exports.camelCaseToKebabCase = camelCaseToKebabCase;
|
|
4515
4606
|
exports.cancelBubble = cancelBubble;
|
|
4607
|
+
exports.clearHtml = clearHtml;
|
|
4516
4608
|
exports.compatibleExist = compatibleExist;
|
|
4609
|
+
exports.cutCHSString = cutCHSString;
|
|
4517
4610
|
exports.debounce = debounce;
|
|
4518
4611
|
exports.deepCopyObject = deepCopyObject;
|
|
4519
4612
|
exports.doFn = doFn;
|