@whitesev/utils 2.4.7 → 2.5.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.
@@ -1771,7 +1771,7 @@ System.register('Utils', [], (function (exports) {
1771
1771
  let that = this;
1772
1772
  let requestOption = {
1773
1773
  url: userRequestOption.url || this.context.#defaultDetails.url,
1774
- method: (method || "GET").toString().toUpperCase(),
1774
+ method: (method || "GET").toString().toUpperCase().trim(),
1775
1775
  timeout: userRequestOption.timeout || this.context.#defaultDetails.timeout,
1776
1776
  responseType: userRequestOption.responseType ||
1777
1777
  this.context.#defaultDetails.responseType,
@@ -1927,15 +1927,23 @@ System.register('Utils', [], (function (exports) {
1927
1927
  // GET类型,data如果有,那么需要转为searchParams
1928
1928
  let urlObj = new URL(requestOption.url);
1929
1929
  let urlSearch = "";
1930
+ let isHandler = false;
1930
1931
  if (typeof requestOption.data === "string") {
1932
+ isHandler = true;
1931
1933
  urlSearch = requestOption.data;
1932
1934
  }
1933
1935
  else if (typeof requestOption.data === "object") {
1936
+ isHandler = true;
1934
1937
  // URLSearchParams参数可以转普通的string:string,包括FormData
1935
1938
  // @ts-ignore
1936
1939
  let searchParams = new URLSearchParams(requestOption.data);
1937
1940
  urlSearch = searchParams.toString();
1938
1941
  }
1942
+ if (isHandler) {
1943
+ // GET/HEAD请求不支持data参数
1944
+ // 对data进行处理了才可以删除
1945
+ Reflect.deleteProperty(requestOption, "data");
1946
+ }
1939
1947
  if (urlSearch != "") {
1940
1948
  if (urlObj.search === "") {
1941
1949
  // url没有search参数,直接覆盖
@@ -4914,6 +4922,12 @@ System.register('Utils', [], (function (exports) {
4914
4922
  return Math.min(...newResult);
4915
4923
  }
4916
4924
  }
4925
+ /**
4926
+ * 获取随机的安卓手机User-Agent
4927
+ * @example
4928
+ * Utils.getRandomAndroidUA();
4929
+ * > 'Mozilla/5.0 (Linux; Android 10; MI 13 Build/OPR1.170623.027; wv) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.3490.40 Mobile Safari/537.36'
4930
+ **/
4917
4931
  getRandomAndroidUA() {
4918
4932
  let UtilsContext = this;
4919
4933
  let mobileNameList = [
@@ -4932,14 +4946,44 @@ System.register('Utils', [], (function (exports) {
4932
4946
  "M2003J15SC Build/RP1A.200720.011; wv",
4933
4947
  "MI 13 Build/OPR1.170623.027; wv",
4934
4948
  ];
4949
+ /* 安卓版本 */
4935
4950
  let androidVersion = UtilsContext.getRandomValue(12, 14);
4951
+ /* 手机型号 */
4936
4952
  let randomMobile = UtilsContext.getRandomValue(mobileNameList);
4937
- let chromeVersion1 = UtilsContext.getRandomValue(115, 127);
4953
+ /* chrome大版本号 */
4954
+ let chromeVersion1 = UtilsContext.getRandomValue(120, 132);
4938
4955
  let chromeVersion2 = UtilsContext.getRandomValue(0, 0);
4939
4956
  let chromeVersion3 = UtilsContext.getRandomValue(2272, 6099);
4940
4957
  let chromeVersion4 = UtilsContext.getRandomValue(1, 218);
4941
4958
  return `Mozilla/5.0 (Linux; Android ${androidVersion}; ${randomMobile}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion1}.${chromeVersion2}.${chromeVersion3}.${chromeVersion4} Mobile Safari/537.36`;
4942
4959
  }
4960
+ /**
4961
+ * 获取随机的电脑端User-Agent
4962
+ * + Mozilla/5.0:以前用于Netscape浏览器,目前大多数浏览器UA都会带有
4963
+ * + Windows NT 13:代表Window11系统
4964
+ * + Windows NT 10.0:代表Window10系统
4965
+ * + Windows NT 6.1:代表windows7系统
4966
+ * + WOW64:Windows-on-Windows 64-bit,32位的应用程序运行于此64位处理器上
4967
+ * + Win64:64位
4968
+ * + AppleWebKit/537.36:浏览器内核
4969
+ * + KHTML:HTML排版引擎
4970
+ * + like Gecko:这不是Geckeo 浏览器,但是运行起来像Geckeo浏览器
4971
+ * + Chrome/106.0.5068.19:Chrome版本号
4972
+ * + Safari/537.36:宣称自己是Safari?
4973
+ * @returns 返回随机字符串
4974
+ * @example
4975
+ * Utils.getRandomPCUA();
4976
+ * > 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.5068.19 Safari/537.36'
4977
+ **/
4978
+ getRandomPCUA() {
4979
+ let UtilsContext = this;
4980
+ /* chrome大版本号 */
4981
+ let chromeVersion1 = UtilsContext.getRandomValue(120, 132);
4982
+ let chromeVersion2 = UtilsContext.getRandomValue(0, 0);
4983
+ let chromeVersion3 = UtilsContext.getRandomValue(2272, 6099);
4984
+ let chromeVersion4 = UtilsContext.getRandomValue(1, 218);
4985
+ return `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion1}.${chromeVersion2}.${chromeVersion3}.${chromeVersion4} Safari/537.36`;
4986
+ }
4943
4987
  getRandomValue(...args) {
4944
4988
  let result = [...args];
4945
4989
  if (result.length > 1) {
@@ -4969,32 +5013,6 @@ System.register('Utils', [], (function (exports) {
4969
5013
  }
4970
5014
  }
4971
5015
  }
4972
- /**
4973
- * 获取随机的电脑端User-Agent
4974
- * + Mozilla/5.0:以前用于Netscape浏览器,目前大多数浏览器UA都会带有
4975
- * + Windows NT 13:代表Window11系统
4976
- * + Windows NT 10.0:代表Window10系统
4977
- * + Windows NT 6.1:代表windows7系统
4978
- * + WOW64:Windows-on-Windows 64-bit,32位的应用程序运行于此64位处理器上
4979
- * + Win64:64位
4980
- * + AppleWebKit/537.36:浏览器内核
4981
- * + KHTML:HTML排版引擎
4982
- * + like Gecko:这不是Geckeo 浏览器,但是运行起来像Geckeo浏览器
4983
- * + Chrome/106.0.5068.19:Chrome版本号
4984
- * + Safari/537.36:宣称自己是Safari?
4985
- * @returns 返回随机字符串
4986
- * @example
4987
- * Utils.getRandomPCUA();
4988
- * > 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.5068.19 Safari/537.36'
4989
- **/
4990
- getRandomPCUA() {
4991
- let UtilsContext = this;
4992
- let chromeVersion1 = UtilsContext.getRandomValue(115, 127);
4993
- let chromeVersion2 = UtilsContext.getRandomValue(0, 0);
4994
- let chromeVersion3 = UtilsContext.getRandomValue(2272, 6099);
4995
- let chromeVersion4 = UtilsContext.getRandomValue(1, 218);
4996
- return `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion1}.${chromeVersion2}.${chromeVersion3}.${chromeVersion4} Safari/537.36`;
4997
- }
4998
5016
  /**
4999
5017
  * 获取元素上的使用React框架的实例属性,目前包括reactFiber、reactProps、reactEvents、reactEventHandlers、reactInternalInstance
5000
5018
  * @param element 需要获取的目标元素
@@ -5289,13 +5307,45 @@ System.register('Utils', [], (function (exports) {
5289
5307
  isNativeFunc(target) {
5290
5308
  return Boolean(target.toString().match(/^function .*\(\) { \[native code\] }$/));
5291
5309
  }
5292
- isNearBottom(nearValue = 50) {
5293
- var scrollTop = this.windowApi.window.pageYOffset ||
5294
- this.windowApi.document.documentElement.scrollTop;
5295
- var windowHeight = this.windowApi.window.innerHeight ||
5296
- this.windowApi.document.documentElement.clientHeight;
5297
- var documentHeight = this.windowApi.document.documentElement.scrollHeight;
5298
- return scrollTop + windowHeight >= documentHeight - nearValue;
5310
+ isNearBottom(...args) {
5311
+ let nearBottomHeight = 50;
5312
+ let checkWindow = () => {
5313
+ // 已滚动的距离
5314
+ let scrollTop = this.windowApi.window.pageYOffset ||
5315
+ this.windowApi.document.documentElement.scrollTop;
5316
+ // 视窗高度
5317
+ let viewportHeight = this.windowApi.window.innerHeight ||
5318
+ this.windowApi.document.documentElement.clientHeight;
5319
+ // 最大滚动距离
5320
+ let maxScrollHeight = this.windowApi.document.documentElement.scrollHeight - nearBottomHeight;
5321
+ return scrollTop + viewportHeight >= maxScrollHeight;
5322
+ };
5323
+ let checkNode = ($ele) => {
5324
+ // 已滚动的距离
5325
+ let scrollTop = $ele.scrollTop;
5326
+ // 视窗高度
5327
+ let viewportHeight = $ele.clientHeight;
5328
+ // 最大滚动距离
5329
+ let maxScrollHeight = $ele.scrollHeight - viewportHeight - nearBottomHeight;
5330
+ return scrollTop >= maxScrollHeight;
5331
+ };
5332
+ let firstArg = args[0];
5333
+ if (args.length === 0 || typeof args[0] === "number") {
5334
+ // nearBottomHeight
5335
+ //
5336
+ return checkWindow();
5337
+ }
5338
+ else if (typeof args[0] === "object" && args[0] instanceof HTMLElement) {
5339
+ // target
5340
+ // target,nearBottomHeight
5341
+ if (typeof args[1] === "number" && !Number.isNaN(args[1])) {
5342
+ nearBottomHeight = args[1];
5343
+ }
5344
+ return checkNode(args[0]);
5345
+ }
5346
+ else {
5347
+ throw new TypeError("参数1类型错误" + typeof firstArg);
5348
+ }
5299
5349
  }
5300
5350
  isDOM(target) {
5301
5351
  return target instanceof Node;