youtil 3.0.4 → 3.0.6

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.
Files changed (160) hide show
  1. package/cjs/enum.js +2 -2
  2. package/cjs/index.d.ts +1 -0
  3. package/cjs/index.js +1 -0
  4. package/cjs/loading.js +2 -2
  5. package/cjs/message.js +9 -9
  6. package/cjs/other.d.ts +14 -0
  7. package/cjs/other.js +86 -0
  8. package/cjs/request.d.ts +8 -2
  9. package/cjs/request.js +42 -21
  10. package/cjs/string.d.ts +42 -0
  11. package/cjs/string.js +108 -0
  12. package/docs/404.html +4 -4
  13. package/docs/CNAME +1 -0
  14. package/docs/api/functions/copyToClipboard/index.html +5 -5
  15. package/docs/api/functions/createEnum/index.html +5 -5
  16. package/docs/api/functions/decodeHtml/index.html +5 -5
  17. package/docs/api/functions/deepCopy/index.html +5 -5
  18. package/docs/api/functions/delParam/index.html +5 -5
  19. package/docs/api/functions/encodeHtml/index.html +5 -5
  20. package/docs/api/functions/formatDate/index.html +5 -5
  21. package/docs/api/functions/formatJson/index.html +17 -0
  22. package/docs/api/functions/getIdCardLastChar/index.html +16 -0
  23. package/docs/api/functions/getParam/index.html +6 -6
  24. package/docs/api/functions/getParamInt/index.html +5 -5
  25. package/docs/api/functions/getParams/index.html +6 -6
  26. package/docs/api/functions/getRandom/index.html +21 -0
  27. package/docs/api/functions/getRandomStr/index.html +16 -0
  28. package/docs/api/functions/hideLoading/index.html +5 -5
  29. package/docs/api/functions/initWindowMessage/index.html +5 -5
  30. package/docs/api/functions/parseDate/index.html +5 -5
  31. package/docs/api/functions/request/index.html +5 -5
  32. package/docs/api/functions/setParam/index.html +5 -5
  33. package/docs/api/functions/showLoading/index.html +5 -5
  34. package/docs/api/functions/sleep/index.html +6 -6
  35. package/docs/api/functions/toHump/index.html +18 -0
  36. package/docs/api/functions/toUnderline/index.html +16 -0
  37. package/docs/api/functions/toUrlParams/index.html +5 -5
  38. package/docs/api/functions/validateIdCard/index.html +16 -0
  39. package/docs/api/globals/index.html +5 -5
  40. package/docs/api/index.html +4 -4
  41. package/docs/api/interfaces/IRequestOptions/index.html +5 -5
  42. package/docs/api/interfaces/IShowLoadingConfig/index.html +5 -5
  43. package/docs/api/variables/Request/index.html +5 -5
  44. package/docs/api/variables/keyCodes/index.html +16 -0
  45. package/docs/assets/js/00078de9.40631b85.js +1 -0
  46. package/docs/assets/js/04050071.c7e3abde.js +1 -0
  47. package/docs/assets/js/08f709b9.a083fff8.js +1 -0
  48. package/docs/assets/js/094cfbf1.00977b14.js +1 -0
  49. package/docs/assets/js/0c2147ef.7be0fbdf.js +1 -0
  50. package/docs/assets/js/114.c257b8b0.js +2 -0
  51. package/docs/assets/js/1501a739.13d7c7be.js +1 -0
  52. package/docs/assets/js/1608b181.cbe9c45e.js +1 -0
  53. package/docs/assets/js/1774.902f2e94.js +1 -0
  54. package/docs/assets/js/17896441.7fc5704e.js +1 -0
  55. package/docs/assets/js/194adc5f.8a12cf8c.js +1 -0
  56. package/docs/assets/js/1be78505.71fee479.js +1 -0
  57. package/docs/assets/js/26a70007.f12496a6.js +1 -0
  58. package/docs/assets/js/2ac048f8.1f1f0188.js +1 -0
  59. package/docs/assets/js/2e314e38.32e955e9.js +1 -0
  60. package/docs/assets/js/{3b14ef11.f71babe0.js → 3b14ef11.5bc3d469.js} +1 -1
  61. package/docs/assets/js/3ec39cd5.55864cc1.js +1 -0
  62. package/docs/assets/js/479af78b.8e2443f4.js +1 -0
  63. package/docs/assets/js/5888.a314615c.js +2 -0
  64. package/docs/assets/js/66592e46.de586a2b.js +1 -0
  65. package/docs/assets/js/{6bc50bd8.d7b46cc0.js → 6bc50bd8.3c68878f.js} +1 -1
  66. package/docs/assets/js/7830.006c8eaa.js +1 -0
  67. package/docs/assets/js/7891b53e.79b654b9.js +1 -0
  68. package/docs/assets/js/8b76e124.7c5e5eb2.js +1 -0
  69. package/docs/assets/js/901a7e9f.5cd13eb6.js +1 -0
  70. package/docs/assets/js/9104954f.c7d49874.js +1 -0
  71. package/docs/assets/js/92b7d874.a379eff4.js +1 -0
  72. package/docs/assets/js/9334cb7c.c2c6b902.js +1 -0
  73. package/docs/assets/js/935f2afb.6c90f018.js +1 -0
  74. package/docs/assets/js/969412eb.5a33260d.js +1 -0
  75. package/docs/assets/js/9be94766.3c374589.js +1 -0
  76. package/docs/assets/js/9dd5329b.14301248.js +1 -0
  77. package/docs/assets/js/a0c44371.6c889be4.js +1 -0
  78. package/docs/assets/js/ab2af742.46b7af8c.js +1 -0
  79. package/docs/assets/js/b01f3e06.62f3a014.js +1 -0
  80. package/docs/assets/js/ba6f0f15.39cd6e80.js +1 -0
  81. package/docs/assets/js/ccb851b4.bba2fb6b.js +1 -0
  82. package/docs/assets/js/d4323bca.ac481634.js +1 -0
  83. package/docs/assets/js/d9f162ad.2abc1769.js +1 -0
  84. package/docs/assets/js/e2aa7f69.620e7b98.js +1 -0
  85. package/docs/assets/js/ef3f9d02.479dddf7.js +1 -0
  86. package/docs/assets/js/f4c916b9.07c4240c.js +1 -0
  87. package/docs/assets/js/f7d87c57.9b13a5a8.js +1 -0
  88. package/docs/assets/js/f97ec998.449e16b8.js +1 -0
  89. package/docs/assets/js/f9953324.325f2a5d.js +1 -0
  90. package/docs/assets/js/{fc1c80db.cfb5338b.js → fc1c80db.551e2052.js} +1 -1
  91. package/docs/assets/js/fdb649b1.5d0fff7c.js +1 -0
  92. package/docs/assets/js/main.15afa47b.js +2 -0
  93. package/docs/assets/js/runtime~main.1ee1dff9.js +1 -0
  94. package/docs/demos/IcePkgDemo_doc_01_request_0/index.html +4 -4
  95. package/docs/demos/IcePkgDemo_doc_01_request_1/index.html +4 -4
  96. package/docs/demos/IcePkgDemo_doc_02_time_0/index.html +4 -4
  97. package/docs/demos/IcePkgDemo_doc_03_loading_0/index.html +4 -4
  98. package/docs/index.html +4 -4
  99. package/docs/loading/index.html +18 -18
  100. package/docs/request/index.html +32 -32
  101. package/docs/sitemap.xml +1 -1
  102. package/docs/time/index.html +18 -18
  103. package/es/89c27c69.esm.es5.production.mjs +1 -0
  104. package/es/index.mjs +1 -1
  105. package/esm/enum.js +2 -2
  106. package/esm/index.d.ts +1 -0
  107. package/esm/index.js +1 -0
  108. package/esm/loading.js +2 -2
  109. package/esm/message.js +9 -9
  110. package/esm/other.d.ts +14 -0
  111. package/esm/other.js +85 -0
  112. package/esm/request.d.ts +8 -2
  113. package/esm/request.js +42 -21
  114. package/esm/string.d.ts +42 -0
  115. package/esm/string.js +106 -0
  116. package/package.json +1 -1
  117. package/umd/index.js +1 -1
  118. package/docs/assets/js/00078de9.a02a731a.js +0 -1
  119. package/docs/assets/js/04050071.0825974f.js +0 -1
  120. package/docs/assets/js/08f709b9.811f5e45.js +0 -1
  121. package/docs/assets/js/094cfbf1.2b58cb63.js +0 -1
  122. package/docs/assets/js/0c2147ef.6eb74fc2.js +0 -2
  123. package/docs/assets/js/1501a739.5f21617c.js +0 -1
  124. package/docs/assets/js/1608b181.b1c51f75.js +0 -1
  125. package/docs/assets/js/17896441.6674ffec.js +0 -1
  126. package/docs/assets/js/194adc5f.0203fec9.js +0 -1
  127. package/docs/assets/js/1be78505.537008e6.js +0 -1
  128. package/docs/assets/js/2ac048f8.ee6f4e82.js +0 -1
  129. package/docs/assets/js/2e314e38.995f71c6.js +0 -1
  130. package/docs/assets/js/3ec39cd5.3e1ed37e.js +0 -1
  131. package/docs/assets/js/66592e46.f0e51f16.js +0 -2
  132. package/docs/assets/js/66592e46.f0e51f16.js.LICENSE.txt +0 -1
  133. package/docs/assets/js/774.fa0d167d.js +0 -1
  134. package/docs/assets/js/7891b53e.0e060d15.js +0 -1
  135. package/docs/assets/js/830.d8724ce6.js +0 -1
  136. package/docs/assets/js/888.800281f1.js +0 -2
  137. package/docs/assets/js/8b76e124.68a54c9e.js +0 -1
  138. package/docs/assets/js/9104954f.a1a72ca6.js +0 -1
  139. package/docs/assets/js/92b7d874.a69b898c.js +0 -1
  140. package/docs/assets/js/9334cb7c.2d33ddf8.js +0 -1
  141. package/docs/assets/js/935f2afb.a8948813.js +0 -1
  142. package/docs/assets/js/969412eb.cb2451c8.js +0 -1
  143. package/docs/assets/js/9be94766.2925f488.js +0 -1
  144. package/docs/assets/js/9dd5329b.6f458fc4.js +0 -1
  145. package/docs/assets/js/ab2af742.ff411c9b.js +0 -1
  146. package/docs/assets/js/ba6f0f15.5a9e407a.js +0 -1
  147. package/docs/assets/js/ccb851b4.71647e94.js +0 -1
  148. package/docs/assets/js/d4323bca.9bf7bf5a.js +0 -2
  149. package/docs/assets/js/d4323bca.9bf7bf5a.js.LICENSE.txt +0 -1
  150. package/docs/assets/js/e2aa7f69.b5afb674.js +0 -1
  151. package/docs/assets/js/ef3f9d02.841c2fab.js +0 -1
  152. package/docs/assets/js/f7d87c57.af927e77.js +0 -1
  153. package/docs/assets/js/f97ec998.133018f9.js +0 -1
  154. package/docs/assets/js/fdb649b1.86925c6b.js +0 -1
  155. package/docs/assets/js/main.98037fba.js +0 -2
  156. package/docs/assets/js/runtime~main.7aa653bc.js +0 -1
  157. package/es/bb1b9025.esm.es5.production.mjs +0 -1
  158. /package/docs/assets/js/{0c2147ef.6eb74fc2.js.LICENSE.txt → 114.c257b8b0.js.LICENSE.txt} +0 -0
  159. /package/docs/assets/js/{888.800281f1.js.LICENSE.txt → 5888.a314615c.js.LICENSE.txt} +0 -0
  160. /package/docs/assets/js/{main.98037fba.js.LICENSE.txt → main.15afa47b.js.LICENSE.txt} +0 -0
