youtil 3.1.0-beta3 → 3.1.1

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 (271) hide show
  1. package/README.md +2 -3
  2. package/dist/index.mjs +14 -14
  3. package/dist/index.umd.js +14 -14
  4. package/dist/types/enum.d.ts +19 -11
  5. package/docs/404.html +20 -12
  6. package/docs/574.483e4d8b.async.js +15 -0
  7. package/docs/574.e8c51481.chunk.css +5 -0
  8. package/docs/762.1d61e7db.async.js +3 -0
  9. package/docs/831.f94499ec.async.js +137 -0
  10. package/docs/972.5b978da2.async.js +22 -0
  11. package/docs/CNAME +1 -1
  12. package/docs/api/functions/copy-to-clipboard/index.html +24 -0
  13. package/docs/api/functions/create-enum/index.html +24 -0
  14. package/docs/api/functions/decode-html/index.html +24 -0
  15. package/docs/api/functions/deep-copy/index.html +24 -0
  16. package/docs/api/functions/del-param/index.html +24 -0
  17. package/docs/api/functions/encode-html/index.html +24 -0
  18. package/docs/api/functions/format-date/index.html +24 -0
  19. package/docs/api/functions/format-json/index.html +24 -0
  20. package/docs/api/functions/get-id-card-last-char/index.html +24 -0
  21. package/docs/api/functions/get-param/index.html +24 -0
  22. package/docs/api/functions/get-param-int/index.html +24 -0
  23. package/docs/api/functions/get-params/index.html +24 -0
  24. package/docs/api/functions/get-random/index.html +24 -0
  25. package/docs/api/functions/get-random-str/index.html +24 -0
  26. package/docs/api/functions/hide-loading/index.html +24 -0
  27. package/docs/api/functions/init-window-message/index.html +24 -0
  28. package/docs/api/functions/parse-date/index.html +24 -0
  29. package/docs/api/functions/request/index.html +20 -12
  30. package/docs/api/functions/set-param/index.html +24 -0
  31. package/docs/api/functions/show-loading/index.html +24 -0
  32. package/docs/api/functions/sleep/index.html +20 -13
  33. package/docs/api/functions/to-hump/index.html +24 -0
  34. package/docs/api/functions/to-underline/index.html +24 -0
  35. package/docs/api/functions/to-url-params/index.html +24 -0
  36. package/docs/api/functions/validate-id-card/index.html +24 -0
  37. package/docs/api/globals/index.html +20 -12
  38. package/docs/api/interfaces/i-request-options/index.html +24 -0
  39. package/docs/api/interfaces/i-show-loading-config/index.html +24 -0
  40. package/docs/api/type-aliases/enum-item/index.html +24 -0
  41. package/docs/api/type-aliases/enum-type/index.html +24 -0
  42. package/docs/api/variables/key-codes/index.html +24 -0
  43. package/docs/api/variables/request/index.html +24 -0
  44. package/docs/dumi__tmp-production__dumi__theme__ContextWrapper.ab2cd1e2.async.js +1 -0
  45. package/docs/guide/enum/index.html +24 -0
  46. package/docs/guide/index.html +24 -0
  47. package/docs/guide/loading/index.html +24 -0
  48. package/docs/guide/message/index.html +24 -0
  49. package/docs/guide/request/index.html +24 -0
  50. package/docs/index.html +20 -12
  51. package/docs/markdown__api__functions__copyToClipboard.md.33be0665.chunk.css +1 -0
  52. package/docs/markdown__api__functions__copyToClipboard.md.fa13570e.async.js +3 -0
  53. package/docs/markdown__api__functions__createEnum.md.33be0665.chunk.css +1 -0
  54. package/docs/markdown__api__functions__createEnum.md.ab0957ee.async.js +8 -0
  55. package/docs/markdown__api__functions__decodeHtml.md.33be0665.chunk.css +1 -0
  56. package/docs/markdown__api__functions__decodeHtml.md.922bf499.async.js +1 -0
  57. package/docs/markdown__api__functions__deepCopy.md.33be0665.chunk.css +1 -0
  58. package/docs/markdown__api__functions__deepCopy.md.4dea99a7.async.js +1 -0
  59. package/docs/markdown__api__functions__delParam.md.33be0665.chunk.css +1 -0
  60. package/docs/markdown__api__functions__delParam.md.dc0c2c8a.async.js +4 -0
  61. package/docs/markdown__api__functions__encodeHtml.md.33be0665.chunk.css +1 -0
  62. package/docs/markdown__api__functions__encodeHtml.md.d4d7ef49.async.js +1 -0
  63. package/docs/markdown__api__functions__formatDate.md.33be0665.chunk.css +1 -0
  64. package/docs/markdown__api__functions__formatDate.md.e43ecd6d.async.js +1 -0
  65. package/docs/markdown__api__functions__formatJson.md.33be0665.chunk.css +1 -0
  66. package/docs/markdown__api__functions__formatJson.md.56d52c5d.async.js +2 -0
  67. package/docs/markdown__api__functions__getIdCardLastChar.md.1a9f4c4c.async.js +1 -0
  68. package/docs/markdown__api__functions__getIdCardLastChar.md.33be0665.chunk.css +1 -0
  69. package/docs/markdown__api__functions__getParam.md.33be0665.chunk.css +1 -0
  70. package/docs/markdown__api__functions__getParam.md.65c4baf1.async.js +5 -0
  71. package/docs/markdown__api__functions__getParamInt.md.33be0665.chunk.css +1 -0
  72. package/docs/markdown__api__functions__getParamInt.md.e53ccbcf.async.js +1 -0
  73. package/docs/markdown__api__functions__getParams.md.33be0665.chunk.css +1 -0
  74. package/docs/markdown__api__functions__getParams.md.86dccf75.async.js +2 -0
  75. package/docs/markdown__api__functions__getRandom.md.2c03a03a.async.js +6 -0
  76. package/docs/markdown__api__functions__getRandom.md.33be0665.chunk.css +1 -0
  77. package/docs/markdown__api__functions__getRandomStr.md.33be0665.chunk.css +1 -0
  78. package/docs/markdown__api__functions__getRandomStr.md.7162c7eb.async.js +1 -0
  79. package/docs/markdown__api__functions__hideLoading.md.33be0665.chunk.css +1 -0
  80. package/docs/markdown__api__functions__hideLoading.md.63141f59.async.js +1 -0
  81. package/docs/markdown__api__functions__initWindowMessage.md.33be0665.chunk.css +1 -0
  82. package/docs/markdown__api__functions__initWindowMessage.md.4cecf804.async.js +1 -0
  83. package/docs/markdown__api__functions__parseDate.md.33be0665.chunk.css +1 -0
  84. package/docs/markdown__api__functions__parseDate.md.43f68864.async.js +1 -0
  85. package/docs/markdown__api__functions__request.md.33be0665.chunk.css +1 -0
  86. package/docs/markdown__api__functions__request.md.8100475a.async.js +1 -0
  87. package/docs/markdown__api__functions__setParam.md.33be0665.chunk.css +1 -0
  88. package/docs/markdown__api__functions__setParam.md.6122453b.async.js +3 -0
  89. package/docs/markdown__api__functions__showLoading.md.23c9d9cf.async.js +1 -0
  90. package/docs/markdown__api__functions__showLoading.md.33be0665.chunk.css +1 -0
  91. package/docs/markdown__api__functions__sleep.md.33be0665.chunk.css +1 -0
  92. package/docs/markdown__api__functions__sleep.md.65b4d778.async.js +2 -0
  93. package/docs/markdown__api__functions__toHump.md.33be0665.chunk.css +1 -0
  94. package/docs/markdown__api__functions__toHump.md.a648d9ca.async.js +3 -0
  95. package/docs/markdown__api__functions__toUnderline.md.33be0665.chunk.css +1 -0
  96. package/docs/markdown__api__functions__toUnderline.md.ab7a4578.async.js +1 -0
  97. package/docs/markdown__api__functions__toUrlParams.md.33be0665.chunk.css +1 -0
  98. package/docs/markdown__api__functions__toUrlParams.md.de7422f6.async.js +1 -0
  99. package/docs/markdown__api__functions__validateIdCard.md.33be0665.chunk.css +1 -0
  100. package/docs/markdown__api__functions__validateIdCard.md.ccfc4d2f.async.js +1 -0
  101. package/docs/markdown__api__globals.md.2389be1f.async.js +1 -0
  102. package/docs/markdown__api__globals.md.33be0665.chunk.css +1 -0
  103. package/docs/markdown__api__interfaces__IRequestOptions.md.33be0665.chunk.css +1 -0
  104. package/docs/markdown__api__interfaces__IRequestOptions.md.da2c2fdd.async.js +1 -0
  105. package/docs/markdown__api__interfaces__IShowLoadingConfig.md.09756000.async.js +1 -0
  106. package/docs/markdown__api__interfaces__IShowLoadingConfig.md.33be0665.chunk.css +1 -0
  107. package/docs/markdown__api__type-aliases__EnumItem.md.33be0665.chunk.css +1 -0
  108. package/docs/markdown__api__type-aliases__EnumItem.md.955a45d6.async.js +1 -0
  109. package/docs/markdown__api__type-aliases__EnumType.md.33be0665.chunk.css +1 -0
  110. package/docs/markdown__api__type-aliases__EnumType.md.efd1803a.async.js +1 -0
  111. package/docs/markdown__api__variables__Request.md.1dbabcda.async.js +1 -0
  112. package/docs/markdown__api__variables__Request.md.33be0665.chunk.css +1 -0
  113. package/docs/markdown__api__variables__keyCodes.md.33be0665.chunk.css +1 -0
  114. package/docs/markdown__api__variables__keyCodes.md.74858111.async.js +1 -0
  115. package/docs/markdown__guide__enum.md.33be0665.chunk.css +1 -0
  116. package/docs/markdown__guide__enum.md.b90b172d.async.js +1 -0
  117. package/docs/markdown__guide__index.md.33be0665.chunk.css +1 -0
  118. package/docs/markdown__guide__index.md.896aab37.async.js +13 -0
  119. package/docs/markdown__guide__loading.md.33be0665.chunk.css +1 -0
  120. package/docs/markdown__guide__loading.md.512e960b.async.js +1 -0
  121. package/docs/markdown__guide__message.md.0788a6e2.async.js +84 -0
  122. package/docs/markdown__guide__message.md.33be0665.chunk.css +1 -0
  123. package/docs/markdown__guide__request.md.33be0665.chunk.css +1 -0
  124. package/docs/markdown__guide__request.md.804eed5b.async.js +57 -0
  125. package/docs/markdown__index.md.33be0665.chunk.css +1 -0
  126. package/docs/markdown__index.md.9c254237.async.js +1 -0
  127. package/docs/meta__markdown.3bc0c0cf.async.js +310 -0
  128. package/docs/nm__dumi__dist__client__pages__404.816f7d6a.async.js +1 -0
  129. package/docs/nm__dumi__dist__client__pages__404.8b85f2d9.chunk.css +1 -0
  130. package/docs/nm__dumi__dist__client__pages__Demo__index.088e9a8b.async.js +1 -0
  131. package/docs/nm__dumi__dist__client__pages__Demo__index.578aa5c0.chunk.css +1 -0
  132. package/docs/nm__dumi__theme-default__layouts__DocLayout__index.363dcde9.async.js +1 -0
  133. package/docs/preload_helper.a0360861.js +1 -0
  134. package/docs/umi.04710f8f.js +104 -0
  135. package/docs/umi.4e0bcd92.css +1 -0
  136. package/docs/~demos/:id/index.html +24 -0
  137. package/docs/~demos/markdown-guide-enum-demo-0/index.html +24 -0
  138. package/docs/~demos/markdown-guide-loading-demo-0/index.html +24 -0
  139. package/docs/~demos/markdown-guide-request-demo-0/index.html +24 -0
  140. package/docs/~demos/markdown-guide-request-demo-1/index.html +24 -0
  141. package/package.json +7 -8
  142. package/cjs/enum.d.ts +0 -30
  143. package/cjs/enum.js +0 -49
  144. package/cjs/index.d.ts +0 -8
  145. package/cjs/index.js +0 -13
  146. package/cjs/loading.d.ts +0 -19
  147. package/cjs/loading.js +0 -68
  148. package/cjs/message.d.ts +0 -12
  149. package/cjs/message.js +0 -220
  150. package/cjs/other.d.ts +0 -42
  151. package/cjs/other.js +0 -167
  152. package/cjs/param.d.ts +0 -48
  153. package/cjs/param.js +0 -80
  154. package/cjs/request.d.ts +0 -62
  155. package/cjs/request.js +0 -216
  156. package/cjs/string.d.ts +0 -42
  157. package/cjs/string.js +0 -108
  158. package/cjs/time.d.ts +0 -21
  159. package/cjs/time.js +0 -102
  160. package/docs/api/functions/copyToClipboard/index.html +0 -18
  161. package/docs/api/functions/createEnum/index.html +0 -23
  162. package/docs/api/functions/decodeHtml/index.html +0 -16
  163. package/docs/api/functions/deepCopy/index.html +0 -16
  164. package/docs/api/functions/delParam/index.html +0 -19
  165. package/docs/api/functions/encodeHtml/index.html +0 -16
  166. package/docs/api/functions/formatDate/index.html +0 -16
  167. package/docs/api/functions/formatJson/index.html +0 -17
  168. package/docs/api/functions/getIdCardLastChar/index.html +0 -16
  169. package/docs/api/functions/getParam/index.html +0 -20
  170. package/docs/api/functions/getParamInt/index.html +0 -16
  171. package/docs/api/functions/getParams/index.html +0 -17
  172. package/docs/api/functions/getRandom/index.html +0 -21
  173. package/docs/api/functions/getRandomStr/index.html +0 -16
  174. package/docs/api/functions/hideLoading/index.html +0 -16
  175. package/docs/api/functions/initWindowMessage/index.html +0 -16
  176. package/docs/api/functions/parseDate/index.html +0 -16
  177. package/docs/api/functions/setParam/index.html +0 -18
  178. package/docs/api/functions/showLoading/index.html +0 -16
  179. package/docs/api/functions/toHump/index.html +0 -18
  180. package/docs/api/functions/toUnderline/index.html +0 -16
  181. package/docs/api/functions/toUrlParams/index.html +0 -16
  182. package/docs/api/functions/validateIdCard/index.html +0 -16
  183. package/docs/api/index.html +0 -16
  184. package/docs/api/interfaces/IRequestOptions/index.html +0 -16
  185. package/docs/api/interfaces/IShowLoadingConfig/index.html +0 -16
  186. package/docs/api/variables/Request/index.html +0 -16
  187. package/docs/api/variables/keyCodes/index.html +0 -16
  188. package/docs/assets/css/styles.077146e6.css +0 -1
  189. package/docs/assets/images/iphoneX-1fc37282d0e9b32fcd03fd96f461e7d5.png +0 -0
  190. package/docs/assets/js/00078de9.40631b85.js +0 -1
  191. package/docs/assets/js/04050071.c7e3abde.js +0 -1
  192. package/docs/assets/js/08f709b9.a083fff8.js +0 -1
  193. package/docs/assets/js/094cfbf1.00977b14.js +0 -1
  194. package/docs/assets/js/0c2147ef.7be0fbdf.js +0 -1
  195. package/docs/assets/js/114.c257b8b0.js +0 -2
  196. package/docs/assets/js/114.c257b8b0.js.LICENSE.txt +0 -1
  197. package/docs/assets/js/1501a739.13d7c7be.js +0 -1
  198. package/docs/assets/js/1608b181.cbe9c45e.js +0 -1
  199. package/docs/assets/js/1774.902f2e94.js +0 -1
  200. package/docs/assets/js/17896441.7fc5704e.js +0 -1
  201. package/docs/assets/js/194adc5f.8a12cf8c.js +0 -1
  202. package/docs/assets/js/1be78505.71fee479.js +0 -1
  203. package/docs/assets/js/26a70007.f12496a6.js +0 -1
  204. package/docs/assets/js/2ac048f8.1f1f0188.js +0 -1
  205. package/docs/assets/js/2e314e38.32e955e9.js +0 -1
  206. package/docs/assets/js/3b14ef11.5bc3d469.js +0 -1
  207. package/docs/assets/js/3ec39cd5.55864cc1.js +0 -1
  208. package/docs/assets/js/479af78b.8e2443f4.js +0 -1
  209. package/docs/assets/js/5888.a314615c.js +0 -2
  210. package/docs/assets/js/5888.a314615c.js.LICENSE.txt +0 -14
  211. package/docs/assets/js/66592e46.de586a2b.js +0 -1
  212. package/docs/assets/js/6bc50bd8.3c68878f.js +0 -1
  213. package/docs/assets/js/7263d0e6.ab50c755.js +0 -1
  214. package/docs/assets/js/7830.006c8eaa.js +0 -1
  215. package/docs/assets/js/7891b53e.79b654b9.js +0 -1
  216. package/docs/assets/js/8b76e124.7c5e5eb2.js +0 -1
  217. package/docs/assets/js/901a7e9f.5cd13eb6.js +0 -1
  218. package/docs/assets/js/9104954f.c7d49874.js +0 -1
  219. package/docs/assets/js/92b7d874.a379eff4.js +0 -1
  220. package/docs/assets/js/9334cb7c.c2c6b902.js +0 -1
  221. package/docs/assets/js/935f2afb.6c90f018.js +0 -1
  222. package/docs/assets/js/969412eb.5a33260d.js +0 -1
  223. package/docs/assets/js/9be94766.3c374589.js +0 -1
  224. package/docs/assets/js/9dd5329b.14301248.js +0 -1
  225. package/docs/assets/js/a0c44371.6c889be4.js +0 -1
  226. package/docs/assets/js/ab2af742.46b7af8c.js +0 -1
  227. package/docs/assets/js/b01f3e06.62f3a014.js +0 -1
  228. package/docs/assets/js/ba6f0f15.39cd6e80.js +0 -1
  229. package/docs/assets/js/ccb851b4.bba2fb6b.js +0 -1
  230. package/docs/assets/js/d4323bca.ac481634.js +0 -1
  231. package/docs/assets/js/d9f162ad.2abc1769.js +0 -1
  232. package/docs/assets/js/e2aa7f69.620e7b98.js +0 -1
  233. package/docs/assets/js/ef3f9d02.479dddf7.js +0 -1
  234. package/docs/assets/js/f4c916b9.07c4240c.js +0 -1
  235. package/docs/assets/js/f7d87c57.9b13a5a8.js +0 -1
  236. package/docs/assets/js/f97ec998.449e16b8.js +0 -1
  237. package/docs/assets/js/f9953324.325f2a5d.js +0 -1
  238. package/docs/assets/js/fc1c80db.551e2052.js +0 -1
  239. package/docs/assets/js/fdb649b1.5d0fff7c.js +0 -1
  240. package/docs/assets/js/main.15afa47b.js +0 -2
  241. package/docs/assets/js/main.15afa47b.js.LICENSE.txt +0 -63
  242. package/docs/assets/js/runtime~main.1ee1dff9.js +0 -1
  243. package/docs/demos/IcePkgDemo_doc_01_request_0/index.html +0 -16
  244. package/docs/demos/IcePkgDemo_doc_01_request_1/index.html +0 -16
  245. package/docs/demos/IcePkgDemo_doc_02_time_0/index.html +0 -16
  246. package/docs/demos/IcePkgDemo_doc_03_loading_0/index.html +0 -16
  247. package/docs/loading/index.html +0 -128
  248. package/docs/request/index.html +0 -240
  249. package/docs/sitemap.xml +0 -1
  250. package/docs/time/index.html +0 -128
  251. package/es/89c27c69.esm.es5.production.mjs +0 -1
  252. package/es/index.mjs +0 -1
  253. package/esm/enum.d.ts +0 -30
  254. package/esm/enum.js +0 -50
  255. package/esm/index.d.ts +0 -8
  256. package/esm/index.js +0 -8
  257. package/esm/loading.d.ts +0 -19
  258. package/esm/loading.js +0 -57
  259. package/esm/message.d.ts +0 -12
  260. package/esm/message.js +0 -215
  261. package/esm/other.d.ts +0 -42
  262. package/esm/other.js +0 -158
  263. package/esm/param.d.ts +0 -48
  264. package/esm/param.js +0 -78
  265. package/esm/request.d.ts +0 -62
  266. package/esm/request.js +0 -202
  267. package/esm/string.d.ts +0 -42
  268. package/esm/string.js +0 -106
  269. package/esm/time.d.ts +0 -21
  270. package/esm/time.js +0 -91
  271. package/umd/index.js +0 -1
