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/src/index.ts CHANGED
@@ -251,11 +251,12 @@ export function resetForm(...rest: any[]) {
251
251
  /**
252
252
  * @method floatToPercent
253
253
  * @description 浮点数转为百分比 0.2 => 20%。
254
- * @param {Number} 浮点数。
254
+ * @param {Number} num 浮点数
255
+ * @param {Number} fixSize 保留几位浮点数
255
256
  * */
256
- export function floatToPercent(num: any, isFix: any) {
257
- if (isFix) {
258
- num = (num * 100).toFixed(isFix);
257
+ export function floatToPercent(num: any, fixSize = 0): string {
258
+ if (fixSize) {
259
+ num = (num * 100).toFixed(fixSize);
259
260
  } else {
260
261
  num = Math.floor(num * 100);
261
262
  }
@@ -618,7 +619,7 @@ export function getLocalStorage(key: string) {
618
619
  return ret;
619
620
  }
620
621
 
621
- /*
622
+ /**
622
623
  * @method loadCSS
623
624
  * @description 动态加载css文件
624
625
  * @param {String} url -- css资源路径
@@ -739,22 +740,26 @@ export function loadCSS({ url = '', id = '' } = {}) {
739
740
  return status;
740
741
  }
741
742
 
742
- /*
743
+ /**
743
744
  * @method loadScript
744
745
  * @description 动态加载js文件
745
746
  * @param {String} url -- js资源路径
746
747
  * @param {String} id -- DOM ID
747
748
  * @param {Function} callback -- 加载后回调函数
748
749
  * @param {Number} timeout -- 超时时长
750
+ * @param {Boolean} isDefer -- 是否添加 defer 标签
749
751
  * @return {Promise<Boolean>} -- true 成功
750
752
  */
751
- export function loadScript({ url = '', id = '', callback = function () { /* pass */ }, timeout = 5000 } = {}) {
753
+ export function loadScript({ url = '', id = '', callback = function () { /* pass */ }, timeout = 5000, isDefer = false } = {}): any {
752
754
  let success: any = null;
753
755
  let fail: any = null;
754
756
  const script: any = document.createElement('script');
755
757
  // 如果没有 script 标签,那么代码就不会运行。可以利用这一事实,在页面的第一个 script 标签上使用 insertBefore()。
756
758
  const firstScript: any = document.getElementsByTagName('script')[0];
757
759
  script.type = 'text/javascript';
760
+ if (isDefer) {
761
+ script.defer = 'defer';
762
+ }
758
763
  if (id) {
759
764
  script.id = id;
760
765
  }
@@ -784,7 +789,7 @@ export function loadScript({ url = '', id = '', callback = function () { /* pass
784
789
  });
785
790
  }
786
791
 
787
- /*
792
+ /**
788
793
  * @method mNow
789
794
  * @description 获取时间戳
790
795
  */
@@ -798,7 +803,7 @@ export function mNow() {
798
803
  return ret;
799
804
  }
800
805
 
801
- /*
806
+ /**
802
807
  * @method setCookie
803
808
  * @description 设置 Cookie
804
809
  */
@@ -840,7 +845,7 @@ export function setCookie(name: string, value: string, days: number, domain: str
840
845
  }
841
846
  }
842
847
 
843
- /*
848
+ /**
844
849
  * @method getCookie
845
850
  * @description 获取 Cookie
846
851
  */
@@ -857,7 +862,7 @@ export function getCookie(name: string) {
857
862
  return null;
858
863
  }
859
864
 
860
- /*
865
+ /**
861
866
  * @method getPerformance
862
867
  * @description 获取页面加载相关的各项数据
863
868
  * @param {Boolean} camelCase -- true(默认) 以驼峰形式返回数据 false 以下划线形式返回数据
@@ -937,12 +942,17 @@ export function getPerformance({ camelCase = true } = {}) {
937
942
  decodedBodySize: performanceNavigationTiming.decodedBodySize || '', //页面压缩前大小
938
943
  encodedBodySize: performanceNavigationTiming.encodedBodySize || '', //页面压缩后大小
939
944
  };
940
- // 过滤掉 <0 的数据
945
+ // 过滤异常数据
941
946
  Object.keys(data).forEach(k => {
947
+ // 过滤掉 <0 的数据
942
948
  if (isNumber(data[k]) && data[k] < 0) {
943
949
  data[k] = 0;
944
950
  }
945
951
  });
952
+ // 过滤掉白屏时间 > onload 的数据
953
+ if (isNumber(data.whiteTime) && data.whiteTime > data.onloadTime) {
954
+ data.whiteTime = 0;
955
+ }
946
956
  if (startTime > 0) {
947
957
  let Underscore: any;
948
958
  if (!camelCase) {
@@ -1062,7 +1072,7 @@ export function getPerformance({ camelCase = true } = {}) {
1062
1072
  return status;
1063
1073
  }
1064
1074
 
1065
- /*
1075
+ /**
1066
1076
  * @method inRate
1067
1077
  * @description 百分位概率
1068
1078
  * @param {Number} rate -- 0.1 ~ 1 => 1% ~ 100%
@@ -1075,7 +1085,7 @@ export function inRate(rate: number): boolean {
1075
1085
  return false;
1076
1086
  }
1077
1087
 
1078
- /*
1088
+ /**
1079
1089
  * @method isSafePWAEnv
1080
1090
  * @description 判断是否是安全的 PWA 环境
1081
1091
  * @return {Boolean} true 是
@@ -1083,17 +1093,19 @@ export function inRate(rate: number): boolean {
1083
1093
  export function isSafePWAEnv(): boolean {
1084
1094
  // 判断是否支持 async await
1085
1095
  function isSupportAsyncAwait() {
1086
- let func;
1096
+ let isSupportAsyncAwaitFunc;
1087
1097
  try {
1088
1098
  // eval("func = async function(){};");
1089
- new Function("var isSupportAsyncAwaitFunc = async function(){};");
1099
+ const fn = new Function("return async function(){};");
1100
+ isSupportAsyncAwaitFunc = fn();
1101
+ // console.log('isSupportAsyncAwaitFunc', isSupportAsyncAwaitFunc);
1102
+ // 由于async函数的构造器不是全局对象,所以我们需要由下面代码来获取async函数的构造器
1103
+ // 具体可以查看以下MDN上有关于AsyncFunction的说明,
1104
+ // 地址:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncFunction
1105
+ return Object.getPrototypeOf(isSupportAsyncAwaitFunc).constructor != null;
1090
1106
  } catch (e) {
1091
1107
  return false;
1092
1108
  }
1093
- // 由于async函数的构造器不是全局对象,所以我们需要由下面代码来获取async函数的构造器
1094
- // 具体可以查看以下MDN上有关于AsyncFunction的说明,
1095
- // 地址:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncFunction
1096
- return Object.getPrototypeOf(func).constructor != null;
1097
1109
  }
1098
1110
  // 判断是否支持 Promise
1099
1111
  function isSupportPromise() {
@@ -1118,151 +1130,203 @@ export function isSafePWAEnv(): boolean {
1118
1130
  return false;
1119
1131
  }
1120
1132
 
1121
- /*
1122
- * @method showBrowserType
1133
+ /**
1134
+ * @method getBrowserType
1123
1135
  * @description 返回浏览器信息 https://github.com/JowayYoung/juejin-code/blob/master/browser-type.js
1124
1136
  * @return {Object} 浏览器信息
1125
1137
  */
1126
- export function getBrowserType() {
1127
- // 权重:系统 + 系统版本 > 平台 > 内核 + 载体 + 内核版本 + 载体版本 > 外壳 + 外壳版本
1128
- const ua: any = navigator.userAgent.toLowerCase();
1129
- const testUa: (regexp: any) => any = regexp => regexp.test(ua);
1130
- const testVs: (regexp: any) => any = regexp => ua.match(regexp)
1131
- .toString()
1132
- .replace(/[^0-9|_.]/g, "")
1133
- .replace(/_/g, ".");
1134
- // 系统
1135
- let system = "unknow";
1136
- if (testUa(/windows|win32|win64|wow32|wow64/g)) {
1137
- system = "windows"; // windows系统
1138
- } else if (testUa(/macintosh|macintel/g)) {
1139
- system = "macos"; // macos系统
1140
- } else if (testUa(/x11/g)) {
1141
- system = "linux"; // linux系统
1142
- } else if (testUa(/android|adr/g)) {
1143
- system = "android"; // android系统
1144
- } else if (testUa(/ios|iphone|ipad|ipod|iwatch/g)) {
1145
- system = "ios"; // ios系统
1146
- }
1147
- // 系统版本
1148
- let systemVs = "unknow";
1149
- if (system === "windows") {
1150
- if (testUa(/windows nt 5.0|windows 2000/g)) {
1151
- systemVs = "2000";
1152
- } else if (testUa(/windows nt 5.1|windows xp/g)) {
1153
- systemVs = "xp";
1154
- } else if (testUa(/windows nt 5.2|windows 2003/g)) {
1155
- systemVs = "2003";
1156
- } else if (testUa(/windows nt 6.0|windows vista/g)) {
1157
- systemVs = "vista";
1158
- } else if (testUa(/windows nt 6.1|windows 7/g)) {
1159
- systemVs = "7";
1160
- } else if (testUa(/windows nt 6.2|windows 8/g)) {
1161
- systemVs = "8";
1162
- } else if (testUa(/windows nt 6.3|windows 8.1/g)) {
1163
- systemVs = "8.1";
1164
- } else if (testUa(/windows nt 10.0|windows 10/g)) {
1165
- systemVs = "10";
1166
- }
1167
- } else if (system === "macos") {
1168
- systemVs = testVs(/os x [\d._]+/g);
1169
- } else if (system === "android") {
1170
- systemVs = testVs(/android [\d._]+/g);
1171
- } else if (system === "ios") {
1172
- systemVs = testVs(/os [\d._]+/g);
1173
- }
1174
- // 平台
1175
- let platform = "unknow";
1176
- if (system === "windows" || system === "macos" || system === "linux") {
1177
- platform = "desktop"; // 桌面端
1178
- } else if (system === "android" || system === "ios" || testUa(/mobile/g)) {
1179
- platform = "mobile"; // 移动端
1180
- }
1181
- // 内核和载体
1182
- let engine = "unknow";
1183
- let supporter = "unknow";
1184
- if (testUa(/applewebkit/g)) {
1185
- engine = "webkit"; // webkit内核
1186
- if (testUa(/edge/g)) {
1187
- supporter = "edge"; // edge浏览器
1188
- } else if (testUa(/opr/g)) {
1189
- supporter = "opera"; // opera浏览器
1190
- } else if (testUa(/chrome/g)) {
1191
- supporter = "chrome"; // chrome浏览器
1192
- } else if (testUa(/safari/g)) {
1193
- supporter = "safari"; // safari浏览器
1194
- }
1195
- } else if (testUa(/gecko/g) && testUa(/firefox/g)) {
1196
- engine = "gecko"; // gecko内核
1197
- supporter = "firefox"; // firefox浏览器
1198
- } else if (testUa(/presto/g)) {
1199
- engine = "presto"; // presto内核
1200
- supporter = "opera"; // opera浏览器
1201
- } else if (testUa(/trident|compatible|msie/g)) {
1202
- engine = "trident"; // trident内核
1203
- supporter = "iexplore"; // iexplore浏览器
1204
- }
1205
- // 内核版本
1206
- let engineVs = "unknow";
1207
- if (engine === "webkit") {
1208
- engineVs = testVs(/applewebkit\/[\d._]+/g);
1209
- } else if (engine === "gecko") {
1210
- engineVs = testVs(/gecko\/[\d._]+/g);
1211
- } else if (engine === "presto") {
1212
- engineVs = testVs(/presto\/[\d._]+/g);
1213
- } else if (engine === "trident") {
1214
- engineVs = testVs(/trident\/[\d._]+/g);
1215
- }
1216
- // 载体版本
1217
- let supporterVs = "unknow";
1218
- if (supporter === "chrome") {
1219
- supporterVs = testVs(/chrome\/[\d._]+/g);
1220
- } else if (supporter === "safari") {
1221
- supporterVs = testVs(/version\/[\d._]+/g);
1222
- } else if (supporter === "firefox") {
1223
- supporterVs = testVs(/firefox\/[\d._]+/g);
1224
- } else if (supporter === "opera") {
1225
- supporterVs = testVs(/opr\/[\d._]+/g);
1226
- } else if (supporter === "iexplore") {
1227
- supporterVs = testVs(/(msie [\d._]+)|(rv:[\d._]+)/g);
1228
- } else if (supporter === "edge") {
1229
- supporterVs = testVs(/edge\/[\d._]+/g);
1230
- }
1231
- // 外壳和外壳版本
1232
- let shell = "none";
1233
- let shellVs = "unknow";
1234
- if (testUa(/micromessenger/g)) {
1235
- shell = "wechat"; // 微信浏览器
1236
- shellVs = testVs(/micromessenger\/[\d._]+/g);
1237
- } else if (testUa(/qqbrowser/g)) {
1238
- shell = "qq"; // QQ浏览器
1239
- shellVs = testVs(/qqbrowser\/[\d._]+/g);
1240
- } else if (testUa(/ucbrowser/g)) {
1241
- shell = "uc"; // UC浏览器
1242
- shellVs = testVs(/ucbrowser\/[\d._]+/g);
1243
- } else if (testUa(/qihu 360se/g)) {
1244
- shell = "360"; // 360浏览器(无版本)
1245
- } else if (testUa(/2345explorer/g)) {
1246
- shell = "2345"; // 2345浏览器
1247
- shellVs = testVs(/2345explorer\/[\d._]+/g);
1248
- } else if (testUa(/metasr/g)) {
1249
- shell = "sougou"; // 搜狗浏览器(无版本)
1250
- } else if (testUa(/lbbrowser/g)) {
1251
- shell = "liebao"; // 猎豹浏览器(无版本)
1252
- } else if (testUa(/maxthon/g)) {
1253
- shell = "maxthon"; // 遨游浏览器
1254
- shellVs = testVs(/maxthon\/[\d._]+/g);
1255
- }
1256
- return Object.assign({
1257
- engine, // webkit gecko presto trident
1258
- engineVs,
1259
- platform, // desktop mobile
1260
- supporter, // chrome safari firefox opera iexplore edge
1261
- supporterVs,
1262
- system, // windows macos linux android ios
1263
- systemVs
1264
- }, shell === "none" ? {} : {
1265
- shell, // wechat qq uc 360 2345 sougou liebao maxthon
1266
- shellVs
1267
- });
1268
- }
1138
+ export function getBrowserType(): any {
1139
+ try {
1140
+ // 权重:系统 + 系统版本 > 平台 > 内核 + 载体 + 内核版本 + 载体版本 > 外壳 + 外壳版本
1141
+ const ua: any = navigator.userAgent.toLowerCase();
1142
+ const testUa: (regexp: any) => any = regexp => regexp.test(ua);
1143
+ const testVs: (regexp: any) => any = regexp => ua.match(regexp)
1144
+ .toString()
1145
+ .replace(/[^0-9|_.]/g, "")
1146
+ .replace(/_/g, ".");
1147
+ // 系统
1148
+ let system = "unknow";
1149
+ if (testUa(/windows|win32|win64|wow32|wow64/g)) {
1150
+ system = "windows"; // windows系统
1151
+ } else if (testUa(/macintosh|macintel/g)) {
1152
+ system = "macos"; // macos系统
1153
+ } else if (testUa(/x11/g)) {
1154
+ system = "linux"; // linux系统
1155
+ } else if (testUa(/android|adr/g)) {
1156
+ system = "android"; // android系统
1157
+ } else if (testUa(/ios|iphone|ipad|ipod|iwatch/g)) {
1158
+ system = "ios"; // ios系统
1159
+ }
1160
+ // 系统版本
1161
+ let systemVs = "unknow";
1162
+ if (system === "windows") {
1163
+ if (testUa(/windows nt 5.0|windows 2000/g)) {
1164
+ systemVs = "2000";
1165
+ } else if (testUa(/windows nt 5.1|windows xp/g)) {
1166
+ systemVs = "xp";
1167
+ } else if (testUa(/windows nt 5.2|windows 2003/g)) {
1168
+ systemVs = "2003";
1169
+ } else if (testUa(/windows nt 6.0|windows vista/g)) {
1170
+ systemVs = "vista";
1171
+ } else if (testUa(/windows nt 6.1|windows 7/g)) {
1172
+ systemVs = "7";
1173
+ } else if (testUa(/windows nt 6.2|windows 8/g)) {
1174
+ systemVs = "8";
1175
+ } else if (testUa(/windows nt 6.3|windows 8.1/g)) {
1176
+ systemVs = "8.1";
1177
+ } else if (testUa(/windows nt 10.0|windows 10/g)) {
1178
+ systemVs = "10";
1179
+ }
1180
+ } else if (system === "macos") {
1181
+ systemVs = testVs(/os x [\d._]+/g);
1182
+ } else if (system === "android") {
1183
+ systemVs = testVs(/android [\d._]+/g);
1184
+ } else if (system === "ios") {
1185
+ systemVs = testVs(/os [\d._]+/g);
1186
+ }
1187
+ // 平台
1188
+ let platform = "unknow";
1189
+ if (system === "windows" || system === "macos" || system === "linux") {
1190
+ platform = "desktop"; // 桌面端
1191
+ } else if (system === "android" || system === "ios" || testUa(/mobile/g)) {
1192
+ platform = "mobile"; // 移动端
1193
+ }
1194
+ // 内核和载体
1195
+ let engine = "unknow";
1196
+ let supporter = "unknow";
1197
+ if (testUa(/applewebkit/g)) {
1198
+ engine = "webkit"; // webkit内核
1199
+ if (testUa(/edge/g)) {
1200
+ supporter = "edge"; // edge浏览器
1201
+ } else if (testUa(/opr/g)) {
1202
+ supporter = "opera"; // opera浏览器
1203
+ } else if (testUa(/chrome/g)) {
1204
+ supporter = "chrome"; // chrome浏览器
1205
+ } else if (testUa(/safari/g)) {
1206
+ supporter = "safari"; // safari浏览器
1207
+ }
1208
+ } else if (testUa(/gecko/g) && testUa(/firefox/g)) {
1209
+ engine = "gecko"; // gecko内核
1210
+ supporter = "firefox"; // firefox浏览器
1211
+ } else if (testUa(/presto/g)) {
1212
+ engine = "presto"; // presto内核
1213
+ supporter = "opera"; // opera浏览器
1214
+ } else if (testUa(/trident|compatible|msie/g)) {
1215
+ engine = "trident"; // trident内核
1216
+ supporter = "iexplore"; // iexplore浏览器
1217
+ }
1218
+ // 内核版本
1219
+ let engineVs = "unknow";
1220
+ if (engine === "webkit") {
1221
+ engineVs = testVs(/applewebkit\/[\d._]+/g);
1222
+ } else if (engine === "gecko") {
1223
+ engineVs = testVs(/gecko\/[\d._]+/g);
1224
+ } else if (engine === "presto") {
1225
+ engineVs = testVs(/presto\/[\d._]+/g);
1226
+ } else if (engine === "trident") {
1227
+ engineVs = testVs(/trident\/[\d._]+/g);
1228
+ }
1229
+ // 载体版本
1230
+ let supporterVs = "unknow";
1231
+ if (supporter === "chrome") {
1232
+ supporterVs = testVs(/chrome\/[\d._]+/g);
1233
+ } else if (supporter === "safari") {
1234
+ supporterVs = testVs(/version\/[\d._]+/g);
1235
+ } else if (supporter === "firefox") {
1236
+ supporterVs = testVs(/firefox\/[\d._]+/g);
1237
+ } else if (supporter === "opera") {
1238
+ supporterVs = testVs(/opr\/[\d._]+/g);
1239
+ } else if (supporter === "iexplore") {
1240
+ supporterVs = testVs(/(msie [\d._]+)|(rv:[\d._]+)/g);
1241
+ } else if (supporter === "edge") {
1242
+ supporterVs = testVs(/edge\/[\d._]+/g);
1243
+ }
1244
+ // 外壳和外壳版本
1245
+ let shell = "none";
1246
+ let shellVs = "unknow";
1247
+ if (testUa(/micromessenger/g)) {
1248
+ shell = "wechat"; // 微信浏览器
1249
+ shellVs = testVs(/micromessenger\/[\d._]+/g);
1250
+ } else if (testUa(/qqbrowser/g)) {
1251
+ shell = "qq"; // QQ浏览器
1252
+ shellVs = testVs(/qqbrowser\/[\d._]+/g);
1253
+ } else if (testUa(/ucbrowser/g)) {
1254
+ shell = "uc"; // UC浏览器
1255
+ shellVs = testVs(/ucbrowser\/[\d._]+/g);
1256
+ } else if (testUa(/qihu 360se/g)) {
1257
+ shell = "360"; // 360浏览器(无版本)
1258
+ } else if (testUa(/2345explorer/g)) {
1259
+ shell = "2345"; // 2345浏览器
1260
+ shellVs = testVs(/2345explorer\/[\d._]+/g);
1261
+ } else if (testUa(/metasr/g)) {
1262
+ shell = "sougou"; // 搜狗浏览器(无版本)
1263
+ } else if (testUa(/lbbrowser/g)) {
1264
+ shell = "liebao"; // 猎豹浏览器(无版本)
1265
+ } else if (testUa(/maxthon/g)) {
1266
+ shell = "maxthon"; // 遨游浏览器
1267
+ shellVs = testVs(/maxthon\/[\d._]+/g);
1268
+ }
1269
+ return Object.assign({
1270
+ engine, // webkit gecko presto trident
1271
+ engineVs,
1272
+ platform, // desktop mobile
1273
+ supporter, // chrome safari firefox opera iexplore edge
1274
+ supporterVs,
1275
+ system, // windows macos linux android ios
1276
+ systemVs
1277
+ }, shell === "none" ? {} : {
1278
+ shell, // wechat qq uc 360 2345 sougou liebao maxthon
1279
+ shellVs
1280
+ });
1281
+ } catch (err) {
1282
+ return {};
1283
+ }
1284
+ }
1285
+
1286
+ /**
1287
+ * @method clearHtml
1288
+ * @description 去除HTML标签
1289
+ * @param {String} string 带html标签的字符串
1290
+ * @return {String} 字符串
1291
+ */
1292
+ export function clearHtml (string = ''): string {
1293
+ return string.replace(/<\/?.+?>/g, '').replace(/[\r\n]/g, '');
1294
+ }
1295
+
1296
+ /**
1297
+ * @method cutCHSString
1298
+ * @description 截取字符串,中文算2个字节
1299
+ * @param {String} str 要截取的字符串
1300
+ * @param {Number} len
1301
+ * @param {Boolean} hasDot
1302
+ * @returns {String} 返回截取后的字符串
1303
+ */
1304
+ export function cutCHSString(str = '', len = str.length, hasDot = false): string {
1305
+ if (str == '' || !str) {
1306
+ return '';
1307
+ } else {
1308
+ let newLength = 0;
1309
+ let newStr = '';
1310
+ // eslint-disable-next-line no-control-regex
1311
+ const chineseRegex = /[^\x00-\xff]/g;
1312
+ let singleChar = '';
1313
+ const strLength = str.replace(chineseRegex, '**').length;
1314
+ for (let i = 0; i < strLength; i++) {
1315
+ singleChar = str.charAt(i).toString();
1316
+ if (singleChar.match(chineseRegex) != null) {
1317
+ newLength += 2;
1318
+ } else {
1319
+ newLength++;
1320
+ }
1321
+ if (newLength > len) {
1322
+ break;
1323
+ }
1324
+ newStr += singleChar;
1325
+ }
1326
+
1327
+ if (hasDot && strLength > len) {
1328
+ newStr += '...';
1329
+ }
1330
+ return newStr;
1331
+ }
1332
+ }
@@ -1,89 +1,89 @@
1
1
  // 集合
2
2
  export default function MSet () {
3
- this.dataStore = []
4
- this.add = add
5
- this.remove = remove
6
- this.size = size
7
- this.show = show
8
- this.contains = contains
9
- this.union = union
10
- this.intersect = intersect
11
- this.subset = subset
12
- this.difference = difference
3
+ this.dataStore = [];
4
+ this.add = add;
5
+ this.remove = remove;
6
+ this.size = size;
7
+ this.show = show;
8
+ this.contains = contains;
9
+ this.union = union;
10
+ this.intersect = intersect;
11
+ this.subset = subset;
12
+ this.difference = difference;
13
13
  }
14
14
  function add (data) {
15
15
  if (this.dataStore.indexOf(data) < 0) {
16
- this.dataStore.push(data)
17
- return true
16
+ this.dataStore.push(data);
17
+ return true;
18
18
  } else {
19
- return false
19
+ return false;
20
20
  }
21
21
  }
22
22
  function remove (data) {
23
- let pos = this.dataStore.indexOf(data)
23
+ let pos = this.dataStore.indexOf(data);
24
24
  if (pos > -1) {
25
- this.dataStore.splice(pos, 1)
26
- return true
25
+ this.dataStore.splice(pos, 1);
26
+ return true;
27
27
  } else {
28
- return false
28
+ return false;
29
29
  }
30
30
  }
31
31
  function size () {
32
- return this.dataStore.length
32
+ return this.dataStore.length;
33
33
  }
34
34
  function show () {
35
- return this.dataStore
35
+ return this.dataStore;
36
36
  }
37
37
  function contains (data) {
38
38
  if (this.dataStore.indexOf(data) > -1) {
39
- return true
39
+ return true;
40
40
  } else {
41
- return false
41
+ return false;
42
42
  }
43
43
  }
44
44
  // 并集
45
45
  function union (set) {
46
- let tempSet = new MSet()
46
+ let tempSet = new MSet();
47
47
  for (let i = 0; i < this.dataStore.length; ++i) {
48
- tempSet.add(this.dataStore[i])
48
+ tempSet.add(this.dataStore[i]);
49
49
  }
50
50
  for (let i = 0; i < set.dataStore.length; ++i) {
51
51
  if (!tempSet.contains(set.dataStore[i])) {
52
- tempSet.dataStore.push(set.dataStore[i])
52
+ tempSet.dataStore.push(set.dataStore[i]);
53
53
  }
54
54
  }
55
- return tempSet
55
+ return tempSet;
56
56
  }
57
57
  // 交集
58
58
  function intersect (set) {
59
- let tempSet = new MSet()
59
+ let tempSet = new MSet();
60
60
  for (let i = 0; i < this.dataStore.length; ++i) {
61
61
  if (set.contains(this.dataStore[i])) {
62
- tempSet.add(this.dataStore[i])
62
+ tempSet.add(this.dataStore[i]);
63
63
  }
64
64
  }
65
- return tempSet
65
+ return tempSet;
66
66
  }
67
67
  // 子集
68
68
  function subset (set) {
69
69
  if (this.size() > set.size()) {
70
- return false
70
+ return false;
71
71
  } else {
72
72
  for (let i = 0; i < this.dataStore.length; ++i) {
73
73
  if (!set.contains(this.dataStore[i])) {
74
- return false
74
+ return false;
75
75
  }
76
76
  }
77
77
  }
78
- return true
78
+ return true;
79
79
  }
80
80
  // 差集
81
81
  function difference (set) {
82
- let tempSet = new MSet()
82
+ let tempSet = new MSet();
83
83
  for (let i = 0; i < this.dataStore.length; ++i) {
84
84
  if (!set.contains(this.dataStore[i])) {
85
- tempSet.add(this.dataStore[i])
85
+ tempSet.add(this.dataStore[i]);
86
86
  }
87
87
  }
88
- return tempSet
88
+ return tempSet;
89
89
  }
@@ -1,4 +1,4 @@
1
1
  // 时间戳
2
2
  export const mNow = Date.now || function () {
3
- return new Date().getTime()
4
- }
3
+ return new Date().getTime();
4
+ };