package/cjs/enum.js CHANGED
@@ -36,8 +36,8 @@ function createEnum(items) {
36
36
  return enumArray;
37
37
  } // 使用示例
38
38
  // const genders = createEnum([
39
- // { label: '男', value: 1, key: 'MAN', a: 1 },
40
- // { label: '女', value: '2', key: 'WOMAN' },
39
+ // { label: '男', value: 1, key: 'MAN', a: 1 },
40
+ // { label: '女', value: '2', key: 'WOMAN' },
41
41
  // ] as const);
42
42
  // console.log(genders.MAN); // 鼠标悬停显示类型为 1
43
43
  // console.log(genders.pick('MAN')); // 返回MAN的完整对象
package/cjs/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export * from './other';
5
5
  export * from './param';
6
6
  export * from './request';
7
7
  export * from './time';
8
+ export * from './string';
package/cjs/index.js CHANGED
@@ -10,3 +10,4 @@ _exportStar(require("./other"), exports);
10
10
  _exportStar(require("./param"), exports);
11
11
  _exportStar(require("./request"), exports);
12
12
  _exportStar(require("./time"), exports);
13
+ _exportStar(require("./string"), exports);
package/cjs/loading.js CHANGED
@@ -40,10 +40,10 @@ var showLoading = function() {
40
40
  if (!document.getElementById(styleId)) {
41
41
  var style = document.createElement("style");
42
42
  style.id = styleId;
43
- style.innerHTML = "\n .".concat(id, " {\n position: fixed;\n left: 0;\n top: 0;\n width: 100vw;\n height: 100vh;\n display: flex;\n justify-content: center;\n align-items: center;\n pointer-events: none;\n z-index: 10000;\n }\n .").concat(id, ".show-mask {\n pointer-events: unset;\n background: #00000070;\n }\n .").concat(id, " .mask-wrapper {\n position: fixed;\n }\n .").concat(id, " .loading-wrapper {\n width: 120px;\n height: 120px;\n z-index: 8000;\n background: rgba(0, 0, 0, 0.6);\n border-radius: 8px;\n text-align: center;\n color: white;\n display: flex;\n justify-content: center;\n flex-direction: column;\n align-items: center;\n pointer-events: initial;\n line-height: 1.3;\n }\n .").concat(id, " .loading-wrapper img {\n width: 50px;\n height: 50px;\n margin-bottom: 10px;\n }\n .").concat(id, " .loading-wrapper a {\n color: #6ab2ff;\n }");
43
+ style.innerHTML = "\n .".concat(id, " {\n position: fixed;\n left: 0;\n top: 0;\n width: 100vw;\n height: 100vh;\n display: flex;\n justify-content: center;\n align-items: center;\n pointer-events: none;\n z-index: 10000;\n }\n .").concat(id, ".show-mask {\n pointer-events: unset;\n background: #00000070;\n }\n .").concat(id, " .mask-wrapper {\n position: fixed;\n }\n .").concat(id, " .loading-wrapper {\n width: 120px;\n height: 120px;\n z-index: 8000;\n background: rgba(0, 0, 0, 0.6);\n border-radius: 8px;\n text-align: center;\n color: white;\n display: flex;\n justify-content: center;\n flex-direction: column;\n align-items: center;\n pointer-events: initial;\n line-height: 1.3;\n }\n .").concat(id, " .loading-wrapper img {\n width: 50px;\n height: 50px;\n margin-bottom: 10px;\n }\n .").concat(id, " .loading-wrapper a {\n color: #6ab2ff;\n }");
44
44
  document.head.appendChild(style);
45
45
  }
46
- dom.innerHTML = '\n <div class="loading-wrapper">\n <img src="https://img.alicdn.com/tfs/TB1bnUsQBLoK1RjSZFuXXXn0XXa-32-32.svg" alt="加载中">\n <div>\n <span>'.concat(text, "</span>\n ").concat(cancelInline ? "" : "<br />", "\n ").concat(onCancel ? '<a href="javascript:;" class="cancel">取消</a>' : "", "\n </div>\n </div>");
46
+ dom.innerHTML = '\n <div class="loading-wrapper">\n <img src="https://img.alicdn.com/tfs/TB1bnUsQBLoK1RjSZFuXXXn0XXa-32-32.svg" alt="加载中">\n <div>\n <span>'.concat(text, "</span>\n ").concat(cancelInline ? "" : "<br />", "\n ").concat(onCancel ? '<a href="javascript:;" class="cancel">取消</a>' : "", "\n </div>\n </div>");
47
47
  if (onCancel) {
48
48
  var btn = dom.querySelector(".cancel");
49
49
  btn && btn.addEventListener("click", function() {
package/cjs/message.js CHANGED
@@ -19,11 +19,11 @@ function initWindowMessage(scene, targetWindow) {
19
19
  return functionId;
20
20
  };
21
21
  var postMessage = /**
22
- * 发送消息并等待响应
23
- * @param {string} eventName 事件名称
24
- * @param {*} [payload] 负载数据
25
- * @returns {Promise} 返回一个Promise,resolve接收回调数据
26
- */ function postMessage(eventName) {
22
+ * 发送消息并等待响应
23
+ * @param {string} eventName 事件名称
24
+ * @param {*} [payload] 负载数据
25
+ * @returns {Promise} 返回一个Promise,resolve接收回调数据
26
+ */ function postMessage(eventName) {
27
27
  for(var _len = arguments.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
28
28
  payload[_key - 1] = arguments[_key];
29
29
  }
@@ -49,10 +49,10 @@ function initWindowMessage(scene, targetWindow) {
49
49
  });
50
50
  };
51
51
  var onMessage = /**
52
- * 监听消息
53
- * @param {string} eventName 事件名称
54
- * @param {function} listener 监听函数(支持异步):(...params) => callbackValue
55
- */ function onMessage(eventName, listener) {
52
+ * 监听消息
53
+ * @param {string} eventName 事件名称
54
+ * @param {function} listener 监听函数(支持异步):(...params) => callbackValue
55
+ */ function onMessage(eventName, listener) {
56
56
  if (!eventListeners.has(eventName)) eventListeners.set(eventName, []);
57
57
  eventListeners.get(eventName).push(listener);
58
58
  };
package/cjs/other.d.ts CHANGED
@@ -26,3 +26,17 @@ export declare const decodeHtml: (html: string | any) => any;
26
26
  * @returns
27
27
  */
28
28
  export declare const copyToClipboard: (text: string, onFailure: (message: string) => void, supportSilent: boolean) => Promise<void>;
29
+ /**
30
+ * 获取身份证号第18位校验码
31
+ * @params cid 身份证号码,17或18位均可
32
+ */
33
+ export declare const getIdCardLastChar: (cid: string) => string;
34
+ /**
35
+ * 检测某个身份证ID是否合法,包括长度和最后一位校验码检测
36
+ * @params cid 身份证号码,必须是18位
37
+ */
38
+ export declare const validateIdCard: (cid: string) => boolean;
39
+ /**
40
+ * 键盘键值映射,如: keyCodes.ctrl == 17
41
+ */
42
+ export declare const keyCodes: Record<string, number>;
package/cjs/other.js CHANGED
@@ -24,6 +24,15 @@ _export(exports, {
24
24
  },
25
25
  copyToClipboard: function() {
26
26
  return copyToClipboard;
27
+ },
28
+ getIdCardLastChar: function() {
29
+ return getIdCardLastChar;
30
+ },
31
+ validateIdCard: function() {
32
+ return validateIdCard;
33
+ },
34
+ keyCodes: function() {
35
+ return keyCodes;
27
36
  }
28
37
  });
29
38
  var deepCopy = function(obj) {
@@ -79,3 +88,80 @@ var copyToClipboard = function(text, onFailure, supportSilent) {
79
88
  }
80
89
  });
81
90
  };
91
+ var getIdCardLastChar = function(cid) {
92
+ if (!cid || cid.length < 17) throw new Error("传入的身份证号长度必须>=17");
93
+ var weights = [
94
+ 7,
95
+ 9,
96
+ 10,
97
+ 5,
98
+ 8,
99
+ 4,
100
+ 2,
101
+ 1,
102
+ 6,
103
+ 3,
104
+ 7,
105
+ 9,
106
+ 10,
107
+ 5,
108
+ 8,
109
+ 4,
110
+ 2
111
+ ]; // 十七位数字权重
112
+ var validates = [
113
+ "1",
114
+ "0",
115
+ "X",
116
+ "9",
117
+ "8",
118
+ "7",
119
+ "6",
120
+ "5",
121
+ "4",
122
+ "3",
123
+ "2"
124
+ ]; // 校验码
125
+ var sum = 0;
126
+ for(var i = 0; i < 17; i++)sum += parseInt(cid.charAt(i), 10) * weights[i];
127
+ return validates[sum % 11];
128
+ };
129
+ var validateIdCard = function(cid) {
130
+ if (!cid || cid.length !== 18) {
131
+ console.error("身份证号不是18位!");
132
+ return false;
133
+ }
134
+ return "".concat(getIdCardLastChar(cid)) === cid.charAt(17);
135
+ };
136
+ var keyCodes = function() {
137
+ var keys = {
138
+ backspace: 8,
139
+ tab: 9,
140
+ clear: 12,
141
+ enter: 13,
142
+ shift: 16,
143
+ ctrl: 17,
144
+ alt: 18,
145
+ esc: 27,
146
+ space: 32,
147
+ pageup: 33,
148
+ pagedown: 34,
149
+ end: 35,
150
+ home: 36,
151
+ left: 37,
152
+ up: 38,
153
+ right: 39,
154
+ down: 40,
155
+ insert: 45,
156
+ delete: 46
157
+ };
158
+ // 数字0-9
159
+ for(var i = 48; i <= 57; i++)keys[String.fromCharCode(i)] = i;
160
+ // 字母a-z
161
+ for(var i1 = 65; i1 <= 90; i1++)keys[String.fromCharCode(i1).toLowerCase()] = i1;
162
+ // 小键盘数字0-9,这里用num0-num9表示
163
+ for(var i2 = 96; i2 <= 105; i2++)keys["num".concat(i2 - 96)] = i2;
164
+ // f1-f12功能键
165
+ for(var i3 = 112; i3 <= 123; i3++)keys["f".concat(i3 - 111)] = i3;
166
+ return keys;
167
+ }();
package/cjs/request.d.ts CHANGED
@@ -22,16 +22,22 @@ export interface IRequestOptions {
22
22
  checkSuccess?: (resp: any) => boolean;
23
23
  /** 对响应进行自定义格式化处理,包含 checkSuccess 全部能力 */
24
24
  responseConverter?: (resp: any) => any;
25
- /** 后端未返回 message 时的兜底异常文案 */
25
+ /** @deprecated 后端未返回 message 时的默认异常文案,由于名称经常引发歧义,估改名为 defaultErrorMessage */
26
26
  errorMessage?: string;
27
+ /** 后端未返回 message 时的默认异常文案 */
28
+ defaultErrorMessage?: string;
27
29
  /** 发生异常时的处理方法,一般不太建议重写此方法 */
28
- errorHandler?: (message: string, resp?: any) => void;
30
+ errorHandler?: (message: string, resp: any, options: IRequestOptions) => void;
29
31
  /** 自定义toast实现,为了和UI解耦,方法默认不包含UI处理代码 */
30
32
  toastHandler?: (message: string) => void;
31
33
  /** 是否关闭默认的异常toast */
32
34
  silent?: boolean;
33
35
  /** 自定义 fetch.then() ,非常底层的一个方法,非必要请勿使用 */
34
36
  onFetchResponse?: (response: Response) => any;
37
+ /** 切换loading状态的方法,会在开始请求前置为true,结束时置为false。为什么设计这个方法?在非hooks场景下更方便的切换loading状态 */
38
+ setLoading?: (loading?: boolean) => void;
39
+ /** 覆盖默认的 resp.message 自定义异常抛出文案,也支持传入方法,注意返回''和undefined效果不同 */
40
+ overrideMessage?: string | ((resp: any) => string);
35
41
  }
36
42
  /**
37
43
  * 通用的API请求方法
package/cjs/request.js CHANGED
@@ -16,9 +16,15 @@ _export(exports, {
16
16
  return Request;
17
17
  }
18
18
  });
19
+ var _assertThisInitialized = require("@swc/helpers/lib/_assert_this_initialized.js").default;
19
20
  var _asyncToGenerator = require("@swc/helpers/lib/_async_to_generator.js").default;
21
+ var _classCallCheck = require("@swc/helpers/lib/_class_call_check.js").default;
22
+ var _inherits = require("@swc/helpers/lib/_inherits.js").default;
20
23
  var _instanceof = require("@swc/helpers/lib/_instanceof.js").default;
21
24
  var _objectSpread = require("@swc/helpers/lib/_object_spread.js").default;
25
+ var _objectSpreadProps = require("@swc/helpers/lib/_object_spread_props.js").default;
26
+ var _wrapNativeSuper = require("@swc/helpers/lib/_wrap_native_super.js").default;
27
+ var _createSuper = require("@swc/helpers/lib/_create_super.js").default;
22
28
  var _tsGenerator = require("@swc/helpers/lib/_ts_generator.js").default;
23
29
  var _param = require("./param");
24
30
  /** 合并2个options对象 */ var mergeOptions = function(ops1, ops2) {
@@ -30,6 +36,21 @@ var _param = require("./param");
30
36
  fetchOptions: fetchOptions
31
37
  });
32
38
  };