package/esm/param.d.ts DELETED
@@ -1,48 +0,0 @@
1
- /**
2
- * 从URL中获取某个参数,如果不存在返回 undefined ,如果存在多个同名参数,返回第一个匹配值
3
- * getParam('a', '?a=1&b=&c=3&c=33#abc') // '1'
4
- * getParam('b', '?a=1&b=&c=3&c=33#abc') // ''
5
- * getParam('c', '?a=1&b=&c=3&c=33#abc') // 3
6
- * getParam('d', '?a=1&b=&c=3&c=33#abc') // undefined
7
- * @param {*} name 参数名
8
- * @param {*} url 要获取的URL,默认当前地址
9
- */
10
- export declare const getParam: (name: string, url?: string) => string;
11
- /**
12
- * 从URL中获取int参数
13
- * @param {*} name 参数名
14
- * @param {*} url 要获取的URL,默认当前地址
15
- */
16
- export declare const getParamInt: (name: string, url?: string) => number;
17
- /**
18
- * 获取某个URL的全部参数
19
- * getParams('?a=1&b=2#cc') // {a: '1', b: '2'}
20
- * @param url
21
- * @returns 参数对象
22
- */
23
- export declare const getParams: (url?: string) => any;
24
- /**
25
- * 给URL设置参数,如果已经存在,替换之,兼容hash存在的情况
26
- * setParam('a', '123', '?a=1&b=2&a=3#d') // '?a=123&b=2&a=123#d'
27
- * setParam('d', '444', '?a=1&b=2&a=3#d') // '?a=1&b=2&a=3&d=444#d'
28
- * @param {Object} name 参数名
29
- * @param {Object} value 参数值
30
- * @param {Object} url 如果不传默认当前页面URL
31
- */
32
- export declare const setParam: (name: string, value: string | number, url?: string) => string;
33
- /**
34
- * 删除URL中某个参数
35
- * delParam('a', '?a=1&b=2&a=3#d') // '?b=2#d'
36
- * delParam('b', '?a=1&b=2&a=3#d') // '?a=1&a=3#d'
37
- * delParam('a', '?a=1#d') // '#d'
38
- * @param name 参数名
39
- * @param url 要删除的URL,默认当前页面URL
40
- * @returns 处理完后的URL
41
- */
42
- export declare const delParam: (name: string, url: string) => string;
43
- /**
44
- * 将一个普通对象转为 a=1&b=2 的URL格式,会自动过滤undefined的值
45
- * @param data 一个普通对象,如果对象嵌对象则会被自动转为JSON
46
- * @returns 返回类似 a=1&b=2 的字符串
47
- */
48
- export declare const toUrlParams: (data: any) => string;
package/esm/param.js DELETED
@@ -1,78 +0,0 @@
1
- /**
2
- * 从URL中获取某个参数,如果不存在返回 undefined ,如果存在多个同名参数,返回第一个匹配值
3
- * getParam('a', '?a=1&b=&c=3&c=33#abc') // '1'
4
- * getParam('b', '?a=1&b=&c=3&c=33#abc') // ''
5
- * getParam('c', '?a=1&b=&c=3&c=33#abc') // 3
6
- * getParam('d', '?a=1&b=&c=3&c=33#abc') // undefined
7
- * @param {*} name 参数名
8
- * @param {*} url 要获取的URL,默认当前地址
9
- */ import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs";
10
- export var getParam = function(name) {
11
- var url = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : location.search;
12
- return (new RegExp("(^|\\?|&)".concat(name, "=(.*?)(?=&|#|$)"), "g").exec(url) || [])[2];
13
- };
14
- /**
15
- * 从URL中获取int参数
16
- * @param {*} name 参数名
17
- * @param {*} url 要获取的URL,默认当前地址
18
- */ export var getParamInt = function(name) {
19
- var url = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : location.search;
20
- return parseInt(getParam(name, url) || "0", 10);
21
- };
22
- /**
23
- * 获取某个URL的全部参数
24
- * getParams('?a=1&b=2#cc') // {a: '1', b: '2'}
25
- * @param url
26
- * @returns 参数对象
27
- */ export var getParams = function() {
28
- var url = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : location.search;
29
- var search = ((url || "").split("?").pop() || "").split("#")[0] || "";
30
- var params = {};
31
- search.split("&").map(function(item) {
32
- return item.split("=");
33
- }).forEach(function(param) {
34
- var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
35
- params[key] = value || "";
36
- });
37
- return params;
38
- };
39
- /**
40
- * 给URL设置参数,如果已经存在,替换之,兼容hash存在的情况
41
- * setParam('a', '123', '?a=1&b=2&a=3#d') // '?a=123&b=2&a=123#d'
42
- * setParam('d', '444', '?a=1&b=2&a=3#d') // '?a=1&b=2&a=3&d=444#d'
43
- * @param {Object} name 参数名
44
- * @param {Object} value 参数值
45
- * @param {Object} url 如果不传默认当前页面URL
46
- */ export var setParam = function(name, value, url) {
47
- url = url || "".concat(location.pathname).concat(location.search);
48
- // 如果参数已经存在,替换之
49
- if (getParam(name, url) !== undefined) return url.replace(new RegExp("(^|\\?|&)".concat(name, "=(.*?)(?=&|#|$)"), "g"), "$1".concat(name, "=").concat(value));
50
- var _url_split = _sliced_to_array(url.split("#"), 2), pathname = _url_split[0], hash = _url_split[1]; // 处理存在hash的情况
51
- return "".concat(pathname).concat(pathname.indexOf("?") < 0 ? "?" : "&").concat(name, "=").concat(value).concat(hash ? "#" : "").concat(hash || "");
52
- };
53
- /**
54
- * 删除URL中某个参数
55
- * delParam('a', '?a=1&b=2&a=3#d') // '?b=2#d'
56
- * delParam('b', '?a=1&b=2&a=3#d') // '?a=1&a=3#d'
57
- * delParam('a', '?a=1#d') // '#d'
58
- * @param name 参数名
59
- * @param url 要删除的URL,默认当前页面URL
60
- * @returns 处理完后的URL
61
- */ export var delParam = function(name, url) {
62
- url = url || "".concat(location.pathname).concat(location.search);
63
- return url.replace(new RegExp("(^|\\?|&)".concat(name, "=.*?(&|#|$)"), "g"), function(_m, $1, $2) {
64
- return $2 === "&" ? $1 : $2;
65
- });
66
- };
67
- /**
68
- * 将一个普通对象转为 a=1&b=2 的URL格式,会自动过滤undefined的值
69
- * @param data 一个普通对象,如果对象嵌对象则会被自动转为JSON
70
- * @returns 返回类似 a=1&b=2 的字符串
71
- */ export var toUrlParams = function(data) {
72
- return Object.keys(data || {}).filter(function(key) {
73
- return data[key] !== undefined;
74
- }).map(function(key) {
75
- var value = typeof data[key] === "object" ? JSON.stringify(data[key]) : data[key];
76
- return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
77
- }).join("&");
78
- };
package/esm/request.d.ts DELETED
@@ -1,62 +0,0 @@
1
- /** requestAPI的第二个参数类型 */
2
- export interface IRequestOptions {
3
- /** GET请求时传递的参数 */
4
- params?: Record<string, any>;
5
- /** POST请求时传递的参数 */
6
- data?: Record<string, any>;
7
- /** 采用formData模式请求,可以传入普通的对象,也可以传入标准的formData */
8
- formData?: Record<string, any>;
9
- /** postJson请求时传递的参数 */
10
- json?: Record<string, any>;
11
- /** API前缀,不传默认为空 */
12
- baseUrl?: string;
13
- /** 请求方法,绝大部分情况无需手动指定 */
14
- method?: string;
15
- /** headers */
16
- headers?: Record<string, any>;
17
- /** 其它自定义fetchOptions,优先级高于上面所有参数 */
18
- fetchOptions?: RequestInit;
19
- /** 请求完成之后触发的钩子,无论成功与否均会触发 */
20
- afterRequest?: (success: boolean, resp?: any) => void;
21
- /** 判断接口是否调用成功,默认规则 resp => resp.code == 0 || resp.code == 200 */
22
- checkSuccess?: (resp: any) => boolean;
23
- /** 对响应进行自定义格式化处理,包含 checkSuccess 全部能力 */
24
- responseConverter?: (resp: any) => any;
25
- /** @deprecated 后端未返回 message 时的默认异常文案,由于名称经常引发歧义,估改名为 defaultErrorMessage */
26
- errorMessage?: string;
27
- /** 后端未返回 message 时的默认异常文案 */
28
- defaultErrorMessage?: string;
29
- /** 发生异常时的处理方法,一般不太建议重写此方法 */
30
- errorHandler?: (message: string, resp: any, options: IRequestOptions) => void;
31
- /** 自定义toast实现,为了和UI解耦,方法默认不包含UI处理代码 */
32
- toastHandler?: (message: string) => void;
33
- /** 是否关闭默认的异常toast */
34
- silent?: boolean;
35
- /** 自定义 fetch.then() ,非常底层的一个方法,非必要请勿使用 */
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);
41
- }
42
- /**
43
- * 通用的API请求方法
44
- * @param url
45
- * @param options
46
- * @returns
47
- */
48
- declare const request: {
49
- <T = any>(url: string, options?: IRequestOptions): Promise<T>;
50
- create: any;
51
- };
52
- export { request };
53
- type IRequest = typeof request;
54
- interface RequestConstructor {
55
- new (overrideOptions: IRequestOptions): IRequest;
56
- new (req: IRequest, overrideOptions: IRequestOptions): IRequest;
57
- }
58
- /**
59
- * 支持实例化一个新的request方法,覆盖默认的部分配置项
60
- * @deprecated 推荐使用 request.create() 实例化新的request
61
- */
62
- export declare const Request: RequestConstructor;
package/esm/request.js DELETED
@@ -1,202 +0,0 @@
1
- import _assert_this_initialized from "@swc/helpers/src/_assert_this_initialized.mjs";
2
- import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs";
3
- import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
4
- import _inherits from "@swc/helpers/src/_inherits.mjs";
5
- import _instanceof from "@swc/helpers/src/_instanceof.mjs";
6
- import _object_spread from "@swc/helpers/src/_object_spread.mjs";
7
- import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
8
- import _wrap_native_super from "@swc/helpers/src/_wrap_native_super.mjs";
9
- import _create_super from "@swc/helpers/src/_create_super.mjs";
10
- import _ts_generator from "@swc/helpers/src/_ts_generator.mjs";
11
- import { toUrlParams } from "./param";
12
- /** 合并2个options对象 */ var mergeOptions = function(ops1, ops2) {
13
- // 对象比较特殊,需要特殊处理
14
- var headers = Object.assign({}, (ops1 === null || ops1 === void 0 ? void 0 : ops1.headers) || {}, (ops2 === null || ops2 === void 0 ? void 0 : ops2.headers) || {});
15
- var fetchOptions = Object.assign({}, (ops1 === null || ops1 === void 0 ? void 0 : ops1.fetchOptions) || {}, (ops2 === null || ops2 === void 0 ? void 0 : ops2.fetchOptions) || {});
16
- return Object.assign({}, ops1 || {}, ops2 || {}, {
17
- headers: headers,
18
- fetchOptions: fetchOptions
19
- });
20
- };
21
- /**
22
- * 支持传入自定义属性的Error对象,包括 cause
23
- */ var MyError = /*#__PURE__*/ function(Error1) {
24
- "use strict";
25
- _inherits(MyError, Error1);
26
- var _super = _create_super(MyError);
27
- function MyError(message, options) {
28
- _class_call_check(this, MyError);
29
- var _this;
30
- _this = _super.call(this, message);
31
- Object.assign(_assert_this_initialized(_this), options || {});
32
- return _this;
33
- }
34
- return MyError;
35
- }(_wrap_native_super(Error));
36
- /**
37
- * 通用的API请求方法
38
- * @param url
39
- * @param options
40
- * @returns
41
- */ var request = function() {
42
- var _ref = _async_to_generator(function(url, options) {
43
- 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;
44
- return _ts_generator(this, function(_state) {
45
- switch(_state.label){
46
- case 0:
47
- defaultOptions = {
48
- errorMessage: "系统繁忙,请稍后再试",
49
- errorHandler: function(message) {
50
- var _options_toastHandler;
51
- 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);
52
- // 抛出异常,阻止执行之后的操作
53
- throw new Error(message);
54
- },
55
- baseUrl: "",
56
- headers: {},
57
- fetchOptions: {
58
- credentials: "include"
59
- },
60
- // eslint-disable-next-line eqeqeq
61
- checkSuccess: function(resp) {
62
- return (resp === null || resp === void 0 ? void 0 : resp.code) == 0 || (resp === null || resp === void 0 ? void 0 : resp.code) == 200;
63
- },
64
- toastHandler: function(msg) {
65
- return console.error("[您还没有配置toastHandler,请根据您的UI组件库配置合适的提示方法] ".concat(msg || ""));
66
- },
67
- onFetchResponse: function(response) {
68
- if (response.status === 200) return response.json();
69
- throw new MyError(response.statusText, {
70
- response: _object_spread_props(_object_spread({}, response), {
71
- code: response.status,
72
- message: response.statusText,
73
- /** 标记这是HTTP原始响应,并非服务端返回数据 */ isHttpResponse: true
74
- })
75
- });
76
- }
77
- };
78
- options = mergeOptions(defaultOptions, options);
79
- _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;
80
- defaultErrorMessage = (options === null || options === void 0 ? void 0 : options.defaultErrorMessage) || errorMessage;
81
- // fetchOptions 里面的 headers 优先级高于外部的 headers
82
- fetchOptions.headers = _object_spread({}, headers || {}, fetchOptions.headers || {});
83
- if (params) {
84
- fetchOptions.method = method || "GET";
85
- url = "".concat(url).concat(url.indexOf("?") >= 0 ? "&" : "?").concat(toUrlParams(params));
86
- }
87
- if (data) Object.assign(fetchOptions, {
88
- method: method || "POST",
89
- body: toUrlParams(data),
90
- headers: _object_spread({
91
- "Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
92
- }, fetchOptions.headers || {})
93
- });
94
- else if (formData) {
95
- body = formData;
96
- if (!_instanceof(formData, FormData)) {
97
- body = new FormData();
98
- for(var key in formData)body.append(key, formData[key]);
99
- }
100
- Object.assign(fetchOptions, {
101
- method: method || "POST",
102
- body: body
103
- });
104
- } else if (json) Object.assign(fetchOptions, {
105
- method: method || "POST",
106
- body: JSON.stringify(json),
107
- headers: _object_spread({
108
- "Content-Type": "application/json;charset=utf-8"
109
- }, fetchOptions.headers || {})
110
- });
111
- resp = null;
112
- setLoading === null || setLoading === void 0 ? void 0 : setLoading(true);
113
- _state.label = 1;
114
- case 1:
115
- _state.trys.push([
116
- 1,
117
- 3,
118
- ,
119
- 4
120
- ]);
121
- targetUrl = "".concat(/^(http|\/\/)/g.test(url) ? "" : baseUrl || "").concat(url);
122
- // 如果当前是blob地址,目标地址又是 // 开头,自动修正
123
- if (targetUrl.indexOf("//") === 0 && location.protocol === "blob:") targetUrl = "".concat((_location_pathname_split = location.pathname.split(":")) === null || _location_pathname_split === void 0 ? void 0 : _location_pathname_split[0], ":").concat(targetUrl);
124
- return [
125
- 4,
126
- fetch(targetUrl, fetchOptions).then(onFetchResponse)
127
- ];
128
- case 2:
129
- resp = _state.sent();
130
- return [
131
- 3,
132
- 4
133
- ];
134
- case 3:
135
- e = _state.sent();
136
- console.error(e);
137
- setLoading === null || setLoading === void 0 ? void 0 : setLoading(false);
138
- afterRequest === null || afterRequest === void 0 ? void 0 : afterRequest(false, e.response);
139
- localMessage = typeof overrideMessage === "function" ? overrideMessage(e.response) : overrideMessage;
140
- 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);
141
- return [
142
- 2,
143
- undefined
144
- ];
145
- case 4:
146
- setLoading === null || setLoading === void 0 ? void 0 : setLoading(false);
147
- resp = responseConverter ? responseConverter(resp) : resp;
148
- if (checkSuccess === null || checkSuccess === void 0 ? void 0 : checkSuccess(resp)) {
149
- afterRequest === null || afterRequest === void 0 ? void 0 : afterRequest(true, resp);
150
- return [
151
- 2,
152
- resp.data
153
- ];
154
- } else {
155
- afterRequest === null || afterRequest === void 0 ? void 0 : afterRequest(false, resp);
156
- localMessage1 = typeof overrideMessage === "function" ? overrideMessage(resp) : overrideMessage;
157
- errorHandler === null || errorHandler === void 0 ? void 0 : errorHandler(localMessage1 !== null && localMessage1 !== void 0 ? localMessage1 : resp.message || defaultErrorMessage, resp, options);
158
- return [
159
- 2,
160
- undefined
161
- ];
162
- }
163
- return [
164
- 2
165
- ];
166
- }
167
- });
168
- });
169
- return function request(url, options) {
170
- return _ref.apply(this, arguments);
171
- };
172
- }();
173
- /**
174
- * 基于当前 request 实例化一个新的 request 函数并覆盖部分配置
175
- * @param this
176
- * @param overrideOptions 要覆盖的配置
177
- * @returns
178
- */ var create = function create1(overrideOptions) {
179
- var mergedOptions = mergeOptions(this.overrideDefaultOptions, overrideOptions);
180
- var newRequest = function(url, options) {
181
- return request(url, mergeOptions(mergedOptions, options));
182
- };
183
- // 记录相比于 defaultOptions 之外所有合并后的覆盖options,供下次 create 使用
184
- newRequest.overrideDefaultOptions = mergedOptions;
185
- newRequest.create = create.bind(newRequest);
186
- return newRequest;
187
- };
188
- request.create = create.bind(request);
189
- export { request };
190
- /**
191
- * 支持实例化一个新的request方法,覆盖默认的部分配置项
192
- * @deprecated 推荐使用 request.create() 实例化新的request
193
- */ export var Request = function Request(req, overrideOptions) {
194
- var overrideDefaultOptions = overrideOptions;
195
- if (!overrideOptions) {
196
- overrideDefaultOptions = req;
197
- req = request;
198
- }
199
- return function(url, options) {
200
- return req(url, _object_spread({}, overrideDefaultOptions || {}, options || {}));
201
- };
202
- };
package/esm/string.d.ts DELETED
@@ -1,42 +0,0 @@
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/esm/string.js DELETED
@@ -1,106 +0,0 @@
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
- */ import _instanceof from "@swc/helpers/src/_instanceof.mjs";
9
- export var formatJson = function(json, indent, leftBracesInSameLine) {
10
- var getIndentStr = function getIndentStr(level) {
11
- var str = "";
12
- for(var i = 0; i < level; i++)str += indent || " ";
13
- return str;
14
- };
15
- function format(obj, level) {
16
- level = level === undefined ? 0 : level;
17
- var result = "";
18
- // 如果是object或者array
19
- if (typeof obj === "object" && obj != null) {
20
- var isArray = _instanceof(obj, Array);
21
- var idx = 0;
22
- result += "".concat(isArray ? "[" : "{", "\n");
23
- for(var i in obj){
24
- result += idx++ > 0 ? ",\n" : ""; // 如果不是数组或对象的第一个内容,追加逗号
25
- var nextIsObj = typeof obj[i] === "object" && obj[i] != null;
26
- var indentStr = getIndentStr(level + 1);
27
- result += isArray && nextIsObj ? "" : indentStr; // 如果当前是数组并且子项是对象,无需缩进
28
- result += isArray ? "" : '"'.concat(i, '": ').concat(nextIsObj && !leftBracesInSameLine ? "\n" : "");
29
- result += !nextIsObj || nextIsObj && leftBracesInSameLine && !isArray ? "" : indentStr;
30
- result += format(obj[i], level + 1); // 递归调用
31
- }
32
- result += "\n".concat(getIndentStr(level)).concat(isArray ? "]" : "}");
33
- } else {
34
- // 如果是 null、number、boolean、string
35
- var quot = typeof obj === "string" ? '"' : ""; // 是否是字符串
36
- result += "".concat(quot).concat(obj).concat(quot);
37
- }
38
- return result;
39
- }
40
- // eslint-disable-next-line no-eval
41
- return format(eval("(".concat(json, ")"))); // 使用eval的好处是可以解析非标准JSON
42
- };
43
- /**
44
- * 获取各种随机数,支持如下几种调用方式:
45
- * getRandom() 返回0-1的随机小数,等同于Math.random(),0 <= result < 1
46
- * getRandom(start, end) 返回start-end的随机整数,start <= result < end
47
- * getRandom(end) 返回0-end的随机整数,0 <= result < end
48
- * getRandom(array) 随机返回数组中的某一个内容
49
- * getRandom(array, count) 随机从数组中返回长度为count的不重复内容组成的新数组,如果不足count个,返回全部 并乱序
50
- * @param {Object} start
51
- * @param {Object} end
52
- * @return {Object}
53
- */ export var getRandom = function(start, end) {
54
- if (typeof start === "number") {
55
- if (typeof end === "undefined") {
56
- end = start;
57
- start = 0;
58
- }
59
- return start + Math.floor(Math.random() * (end - start));
60
- } else if (_instanceof(start, Array)) {
61
- if (typeof end === "undefined") {
62
- if (start.length === 0) return null;
63
- if (start.length === 1) return start[0];
64
- return start[Math.floor(Math.random() * start.length)];
65
- } else {
66
- start.sort(function() {
67
- return Math.random() > 0.5 ? 1 : -1;
68
- });
69
- return start.slice(0, end);
70
- }
71
- }
72
- return Math.random();
73
- };
74
- /**
75
- * 获取随机字符串
76
- * @param length 字符串长度
77
- * @param type all 表示所有,number表示仅数字,默认所有
78
- * @return string
79
- */ export var getRandomStr = function(length, type) {
80
- length = length || 18;
81
- var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz0123456789".split("");
82
- if (type === "number") chars = "0123456789".split("");
83
- var result = "";
84
- for(var i = 0; i < length; i++)result += getRandom(chars);
85
- return result;
86
- };
87
- /**
88
- * 字符串转下划线形式,示例:getParam 转 get_param
89
- * @param str 要转换的字符串
90
- * @param flag 默认下划线-,也可以传其它字符
91
- */ export var toUnderline = function(str, flag) {
92
- return str.replace(/([A-Z])/g, function(m, $1) {
93
- return "".concat(flag || "_").concat($1.toLowerCase());
94
- });
95
- };
96
- /**
97
- * 字符串转驼峰形式
98
- * 示例一: toHump('get_param'),返回getParam
99
- * 示例二: toHump('font-size','-'),返回fontSize
100
- * @param str
101
- * @param 分割的标志,默认为“_”
102
- */ export var toHump = function(str, flag) {
103
- return str.replace(new RegExp("".concat(flag || "_", "(\\w)"), "g"), function(_m, $1) {
104
- return $1.toUpperCase();
105
- });
106
- };
package/esm/time.d.ts DELETED
@@ -1,21 +0,0 @@
1
- /**
2
- * 将日期格式化成指定格式的字符串
3
- * @param date 要格式化的日期,不传时默认当前时间,也可以是一个时间戳等
4
- * @param fmt 目标字符串格式,支持的字符有:y,M,d,q,w,H,h,m,S,默认:yyyy-MM-dd HH:mm:ss
5
- * @returns 返回格式化后的日期字符串
6
- */
7
- export declare const formatDate: (date?: Date | number | string, fmt?: string) => string;
8
- /**
9
- * 将字符串解析成日期
10
- * @param str 输入的日期字符串,如'2014-09-13'
11
- * @param fmt 字符串格式,默认'yyyy-MM-dd',支持如下:y、M、d、H、m、s、S,不支持w和q
12
- * @returns 解析后的Date类型日期
13
- */
14
- export declare const parseDate: (str: string, fmt?: string) => Date;
15
- /**
16
- * 休息一段时间,单位毫秒
17
- * 示例:await sleep(200); // 休息200毫秒
18
- * @param ms 要休息的时间,单位毫秒,不传默认0
19
- * @returns
20
- */
21
- export declare const sleep: (ms?: number) => Promise<unknown>;
package/esm/time.js DELETED
@@ -1,91 +0,0 @@
1
- /**
2
- * 将日期格式化成指定格式的字符串
3
- * @param date 要格式化的日期,不传时默认当前时间,也可以是一个时间戳等
4
- * @param fmt 目标字符串格式,支持的字符有:y,M,d,q,w,H,h,m,S,默认:yyyy-MM-dd HH:mm:ss
5
- * @returns 返回格式化后的日期字符串
6
- */ import _instanceof from "@swc/helpers/src/_instanceof.mjs";
7
- export var formatDate = function(date, fmt) {
8
- var _loop = function(i) {
9
- fmt = fmt.replace(new RegExp("".concat(i, "+"), "g"), function(m) {
10
- var val = "".concat(obj[i]);
11
- if (i === "w") return "".concat(m.length > 2 ? "星期" : "周").concat(week[val]);
12
- for(var j = 0, len = val.length; j < m.length - len; j++)val = "0".concat(val);
13
- return m.length === 1 ? val : val.substring(val.length - m.length);
14
- });
15
- };
16
- if (!date) return "";
17
- if (typeof date === "number") // 1687682453445
18
- date = new Date(date);
19
- else if (typeof date === "string") {
20
- if (/^\d{12,13}$/g.test(date)) // '1687682453445'
21
- date = new Date(parseInt(date, 10));
22
- else if (/^.{10}T.{8,12}Z?$/g.test(date)) // '2019-01-01T00:00:00.000Z'
23
- date = new Date(date);
24
- else return date;
25
- }
26
- if (!_instanceof(date, Date)) throw new Error("formatDate error: not date.");
27
- if (isNaN(date === null || date === void 0 ? void 0 : date.getFullYear())) throw new Error("formatDate error: invalid date.");
28
- fmt = fmt || "yyyy-MM-dd HH:mm:ss";
29
- var obj = {
30
- y: date.getFullYear(),
31
- M: date.getMonth() + 1,
32
- d: date.getDate(),
33
- q: Math.floor((date.getMonth() + 3) / 3),
34
- w: date.getDay(),
35
- H: date.getHours(),
36
- h: date.getHours() % 12 === 0 ? 12 : date.getHours() % 12,
37
- m: date.getMinutes(),
38
- s: date.getSeconds(),
39
- S: date.getMilliseconds()
40
- };
41
- var week = [
42
- "天",
43
- "一",
44
- "二",
45
- "三",
46
- "四",
47
- "五",
48
- "六"
49
- ];
50
- for(var i in obj)_loop(i);
51
- return fmt;
52
- };
53
- /**
54
- * 将字符串解析成日期
55
- * @param str 输入的日期字符串,如'2014-09-13'
56
- * @param fmt 字符串格式,默认'yyyy-MM-dd',支持如下:y、M、d、H、m、s、S,不支持w和q
57
- * @returns 解析后的Date类型日期
58
- */ export var parseDate = function(str, fmt) {
59
- fmt = fmt || "yyyy-MM-dd";
60
- var obj = {
61
- y: 0,
62
- M: 1,
63
- d: 0,
64
- H: 0,
65
- h: 0,
66
- m: 0,
67
- s: 0,
68
- S: 0
69
- };
70
- fmt.replace(/([^yMdHmsS]*?)(([yMdHmsS])\3*)([^yMdHmsS]*?)/g, function(m, $1, $2, $3, $4) {
71
- str = str.replace(new RegExp("".concat($1, "(\\d{").concat($2.length, "})").concat($4)), function(_m, _$1) {
72
- obj[$3] = parseInt(_$1, 10);
73
- return "";
74
- });
75
- return "";
76
- });
77
- obj.M--; // 月份是从0开始的,所以要减去1
78
- var date = new Date(obj.y, obj.M, obj.d, obj.H, obj.m, obj.s);
79
- if (obj.S !== 0) date.setMilliseconds(obj.S); // 如果设置了毫秒
80
- return date;
81
- };
82
- /**
83
- * 休息一段时间,单位毫秒
84
- * 示例:await sleep(200); // 休息200毫秒
85
- * @param ms 要休息的时间,单位毫秒,不传默认0
86
- * @returns
87
- */ export var sleep = function(ms) {
88
- return new Promise(function(resolve) {
89
- return setTimeout(resolve, ms || 0);
90
- });
91
- };