@whitesev/utils 2.4.8 → 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.
@@ -1769,7 +1769,7 @@ var Utils = (function () {
1769
1769
  let that = this;
1770
1770
  let requestOption = {
1771
1771
  url: userRequestOption.url || this.context.#defaultDetails.url,
1772
- method: (method || "GET").toString().toUpperCase(),
1772
+ method: (method || "GET").toString().toUpperCase().trim(),
1773
1773
  timeout: userRequestOption.timeout || this.context.#defaultDetails.timeout,
1774
1774
  responseType: userRequestOption.responseType ||
1775
1775
  this.context.#defaultDetails.responseType,
@@ -1925,15 +1925,23 @@ var Utils = (function () {
1925
1925
  // GET类型,data如果有,那么需要转为searchParams
1926
1926
  let urlObj = new URL(requestOption.url);
1927
1927
  let urlSearch = "";
1928
+ let isHandler = false;
1928
1929
  if (typeof requestOption.data === "string") {
1930
+ isHandler = true;
1929
1931
  urlSearch = requestOption.data;
1930
1932
  }
1931
1933
  else if (typeof requestOption.data === "object") {
1934
+ isHandler = true;
1932
1935
  // URLSearchParams参数可以转普通的string:string,包括FormData
1933
1936
  // @ts-ignore
1934
1937
  let searchParams = new URLSearchParams(requestOption.data);
1935
1938
  urlSearch = searchParams.toString();
1936
1939
  }
1940
+ if (isHandler) {
1941
+ // GET/HEAD请求不支持data参数
1942
+ // 对data进行处理了才可以删除
1943
+ Reflect.deleteProperty(requestOption, "data");
1944
+ }
1937
1945
  if (urlSearch != "") {
1938
1946
  if (urlObj.search === "") {
1939
1947
  // url没有search参数,直接覆盖
@@ -4912,6 +4920,12 @@ var Utils = (function () {
4912
4920
  return Math.min(...newResult);
4913
4921
  }
4914
4922
  }
4923
+ /**
4924
+ * 获取随机的安卓手机User-Agent
4925
+ * @example
4926
+ * Utils.getRandomAndroidUA();
4927
+ * > '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'
4928
+ **/
4915
4929
  getRandomAndroidUA() {
4916
4930
  let UtilsContext = this;
4917
4931
  let mobileNameList = [
@@ -4930,14 +4944,44 @@ var Utils = (function () {
4930
4944
  "M2003J15SC Build/RP1A.200720.011; wv",
4931
4945
  "MI 13 Build/OPR1.170623.027; wv",
4932
4946
  ];
4947
+ /* 安卓版本 */
4933
4948
  let androidVersion = UtilsContext.getRandomValue(12, 14);
4949
+ /* 手机型号 */
4934
4950
  let randomMobile = UtilsContext.getRandomValue(mobileNameList);
4935
- let chromeVersion1 = UtilsContext.getRandomValue(115, 127);
4951
+ /* chrome大版本号 */
4952
+ let chromeVersion1 = UtilsContext.getRandomValue(120, 132);
4936
4953
  let chromeVersion2 = UtilsContext.getRandomValue(0, 0);
4937
4954
  let chromeVersion3 = UtilsContext.getRandomValue(2272, 6099);
4938
4955
  let chromeVersion4 = UtilsContext.getRandomValue(1, 218);
4939
4956
  return `Mozilla/5.0 (Linux; Android ${androidVersion}; ${randomMobile}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion1}.${chromeVersion2}.${chromeVersion3}.${chromeVersion4} Mobile Safari/537.36`;
4940
4957
  }
4958
+ /**
4959
+ * 获取随机的电脑端User-Agent
4960
+ * + Mozilla/5.0:以前用于Netscape浏览器,目前大多数浏览器UA都会带有
4961
+ * + Windows NT 13:代表Window11系统
4962
+ * + Windows NT 10.0:代表Window10系统
4963
+ * + Windows NT 6.1:代表windows7系统
4964
+ * + WOW64:Windows-on-Windows 64-bit,32位的应用程序运行于此64位处理器上
4965
+ * + Win64:64位
4966
+ * + AppleWebKit/537.36:浏览器内核
4967
+ * + KHTML:HTML排版引擎
4968
+ * + like Gecko:这不是Geckeo 浏览器,但是运行起来像Geckeo浏览器
4969
+ * + Chrome/106.0.5068.19:Chrome版本号
4970
+ * + Safari/537.36:宣称自己是Safari?
4971
+ * @returns 返回随机字符串
4972
+ * @example
4973
+ * Utils.getRandomPCUA();
4974
+ * > 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.5068.19 Safari/537.36'
4975
+ **/
4976
+ getRandomPCUA() {
4977
+ let UtilsContext = this;
4978
+ /* chrome大版本号 */
4979
+ let chromeVersion1 = UtilsContext.getRandomValue(120, 132);
4980
+ let chromeVersion2 = UtilsContext.getRandomValue(0, 0);
4981
+ let chromeVersion3 = UtilsContext.getRandomValue(2272, 6099);
4982
+ let chromeVersion4 = UtilsContext.getRandomValue(1, 218);
4983
+ return `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion1}.${chromeVersion2}.${chromeVersion3}.${chromeVersion4} Safari/537.36`;
4984
+ }
4941
4985
  getRandomValue(...args) {
4942
4986
  let result = [...args];
4943
4987
  if (result.length > 1) {
@@ -4967,32 +5011,6 @@ var Utils = (function () {
4967
5011
  }
4968
5012
  }
4969
5013
  }
4970
- /**
4971
- * 获取随机的电脑端User-Agent
4972
- * + Mozilla/5.0:以前用于Netscape浏览器,目前大多数浏览器UA都会带有
4973
- * + Windows NT 13:代表Window11系统
4974
- * + Windows NT 10.0:代表Window10系统
4975
- * + Windows NT 6.1:代表windows7系统
4976
- * + WOW64:Windows-on-Windows 64-bit,32位的应用程序运行于此64位处理器上
4977
- * + Win64:64位
4978
- * + AppleWebKit/537.36:浏览器内核
4979
- * + KHTML:HTML排版引擎
4980
- * + like Gecko:这不是Geckeo 浏览器,但是运行起来像Geckeo浏览器
4981
- * + Chrome/106.0.5068.19:Chrome版本号
4982
- * + Safari/537.36:宣称自己是Safari?
4983
- * @returns 返回随机字符串
4984
- * @example
4985
- * Utils.getRandomPCUA();
4986
- * > 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.5068.19 Safari/537.36'
4987
- **/
4988
- getRandomPCUA() {
4989
- let UtilsContext = this;
4990
- let chromeVersion1 = UtilsContext.getRandomValue(115, 127);
4991
- let chromeVersion2 = UtilsContext.getRandomValue(0, 0);
4992
- let chromeVersion3 = UtilsContext.getRandomValue(2272, 6099);
4993
- let chromeVersion4 = UtilsContext.getRandomValue(1, 218);
4994
- return `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion1}.${chromeVersion2}.${chromeVersion3}.${chromeVersion4} Safari/537.36`;
4995
- }
4996
5014
  /**
4997
5015
  * 获取元素上的使用React框架的实例属性,目前包括reactFiber、reactProps、reactEvents、reactEventHandlers、reactInternalInstance
4998
5016
  * @param element 需要获取的目标元素