39
+ /**
40
+ * 支持传入自定义属性的Error对象,包括 cause
41
+ */ var MyError = /*#__PURE__*/ function(Error1) {
42
+ "use strict";
43
+ _inherits(MyError, Error1);
44
+ var _super = _createSuper(MyError);
45
+ function MyError(message, options) {
46
+ _classCallCheck(this, MyError);
47
+ var _this;
48
+ _this = _super.call(this, message);
49
+ Object.assign(_assertThisInitialized(_this), options || {});
50
+ return _this;
51
+ }
52
+ return MyError;
53
+ }(_wrapNativeSuper(Error));
33
54
  /**
34
55
  * 通用的API请求方法
35
56
  * @param url
@@ -37,17 +58,17 @@ var _param = require("./param");
37
58
  * @returns
38
59
  */ var request = function() {
39
60
  var _ref = _asyncToGenerator(function(url, options) {
40
- var defaultOptions, _ref, params, data, formData, json, method, headers, baseUrl, fetchOptions, checkSuccess, afterRequest, errorHandler, errorMessage, responseConverter, onFetchResponse, body, key, resp, _location_pathname_split, targetUrl, e, _e_response;
61
+ var defaultOptions, _ref, params, data, formData, json, method, headers, baseUrl, fetchOptions, checkSuccess, afterRequest, errorHandler, errorMessage, responseConverter, onFetchResponse, setLoading, overrideMessage, defaultErrorMessage, body, key, resp, _location_pathname_split, targetUrl, e, _e_response, localMessage, localMessage1;
41
62
  return _tsGenerator(this, function(_state) {
42
63
  switch(_state.label){
43
64
  case 0:
44
65
  defaultOptions = {
45
66
  errorMessage: "系统繁忙,请稍后再试",
46
- errorHandler: function(msg) {
67
+ errorHandler: function(message) {
47
68
  var _options_toastHandler;
48
- if (!(options === null || options === void 0 ? void 0 : options.silent)) options === null || options === void 0 ? void 0 : (_options_toastHandler = options.toastHandler) === null || _options_toastHandler === void 0 ? void 0 : _options_toastHandler.call(options, msg);
69
+ if (!(options === null || options === void 0 ? void 0 : options.silent) && message) options === null || options === void 0 ? void 0 : (_options_toastHandler = options.toastHandler) === null || _options_toastHandler === void 0 ? void 0 : _options_toastHandler.call(options, message);
49
70
  // 抛出异常,阻止执行之后的操作
50
- throw new Error(msg);
71
+ throw new Error(message);
51
72
  },
52
73
  baseUrl: "",
53
74
  headers: {},
@@ -63,21 +84,18 @@ var _param = require("./param");
63
84
  },
64
85
  onFetchResponse: function(response) {
65
86
  if (response.status === 200) return response.json();
66
- var errorResponse = {
67
- code: response.status,
68
- status: response.status,
69
- message: response.statusText,
70
- headers: response.headers,
71
- // 返回整个response备用,但是一般不推荐用户直接使用
72
- _response: response
73
- };
74
- var error = new Error(errorResponse.message);
75
- error.response = errorResponse;
76
- throw error;
87
+ throw new MyError(response.statusText, {
88
+ response: _objectSpreadProps(_objectSpread({}, response), {
89
+ code: response.status,
90
+ message: response.statusText,
91
+ /** 标记这是HTTP原始响应,并非服务端返回数据 */ isHttpResponse: true
92
+ })
93
+ });
77
94
  }
78
95
  };
79
96
  options = mergeOptions(defaultOptions, options);
80
- _ref = options || {}, params = _ref.params, data = _ref.data, formData = _ref.formData, json = _ref.json, method = _ref.method, headers = _ref.headers, baseUrl = _ref.baseUrl, fetchOptions = _ref.fetchOptions, checkSuccess = _ref.checkSuccess, afterRequest = _ref.afterRequest, errorHandler = _ref.errorHandler, errorMessage = _ref.errorMessage, responseConverter = _ref.responseConverter, onFetchResponse = _ref.onFetchResponse;
97
+ _ref = options || {}, params = _ref.params, data = _ref.data, formData = _ref.formData, json = _ref.json, method = _ref.method, headers = _ref.headers, baseUrl = _ref.baseUrl, fetchOptions = _ref.fetchOptions, checkSuccess = _ref.checkSuccess, afterRequest = _ref.afterRequest, errorHandler = _ref.errorHandler, errorMessage = _ref.errorMessage, responseConverter = _ref.responseConverter, onFetchResponse = _ref.onFetchResponse, setLoading = _ref.setLoading, overrideMessage = _ref.overrideMessage;
98
+ defaultErrorMessage = (options === null || options === void 0 ? void 0 : options.defaultErrorMessage) || errorMessage;
81
99
  // fetchOptions 里面的 headers 优先级高于外部的 headers
82
100
  fetchOptions.headers = _objectSpread({}, headers || {}, fetchOptions.headers || {});
83
101
  if (params) {
@@ -109,6 +127,7 @@ var _param = require("./param");
109
127
  }, fetchOptions.headers || {})
110
128
  });
111
129
  resp = null;
130
+ setLoading === null || setLoading === void 0 ? void 0 : setLoading(true);
112
131
  _state.label = 1;
113
132
  case 1:
114
133
  _state.trys.push([
@@ -133,15 +152,16 @@ var _param = require("./param");
133
152
  case 3:
134
153
  e = _state.sent();
135
154
  console.error(e);
136
- afterRequest === null || afterRequest === void 0 ? void 0 : afterRequest(false, {
137
- message: e === null || e === void 0 ? void 0 : e.message
138
- });
139
- errorHandler === null || errorHandler === void 0 ? void 0 : errorHandler(((_e_response = e.response) === null || _e_response === void 0 ? void 0 : _e_response.message) || errorMessage || "", e.response);
155
+ setLoading === null || setLoading === void 0 ? void 0 : setLoading(false);
156
+ afterRequest === null || afterRequest === void 0 ? void 0 : afterRequest(false, e.response);
157
+ localMessage = typeof overrideMessage === "function" ? overrideMessage(e.response) : overrideMessage;
158
+ errorHandler === null || errorHandler === void 0 ? void 0 : errorHandler(localMessage !== null && localMessage !== void 0 ? localMessage : ((_e_response = e.response) === null || _e_response === void 0 ? void 0 : _e_response.message) || defaultErrorMessage, e.response, options);
140
159
  return [
141
160
  2,
142
161
  undefined
143
162
  ];
144
163
  case 4:
164
+ setLoading === null || setLoading === void 0 ? void 0 : setLoading(false);
145
165
  resp = responseConverter ? responseConverter(resp) : resp;
146
166
  if (checkSuccess === null || checkSuccess === void 0 ? void 0 : checkSuccess(resp)) {
147
167
  afterRequest === null || afterRequest === void 0 ? void 0 : afterRequest(true, resp);
@@ -151,7 +171,8 @@ var _param = require("./param");
151
171
  ];
152
172
  } else {
153
173
  afterRequest === null || afterRequest === void 0 ? void 0 : afterRequest(false, resp);
154
- errorHandler === null || errorHandler === void 0 ? void 0 : errorHandler(resp.message || resp.msg || errorMessage || "", resp);
174
+ localMessage1 = typeof overrideMessage === "function" ? overrideMessage(resp) : overrideMessage;
175
+ errorHandler === null || errorHandler === void 0 ? void 0 : errorHandler(localMessage1 !== null && localMessage1 !== void 0 ? localMessage1 : resp.message || defaultErrorMessage, resp, options);
155
176
  return [
156
177
  2,
157
178
  undefined
@@ -0,0 +1,42 @@
1
+ /**
2
+ * 格式化一段JSON字符串,支持解析非标准JSON
3
+ * 不同于绝大多数格式化工具,本方法支持设置缩进方式以及左大括号是否换行
4
+ * @start 2016-08-24
5
+ * @param {Object} json 要格式化的json串
6
+ * @param {Object} indent 缩进方式,可以是若干个空格和tab,默认tab缩进,如 2个空格:" "、4个空格:" "、tab:" "
7
+ * @param {Object} leftBracesInSameLine 左大括号是否保持在同一行,默认 false
8
+ */
9
+ export declare const formatJson: (json: string, indent?: string, leftBracesInSameLine?: boolean) => string;
10
+ /**
11
+ * 获取各种随机数,支持如下几种调用方式:
12
+ * getRandom() 返回0-1的随机小数,等同于Math.random(),0 <= result < 1
13
+ * getRandom(start, end) 返回start-end的随机整数,start <= result < end
14
+ * getRandom(end) 返回0-end的随机整数,0 <= result < end
15
+ * getRandom(array) 随机返回数组中的某一个内容
16
+ * getRandom(array, count) 随机从数组中返回长度为count的不重复内容组成的新数组,如果不足count个,返回全部 并乱序
17
+ * @param {Object} start
18
+ * @param {Object} end
19
+ * @return {Object}
20
+ */
21
+ export declare const getRandom: (start?: any, end?: any) => any;
22
+ /**
23
+ * 获取随机字符串
24
+ * @param length 字符串长度
25
+ * @param type all 表示所有,number表示仅数字,默认所有
26
+ * @return string
27
+ */
28
+ export declare const getRandomStr: (length: number, type?: 'number' | 'all') => string;
29
+ /**
30
+ * 字符串转下划线形式,示例:getParam 转 get_param
31
+ * @param str 要转换的字符串
32
+ * @param flag 默认下划线-,也可以传其它字符
33
+ */
34
+ export declare const toUnderline: (str: string, flag?: string) => string;
35
+ /**
36
+ * 字符串转驼峰形式
37
+ * 示例一: toHump('get_param'),返回getParam
38
+ * 示例二: toHump('font-size','-'),返回fontSize
39
+ * @param str
40
+ * @param 分割的标志,默认为“_”
41
+ */
42
+ export declare const toHump: (str: string, flag?: string) => string;
package/cjs/string.js ADDED
@@ -0,0 +1,108 @@
1
+ /**
2
+ * 格式化一段JSON字符串,支持解析非标准JSON
3
+ * 不同于绝大多数格式化工具,本方法支持设置缩进方式以及左大括号是否换行
4
+ * @start 2016-08-24
5
+ * @param {Object} json 要格式化的json串
6
+ * @param {Object} indent 缩进方式,可以是若干个空格和tab,默认tab缩进,如 2个空格:" "、4个空格:" "、tab:" "
7
+ * @param {Object} leftBracesInSameLine 左大括号是否保持在同一行,默认 false
8
+ */ "use strict";
9
+ Object.defineProperty(exports, "__esModule", {
10
+ value: true
11
+ });
12
+ function _export(target, all) {
13
+ for(var name in all)Object.defineProperty(target, name, {
14
+ enumerable: true,
15
+ get: all[name]
16
+ });
17
+ }
18
+ _export(exports, {
19
+ formatJson: function() {
20
+ return formatJson;
21
+ },
22
+ getRandom: function() {
23
+ return getRandom;
24
+ },
25
+ getRandomStr: function() {
26
+ return getRandomStr;
27
+ },
28
+ toUnderline: function() {
29
+ return toUnderline;
30
+ },
31
+ toHump: function() {
32
+ return toHump;
33
+ }
34
+ });
35
+ var _instanceof = require("@swc/helpers/lib/_instanceof.js").default;
36
+ var formatJson = function(json, indent, leftBracesInSameLine) {
37
+ var getIndentStr = function getIndentStr(level) {
38
+ var str = "";
39
+ for(var i = 0; i < level; i++)str += indent || " ";
40
+ return str;
41
+ };
42
+ function format(obj, level) {
43
+ level = level === undefined ? 0 : level;
44
+ var result = "";
45
+ // 如果是object或者array
46
+ if (typeof obj === "object" && obj != null) {
47
+ var isArray = _instanceof(obj, Array);
48
+ var idx = 0;
49
+ result += "".concat(isArray ? "[" : "{", "\n");
50
+ for(var i in obj){
51
+ result += idx++ > 0 ? ",\n" : ""; // 如果不是数组或对象的第一个内容,追加逗号
52
+ var nextIsObj = typeof obj[i] === "object" && obj[i] != null;
53
+ var indentStr = getIndentStr(level + 1);
54
+ result += isArray && nextIsObj ? "" : indentStr; // 如果当前是数组并且子项是对象,无需缩进
55
+ result += isArray ? "" : '"'.concat(i, '": ').concat(nextIsObj && !leftBracesInSameLine ? "\n" : "");
56
+ result += !nextIsObj || nextIsObj && leftBracesInSameLine && !isArray ? "" : indentStr;
57
+ result += format(obj[i], level + 1); // 递归调用
58
+ }
59
+ result += "\n".concat(getIndentStr(level)).concat(isArray ? "]" : "}");
60
+ } else {
61
+ // 如果是 null、number、boolean、string
62
+ var quot = typeof obj === "string" ? '"' : ""; // 是否是字符串
63
+ result += "".concat(quot).concat(obj).concat(quot);
64
+ }
65
+ return result;
66
+ }
67
+ // eslint-disable-next-line no-eval
68
+ return format(eval("(".concat(json, ")"))); // 使用eval的好处是可以解析非标准JSON
69
+ };
70
+ var getRandom = function(start, end) {
71
+ if (typeof start === "number") {
72
+ if (typeof end === "undefined") {
73
+ end = start;
74
+ start = 0;
75
+ }
76
+ return start + Math.floor(Math.random() * (end - start));
77
+ } else if (_instanceof(start, Array)) {
78
+ if (typeof end === "undefined") {
79
+ if (start.length === 0) return null;
80
+ if (start.length === 1) return start[0];
81
+ return start[Math.floor(Math.random() * start.length)];
82
+ } else {
83
+ start.sort(function() {
84
+ return Math.random() > 0.5 ? 1 : -1;
85
+ });
86
+ return start.slice(0, end);
87
+ }
88
+ }
89
+ return Math.random();
90
+ };
91
+ var getRandomStr = function(length, type) {
92
+ length = length || 18;
93
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz0123456789".split("");
94
+ if (type === "number") chars = "0123456789".split("");
95
+ var result = "";
96
+ for(var i = 0; i < length; i++)result += getRandom(chars);
97
+ return result;
98
+ };
99
+ var toUnderline = function(str, flag) {
100
+ return str.replace(/([A-Z])/g, function(m, $1) {
101
+ return "".concat(flag || "_").concat($1.toLowerCase());
102
+ });
103
+ };
104
+ var toHump = function(str, flag) {
105
+ return str.replace(new RegExp("".concat(flag || "_", "(\\w)"), "g"), function(_m, $1) {
106
+ return $1.toUpperCase();
107
+ });
108
+ };
package/docs/404.html CHANGED
@@ -4,13 +4,13 @@
4
4
  <meta charset="UTF-8">
5
5
  <meta name="generator" content="Docusaurus v2.4.3">
6
6
  <title data-rh="true">找不到页面 | youtil文档</title><meta data-rh="true" name="viewport" content="width=device-width,initial-scale=1"><meta data-rh="true" name="twitter:card" content="summary_large_image"><meta data-rh="true" property="og:url" content="https://your-docusaurus-test-site.com/404.html"><meta data-rh="true" name="docusaurus_locale" content="zh-Hans"><meta data-rh="true" name="docusaurus_tag" content="default"><meta data-rh="true" name="docsearch:language" content="zh-Hans"><meta data-rh="true" name="docsearch:docusaurus_tag" content="default"><meta data-rh="true" property="og:title" content="找不到页面 | youtil文档"><link data-rh="true" rel="icon" href="https://img.alicdn.com/imgextra/i2/O1CN01jUf9ZP1aKwVvEc58W_!!6000000003312-73-tps-160-160.ico"><link data-rh="true" rel="canonical" href="https://your-docusaurus-test-site.com/404.html"><link data-rh="true" rel="alternate" href="https://your-docusaurus-test-site.com/404.html" hreflang="zh-Hans"><link data-rh="true" rel="alternate" href="https://your-docusaurus-test-site.com/404.html" hreflang="x-default"><link rel="stylesheet" href="/assets/css/styles.077146e6.css">
7
- <link rel="preload" href="/assets/js/runtime~main.7aa653bc.js" as="script">
8
- <link rel="preload" href="/assets/js/main.98037fba.js" as="script">
7
+ <link rel="preload" href="/assets/js/runtime~main.1ee1dff9.js" as="script">
8
+ <link rel="preload" href="/assets/js/main.15afa47b.js" as="script">
9
9
  </head>
10
10
  <body class="navigation-with-keyboard">
11
11
  <script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}return t}()||function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus">
12
12
  <div role="region" aria-label="跳到主要内容"><a class="skipToContent_fXgn" href="#__docusaurus_skipToContent_fallback">跳到主要内容</a></div><nav aria-label="主导航" class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><a class="navbar__brand" href="/"><div class="navbar__logo"><img src="/static/1.jpg" alt="" class="themedImage_ToTc themedImage--light_HNdA"><img src="/static/1.jpg" alt="" class="themedImage_ToTc themedImage--dark_i4oU"></div><b class="navbar__title text--truncate">youtil (油梯)</b></a></div><div class="navbar__items navbar__items--right"><div class="toggle_vylO colorModeToggle_DEke"><button class="clean-btn toggleButton_gllP toggleButtonDisabled_aARS" type="button" disabled="" title="切换浅色/暗黑模式(当前为浅色模式)" aria-label="切换浅色/暗黑模式(当前为浅色模式)" aria-live="polite"><svg viewBox="0 0 24 24" width="24" height="24" class="lightToggleIcon_pyhR"><path fill="currentColor" d="M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.99c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06c-0.39,0.39-0.39,1.03,0,1.41 s1.03,0.39,1.41,0L19.42,5.99z M7.05,18.36c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06 c-0.39,0.39-0.39,1.03,0,1.41s1.03,0.39,1.41,0L7.05,18.36z"></path></svg><svg viewBox="0 0 24 24" width="24" height="24" class="darkToggleIcon_wfgR"><path fill="currentColor" d="M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z"></path></svg></button></div><div class="searchBox_ZlJk"></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div></nav><div id="__docusaurus_skipToContent_fallback" class="main-wrapper mainWrapper_z2l0"><main class="container margin-vert--xl"><div class="row"><div class="col col--6 col--offset-3"><h1 class="hero__title">找不到页面</h1><p>我们找不到您要找的页面。</p><p>请联系原始链接来源网站的所有者,并告知他们链接已损坏。</p></div></div></main></div></div>
13
- <script src="/assets/js/runtime~main.7aa653bc.js"></script>
14
- <script src="/assets/js/main.98037fba.js"></script>
13
+ <script src="/assets/js/runtime~main.1ee1dff9.js"></script>
14
+ <script src="/assets/js/main.15afa47b.js"></script>
15
15
  </body>
16
16
  </html>
package/docs/CNAME ADDED
@@ -0,0 +1 @@
1
+ youtil.haoji.me