tools-min-ns 1.5.2

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 (162) hide show
  1. package/README.md +85 -0
  2. package/esm/array/ArrayUtil.d.ts +109 -0
  3. package/esm/array/ArrayUtil.js +242 -0
  4. package/esm/array/TreeUtil.d.ts +151 -0
  5. package/esm/array/TreeUtil.js +412 -0
  6. package/esm/base/BaseUtil.d.ts +91 -0
  7. package/esm/base/BaseUtil.js +148 -0
  8. package/esm/browser/BrowserUtil.d.ts +57 -0
  9. package/esm/browser/BrowserUtil.js +337 -0
  10. package/esm/browser/fingerprint.d.ts +120 -0
  11. package/esm/browser/fingerprint.js +1469 -0
  12. package/esm/check/CheckUtil.d.ts +110 -0
  13. package/esm/check/CheckUtil.js +465 -0
  14. package/esm/common.d.ts +43 -0
  15. package/esm/common.js +44 -0
  16. package/esm/config.d.ts +7 -0
  17. package/esm/config.js +7 -0
  18. package/esm/cookie/CookieUtil.d.ts +56 -0
  19. package/esm/cookie/CookieUtil.js +12 -0
  20. package/esm/cookie/cookie.d.ts +2 -0
  21. package/esm/cookie/cookie.js +104 -0
  22. package/esm/date/DateUtil.d.ts +261 -0
  23. package/esm/date/DateUtil.js +763 -0
  24. package/esm/env/EnvUtil.d.ts +27 -0
  25. package/esm/env/EnvUtil.js +29 -0
  26. package/esm/env/env.d.ts +41 -0
  27. package/esm/env/env.js +106 -0
  28. package/esm/func/FunctionUtil.d.ts +77 -0
  29. package/esm/func/FunctionUtil.js +215 -0
  30. package/esm/index.d.ts +19 -0
  31. package/esm/index.js +19 -0
  32. package/esm/number/NumberUtil.d.ts +96 -0
  33. package/esm/number/NumberUtil.js +256 -0
  34. package/esm/object/ObjectUtil.d.ts +41 -0
  35. package/esm/object/ObjectUtil.js +158 -0
  36. package/esm/pwd/PasswordUtil.d.ts +33 -0
  37. package/esm/pwd/PasswordUtil.js +68 -0
  38. package/esm/pwd/crypto.d.ts +6 -0
  39. package/esm/pwd/crypto.js +1824 -0
  40. package/esm/request/RequestUtil.d.ts +52 -0
  41. package/esm/request/RequestUtil.js +53 -0
  42. package/esm/request/jsonp.d.ts +18 -0
  43. package/esm/request/jsonp.js +73 -0
  44. package/esm/request/mgop/env.d.ts +7 -0
  45. package/esm/request/mgop/env.js +15 -0
  46. package/esm/request/mgop/index.d.ts +3 -0
  47. package/esm/request/mgop/index.js +276 -0
  48. package/esm/request/mgop/responseCode.d.ts +20 -0
  49. package/esm/request/mgop/responseCode.js +37 -0
  50. package/esm/request/mgop/type.d.ts +34 -0
  51. package/esm/request/mgop/type.js +1 -0
  52. package/esm/request/uniRquest/index.d.ts +2 -0
  53. package/esm/request/uniRquest/index.js +66 -0
  54. package/esm/request/uniRquest/miniapp/index.d.ts +2 -0
  55. package/esm/request/uniRquest/miniapp/index.js +29 -0
  56. package/esm/request/uniRquest/miniapp-bytedance/index.d.ts +2 -0
  57. package/esm/request/uniRquest/miniapp-bytedance/index.js +41 -0
  58. package/esm/request/uniRquest/types.d.ts +65 -0
  59. package/esm/request/uniRquest/types.js +36 -0
  60. package/esm/request/uniRquest/utils.d.ts +9 -0
  61. package/esm/request/uniRquest/utils.js +69 -0
  62. package/esm/request/uniRquest/web/index.d.ts +2 -0
  63. package/esm/request/uniRquest/web/index.js +85 -0
  64. package/esm/request/uniRquest/wechat-miniprogram/index.d.ts +2 -0
  65. package/esm/request/uniRquest/wechat-miniprogram/index.js +41 -0
  66. package/esm/request/uniRquest/weex/index.d.ts +14 -0
  67. package/esm/request/uniRquest/weex/index.js +59 -0
  68. package/esm/storage/StorageUtil.d.ts +19 -0
  69. package/esm/storage/StorageUtil.js +75 -0
  70. package/esm/string/StringUtil.d.ts +392 -0
  71. package/esm/string/StringUtil.js +556 -0
  72. package/esm/system/SystemUtil.d.ts +46 -0
  73. package/esm/system/SystemUtil.js +122 -0
  74. package/esm/transfer/MapTransferUtil.d.ts +54 -0
  75. package/esm/transfer/MapTransferUtil.js +160 -0
  76. package/esm/transfer/TransferUtil.d.ts +98 -0
  77. package/esm/transfer/TransferUtil.js +323 -0
  78. package/esm/types.d.ts +25 -0
  79. package/esm/types.js +1 -0
  80. package/esm/url/UrlUtil.d.ts +30 -0
  81. package/esm/url/UrlUtil.js +85 -0
  82. package/lib/array/ArrayUtil.d.ts +109 -0
  83. package/lib/array/ArrayUtil.js +252 -0
  84. package/lib/array/TreeUtil.d.ts +151 -0
  85. package/lib/array/TreeUtil.js +422 -0
  86. package/lib/base/BaseUtil.d.ts +91 -0
  87. package/lib/base/BaseUtil.js +153 -0
  88. package/lib/browser/BrowserUtil.d.ts +57 -0
  89. package/lib/browser/BrowserUtil.js +347 -0
  90. package/lib/browser/fingerprint.d.ts +120 -0
  91. package/lib/browser/fingerprint.js +1500 -0
  92. package/lib/check/CheckUtil.d.ts +110 -0
  93. package/lib/check/CheckUtil.js +475 -0
  94. package/lib/common.d.ts +43 -0
  95. package/lib/common.js +50 -0
  96. package/lib/config.d.ts +7 -0
  97. package/lib/config.js +12 -0
  98. package/lib/cookie/CookieUtil.d.ts +56 -0
  99. package/lib/cookie/CookieUtil.js +22 -0
  100. package/lib/cookie/cookie.d.ts +2 -0
  101. package/lib/cookie/cookie.js +109 -0
  102. package/lib/date/DateUtil.d.ts +261 -0
  103. package/lib/date/DateUtil.js +773 -0
  104. package/lib/env/EnvUtil.d.ts +27 -0
  105. package/lib/env/EnvUtil.js +39 -0
  106. package/lib/env/env.d.ts +41 -0
  107. package/lib/env/env.js +112 -0
  108. package/lib/func/FunctionUtil.d.ts +77 -0
  109. package/lib/func/FunctionUtil.js +225 -0
  110. package/lib/index.d.ts +19 -0
  111. package/lib/index.js +144 -0
  112. package/lib/number/NumberUtil.d.ts +96 -0
  113. package/lib/number/NumberUtil.js +266 -0
  114. package/lib/object/ObjectUtil.d.ts +41 -0
  115. package/lib/object/ObjectUtil.js +168 -0
  116. package/lib/pwd/PasswordUtil.d.ts +33 -0
  117. package/lib/pwd/PasswordUtil.js +78 -0
  118. package/lib/pwd/crypto.d.ts +6 -0
  119. package/lib/pwd/crypto.js +1829 -0
  120. package/lib/request/RequestUtil.d.ts +52 -0
  121. package/lib/request/RequestUtil.js +94 -0
  122. package/lib/request/jsonp.d.ts +18 -0
  123. package/lib/request/jsonp.js +80 -0
  124. package/lib/request/mgop/env.d.ts +7 -0
  125. package/lib/request/mgop/env.js +21 -0
  126. package/lib/request/mgop/index.d.ts +3 -0
  127. package/lib/request/mgop/index.js +289 -0
  128. package/lib/request/mgop/responseCode.d.ts +20 -0
  129. package/lib/request/mgop/responseCode.js +42 -0
  130. package/lib/request/mgop/type.d.ts +34 -0
  131. package/lib/request/mgop/type.js +5 -0
  132. package/lib/request/uniRquest/index.d.ts +2 -0
  133. package/lib/request/uniRquest/index.js +77 -0
  134. package/lib/request/uniRquest/miniapp/index.d.ts +2 -0
  135. package/lib/request/uniRquest/miniapp/index.js +35 -0
  136. package/lib/request/uniRquest/miniapp-bytedance/index.d.ts +2 -0
  137. package/lib/request/uniRquest/miniapp-bytedance/index.js +47 -0
  138. package/lib/request/uniRquest/types.d.ts +65 -0
  139. package/lib/request/uniRquest/types.js +42 -0
  140. package/lib/request/uniRquest/utils.d.ts +9 -0
  141. package/lib/request/uniRquest/utils.js +83 -0
  142. package/lib/request/uniRquest/web/index.d.ts +2 -0
  143. package/lib/request/uniRquest/web/index.js +91 -0
  144. package/lib/request/uniRquest/wechat-miniprogram/index.d.ts +2 -0
  145. package/lib/request/uniRquest/wechat-miniprogram/index.js +47 -0
  146. package/lib/request/uniRquest/weex/index.d.ts +14 -0
  147. package/lib/request/uniRquest/weex/index.js +65 -0
  148. package/lib/storage/StorageUtil.d.ts +19 -0
  149. package/lib/storage/StorageUtil.js +85 -0
  150. package/lib/string/StringUtil.d.ts +392 -0
  151. package/lib/string/StringUtil.js +566 -0
  152. package/lib/system/SystemUtil.d.ts +46 -0
  153. package/lib/system/SystemUtil.js +132 -0
  154. package/lib/transfer/MapTransferUtil.d.ts +54 -0
  155. package/lib/transfer/MapTransferUtil.js +165 -0
  156. package/lib/transfer/TransferUtil.d.ts +98 -0
  157. package/lib/transfer/TransferUtil.js +333 -0
  158. package/lib/types.d.ts +25 -0
  159. package/lib/types.js +5 -0
  160. package/lib/url/UrlUtil.d.ts +30 -0
  161. package/lib/url/UrlUtil.js +95 -0
  162. package/package.json +56 -0
@@ -0,0 +1,27 @@
1
+ /**
2
+ * 环境判断工具
3
+ * @description
4
+ * @author nanshen
5
+ * @creat 2023-12-15 10:30:30
6
+ */
7
+ declare namespace EnvUtil {
8
+ /** @name Web */
9
+ const isWeb: boolean;
10
+ /** @name Node.js */
11
+ const isNode: boolean;
12
+ /** @name Weex */
13
+ const isWeex: boolean;
14
+ /** @name 阿里小程序环境 */
15
+ const isMiniApp: boolean;
16
+ /** @name 字节跳动小程序环境 */
17
+ const isByteDanceMicroApp: boolean;
18
+ /** @name 百度小程序环境 */
19
+ const isBaiduSmartProgram: boolean;
20
+ /** @name 快手小程序环境 */
21
+ const isKuaiShouMiniProgram: boolean;
22
+ /** @name 微信小程序环境 */
23
+ const isWeChatMiniProgram: boolean;
24
+ /** @name 快应用 */
25
+ const isQuickApp: boolean;
26
+ }
27
+ export default EnvUtil;
@@ -0,0 +1,29 @@
1
+ import env from './env';
2
+ /**
3
+ * 环境判断工具
4
+ * @description
5
+ * @author nanshen
6
+ * @creat 2023-12-15 10:30:30
7
+ */
8
+ var EnvUtil;
9
+ (function (EnvUtil) {
10
+ /** @name Web */
11
+ EnvUtil.isWeb = env.isWeb;
12
+ /** @name Node.js */
13
+ EnvUtil.isNode = env.isNode;
14
+ /** @name Weex */
15
+ EnvUtil.isWeex = env.isWeex;
16
+ /** @name 阿里小程序环境 */
17
+ EnvUtil.isMiniApp = env.isMiniApp;
18
+ /** @name 字节跳动小程序环境 */
19
+ EnvUtil.isByteDanceMicroApp = env.isByteDanceMicroApp;
20
+ /** @name 百度小程序环境 */
21
+ EnvUtil.isBaiduSmartProgram = env.isBaiduSmartProgram;
22
+ /** @name 快手小程序环境 */
23
+ EnvUtil.isKuaiShouMiniProgram = env.isKuaiShouMiniProgram;
24
+ /** @name 微信小程序环境 */
25
+ EnvUtil.isWeChatMiniProgram = env.isWeChatMiniProgram;
26
+ /** @name 快应用 */
27
+ EnvUtil.isQuickApp = env.isQuickApp;
28
+ })(EnvUtil || (EnvUtil = {}));
29
+ export default EnvUtil;
@@ -0,0 +1,41 @@
1
+ export const isWeb: boolean;
2
+ export const isNode: boolean;
3
+ export const isWeex: boolean;
4
+ export const isKraken: boolean;
5
+ export const isMiniApp: boolean;
6
+ export const isByteDanceMicroApp: boolean;
7
+ export const isBaiduSmartProgram: boolean;
8
+ export const isKuaiShouMiniProgram: boolean;
9
+ export const isWeChatMiniProgram: boolean;
10
+ export const isQuickApp: boolean;
11
+ export const isPHA: boolean;
12
+ export const isFRM: any;
13
+ export const isWindVane: boolean;
14
+ declare namespace _default {
15
+ export { isWeb };
16
+ export { isNode };
17
+ export { isWeex };
18
+ export { isKraken };
19
+ export { isMiniApp };
20
+ export { isByteDanceMicroApp };
21
+ export { isBaiduSmartProgram };
22
+ export { isKuaiShouMiniProgram };
23
+ export { isWeChatMiniProgram };
24
+ export { isQuickApp };
25
+ export { isPHA };
26
+ export { isWindVane };
27
+ export { isFRM };
28
+ export { getGlobal };
29
+ export { getData };
30
+ export { setData };
31
+ export { getInstance };
32
+ export { setStorageSync };
33
+ export { getStorageSync };
34
+ }
35
+ export default _default;
36
+ declare function getGlobal(): any;
37
+ declare function getData(key: any): any;
38
+ declare function setData(key: any, val: any): void;
39
+ declare function getInstance(): any;
40
+ declare function setStorageSync(key: any, val: any): void;
41
+ declare function getStorageSync(key: any): any;
package/esm/env/env.js ADDED
@@ -0,0 +1,106 @@
1
+ export var isWeb = typeof window !== 'undefined' && 'onload' in window;
2
+ export var isNode = typeof process !== 'undefined' && !!(process.versions && process.versions.node);
3
+ export var isWeex = typeof WXEnvironment !== 'undefined' && WXEnvironment.platform !== 'Web';
4
+ export var isKraken = typeof __kraken__ !== 'undefined';
5
+ export var isMiniApp = typeof my !== 'undefined' && my !== null && typeof my.alert !== 'undefined';
6
+ export var isByteDanceMicroApp = typeof tt !== 'undefined' && tt !== null && typeof tt.showToast !== 'undefined';
7
+ export var isBaiduSmartProgram = typeof swan !== 'undefined' && swan !== null && typeof swan.showToast !== 'undefined';
8
+ export var isKuaiShouMiniProgram = typeof ks !== 'undefined' && ks !== null && typeof ks.showToast !== 'undefined';
9
+ // In wechat mini program, wx.login is a function
10
+ // In wechat mini propgram webview, there is no wx.login, but exist wx.miniProgram
11
+ // In bytedance maicro app, there is wx variable.
12
+ // In kuaishou mini program, there is wx variable.
13
+ export var isWeChatMiniProgram = !isByteDanceMicroApp && typeof wx !== 'undefined' && wx !== null && (typeof wx.request !== 'undefined' || typeof wx.miniProgram !== 'undefined');
14
+ export var isQuickApp = typeof global !== 'undefined' && global !== null && typeof global.callNative !== 'undefined' && !isWeex;
15
+ export var isPHA = isWeb && typeof pha === 'object';
16
+ export var isFRM = isMiniApp && isWeb && my.isFRM;
17
+ // WindVane.call is a function while page importing windvane.js
18
+ var ua = typeof navigator === 'object' ? navigator.userAgent || navigator.swuserAgent : '';
19
+ export var isWindVane = /.+AliApp\((\w+)\/((?:\d+\.)+\d+)\).* .*(WindVane)(?:\/((?:\d+\.)+\d+))?.*/.test(ua) && isWeb && typeof WindVane !== 'undefined' && typeof WindVane.call !== 'undefined';
20
+ function getGlobal() {
21
+ var global;
22
+ if (isWeb) {
23
+ global = window;
24
+ } else if (isMiniApp) {
25
+ global = my;
26
+ } else if (isWeChatMiniProgram) {
27
+ global = wx;
28
+ } else {
29
+ global = window;
30
+ }
31
+ return global;
32
+ } // 设置全局变量
33
+ function setData(key, val) {
34
+ if (isWeb) {
35
+ window[key] = val;
36
+ } else {
37
+ var app = getApp();
38
+ app[key] = val;
39
+ }
40
+ } // 获取全局变量
41
+ function getData(key) {
42
+ if (isWeb) {
43
+ return window[key];
44
+ } else {
45
+ var app = getApp();
46
+ return app[key];
47
+ }
48
+ } // 获取全局实例
49
+ function getInstance() {
50
+ return isWeb ? window : getApp();
51
+ } // 设置storage
52
+ function setStorageSync(key, val) {
53
+ var global = getGlobal();
54
+ var value = JSON.stringify({
55
+ val: val
56
+ });
57
+ if (isWeb) {
58
+ global.localStorage.setItem(key, value);
59
+ } else if (isMiniApp) {
60
+ global.setStorageSync({
61
+ key: key,
62
+ data: value
63
+ });
64
+ } else if (isWeChatMiniProgram) {
65
+ global.setStorageSync(key, value);
66
+ }
67
+ } // 获取storage值
68
+ function getStorageSync(key) {
69
+ var global = getGlobal();
70
+ var value;
71
+ if (isWeb) {
72
+ value = global.localStorage.getItem(key);
73
+ } else if (isMiniApp) {
74
+ value = global.getStorageSync({
75
+ key: key
76
+ });
77
+ } else if (isWeChatMiniProgram) {
78
+ value = global.getStorageSync(key);
79
+ }
80
+ try {
81
+ return JSON.parse(value).val || value;
82
+ } catch (err) {
83
+ return value;
84
+ }
85
+ }
86
+ export default {
87
+ isWeb: isWeb,
88
+ isNode: isNode,
89
+ isWeex: isWeex,
90
+ isKraken: isKraken,
91
+ isMiniApp: isMiniApp,
92
+ isByteDanceMicroApp: isByteDanceMicroApp,
93
+ isBaiduSmartProgram: isBaiduSmartProgram,
94
+ isKuaiShouMiniProgram: isKuaiShouMiniProgram,
95
+ isWeChatMiniProgram: isWeChatMiniProgram,
96
+ isQuickApp: isQuickApp,
97
+ isPHA: isPHA,
98
+ isWindVane: isWindVane,
99
+ isFRM: isFRM,
100
+ getGlobal: getGlobal,
101
+ getData: getData,
102
+ setData: setData,
103
+ getInstance: getInstance,
104
+ setStorageSync: setStorageSync,
105
+ getStorageSync: getStorageSync
106
+ };
@@ -0,0 +1,77 @@
1
+ declare namespace FunctionUtil {
2
+ /**
3
+ * 函数柯里化
4
+ * @param { Function } fn 方法
5
+ * @param { Any } agrs 参数,可选
6
+ * @example
7
+ * // 实现一个判断数据类型的方法
8
+ const checktype = function(type, content) {
9
+ return Object.prototype.toString.call(content) === `[object ${type}]`;
10
+ }
11
+ checktype('Number',2); => true
12
+ // 这种方法总是要把type参数传过去,如果写错了就会影响到正确的结果了,可以考虑下如何做到把“Number“做到复用
13
+
14
+ const checktype = function(type, content) {
15
+ return Object.prototype.toString.call(content) === `[object ${type}]`;
16
+ }
17
+ const curry = curryFn(checktype)
18
+ const isNumber = curry('Number')
19
+ isNumber(2) => true
20
+ */
21
+ function curryFn(fn: any, ...arg: any): () => any;
22
+ /**
23
+ * 函数防抖
24
+ * @param fn 需要防抖的函数
25
+ * @param t 防抖时间,多久以后才能再执行 单位ms
26
+ * @param immediate true: 立刻执行方法且最后一次时间不执行, false: 等t时间之后再执行方法,如果t时间内执行,则在最后一次的t时间之后执行方法,类似动态搜索效果
27
+ * @example
28
+ * const query = debounceFn(()=>console.log(3),2000,true)
29
+ * query() => 3
30
+ * query()
31
+ * query()
32
+ * const query = debounceFn(()=>console.log(3),2000,false)
33
+ * query()
34
+ * query()
35
+ * query() => 3
36
+ */
37
+ function debounceFn<T extends Function>(fn: T, t?: number, immediate?: boolean): T;
38
+ /**
39
+ * 函数节流
40
+ * @param fn 需要节流的函数
41
+ * @param t 节流时间,多久以后执行一次方法 单位ms
42
+ * @example
43
+ * const query = throttleFn(()=>console.log(3),2000)
44
+ * query() => 3
45
+ * query()
46
+ * query()
47
+ */
48
+ function throttleFn<T extends Function>(fn: T, t?: number): T;
49
+ /**
50
+ * 函数只能调用一次
51
+ * @param { Function } fn 需要被处理的函数
52
+ * @example
53
+ * const canOnlyFireOnce = once(()=>console.log(1));
54
+ * for(let i =1;i<10;i++){
55
+ * canOnlyFireOnce();
56
+ * }
57
+ * // 1
58
+ */
59
+ function once<T extends Function>(fn: T): T;
60
+ /**
61
+ * 睡眠函数, 阻塞代码 timer毫秒
62
+ * @param timer 睡眠时长 (毫秒) 执行后续的操作
63
+ * @return promise
64
+ * @example
65
+ * const fn = async () =>{
66
+ * console.log(1)
67
+ * await sleepFn(2000)
68
+ * console.log(2)
69
+ * }
70
+ * fn()
71
+ * 1
72
+ * //两秒后
73
+ * 2
74
+ */
75
+ function sleepFn(timer?: number): Promise<void>;
76
+ }
77
+ export default FunctionUtil;
@@ -0,0 +1,215 @@
1
+ var __read = this && this.__read || function (o, n) {
2
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
3
+ if (!m) return o;
4
+ var i = m.call(o),
5
+ r,
6
+ ar = [],
7
+ e;
8
+ try {
9
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
10
+ } catch (error) {
11
+ e = {
12
+ error: error
13
+ };
14
+ } finally {
15
+ try {
16
+ if (r && !r.done && (m = i["return"])) m.call(i);
17
+ } finally {
18
+ if (e) throw e.error;
19
+ }
20
+ }
21
+ return ar;
22
+ };
23
+ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
24
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
25
+ if (ar || !(i in from)) {
26
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
27
+ ar[i] = from[i];
28
+ }
29
+ }
30
+ return to.concat(ar || Array.prototype.slice.call(from));
31
+ };
32
+ /**
33
+ * 函数工具
34
+ * @description
35
+ * @author nanshen
36
+ * @creat 2021-09-15 14:22:55
37
+ */
38
+ import BaseUtil from "../base/BaseUtil";
39
+ var FunctionUtil;
40
+ (function (FunctionUtil) {
41
+ /**
42
+ * 函数柯里化
43
+ * @param { Function } fn 方法
44
+ * @param { Any } agrs 参数,可选
45
+ * @example
46
+ * // 实现一个判断数据类型的方法
47
+ const checktype = function(type, content) {
48
+ return Object.prototype.toString.call(content) === `[object ${type}]`;
49
+ }
50
+ checktype('Number',2); => true
51
+ // 这种方法总是要把type参数传过去,如果写错了就会影响到正确的结果了,可以考虑下如何做到把“Number“做到复用
52
+
53
+ const checktype = function(type, content) {
54
+ return Object.prototype.toString.call(content) === `[object ${type}]`;
55
+ }
56
+ const curry = curryFn(checktype)
57
+ const isNumber = curry('Number')
58
+ isNumber(2) => true
59
+ */
60
+ function curryFn(fn) {
61
+ var arg = [];
62
+ for (var _i = 1; _i < arguments.length; _i++) {
63
+ arg[_i - 1] = arguments[_i];
64
+ }
65
+ if (!BaseUtil.isFunction(fn)) throw new Error("第一个参数必须是方法");
66
+ var _this = this;
67
+ var args = Array.from(arguments).slice(1);
68
+ // fn.length 属性指明函数的形参个数。
69
+ var len = fn.length;
70
+ return function () {
71
+ var _args = Array.from(arguments);
72
+ args.push.apply(args, __spreadArray([], __read(_args), false));
73
+ if (args.length < len) {
74
+ return curryFn.call.apply(curryFn, __spreadArray([_this, fn], __read(args), false));
75
+ }
76
+ return fn.apply(_this, args);
77
+ };
78
+ }
79
+ FunctionUtil.curryFn = curryFn;
80
+ /**
81
+ * 函数防抖
82
+ * @param fn 需要防抖的函数
83
+ * @param t 防抖时间,多久以后才能再执行 单位ms
84
+ * @param immediate true: 立刻执行方法且最后一次时间不执行, false: 等t时间之后再执行方法,如果t时间内执行,则在最后一次的t时间之后执行方法,类似动态搜索效果
85
+ * @example
86
+ * const query = debounceFn(()=>console.log(3),2000,true)
87
+ * query() => 3
88
+ * query()
89
+ * query()
90
+ * const query = debounceFn(()=>console.log(3),2000,false)
91
+ * query()
92
+ * query()
93
+ * query() => 3
94
+ */
95
+ function debounceFn(fn, t, immediate) {
96
+ if (t === void 0) {
97
+ t = 2000;
98
+ }
99
+ if (immediate === void 0) {
100
+ immediate = true;
101
+ }
102
+ if (!BaseUtil.isFunction(fn)) throw new Error("第一个参数必须是方法");
103
+ var time;
104
+ // 立刻执行第一次该方法
105
+ if (immediate) {
106
+ return function () {
107
+ clearTimeout(time);
108
+ if (!time) {
109
+ fn.apply(this, arguments);
110
+ }
111
+ time = setTimeout(function () {
112
+ setTimeout(time);
113
+ time = null;
114
+ }, t);
115
+ };
116
+ } else {
117
+ // 满足 time 时间结束之后自动执行一次该方法
118
+ return function () {
119
+ clearTimeout(time);
120
+ var that = this;
121
+ var arg = arguments;
122
+ time = setTimeout(function () {
123
+ setTimeout(time);
124
+ fn.apply(that, arg);
125
+ time = null;
126
+ }, t);
127
+ };
128
+ }
129
+ }
130
+ FunctionUtil.debounceFn = debounceFn;
131
+ /**
132
+ * 函数节流
133
+ * @param fn 需要节流的函数
134
+ * @param t 节流时间,多久以后执行一次方法 单位ms
135
+ * @example
136
+ * const query = throttleFn(()=>console.log(3),2000)
137
+ * query() => 3
138
+ * query()
139
+ * query()
140
+ */
141
+ function throttleFn(fn, t) {
142
+ if (t === void 0) {
143
+ t = 2000;
144
+ }
145
+ if (!BaseUtil.isFunction(fn)) throw new Error("第一个参数必须是方法");
146
+ var _fn = fn;
147
+ var time = null;
148
+ var first = true;
149
+ return function () {
150
+ var arg = arguments;
151
+ var _this = this;
152
+ if (first) {
153
+ _fn.apply(_this, arg);
154
+ first = false;
155
+ return;
156
+ }
157
+ if (time) return;
158
+ time = setTimeout(function () {
159
+ setTimeout(time);
160
+ time = null;
161
+ _fn.apply(_this, arg);
162
+ }, t);
163
+ };
164
+ }
165
+ FunctionUtil.throttleFn = throttleFn;
166
+ /**
167
+ * 函数只能调用一次
168
+ * @param { Function } fn 需要被处理的函数
169
+ * @example
170
+ * const canOnlyFireOnce = once(()=>console.log(1));
171
+ * for(let i =1;i<10;i++){
172
+ * canOnlyFireOnce();
173
+ * }
174
+ * // 1
175
+ */
176
+ function once(fn) {
177
+ if (!BaseUtil.isFunction(fn)) throw new Error("参数必须是方法");
178
+ var result;
179
+ return function () {
180
+ if (fn) {
181
+ result = fn.apply(this, arguments);
182
+ fn = null;
183
+ }
184
+ return result;
185
+ };
186
+ }
187
+ FunctionUtil.once = once;
188
+ /**
189
+ * 睡眠函数, 阻塞代码 timer毫秒
190
+ * @param timer 睡眠时长 (毫秒) 执行后续的操作
191
+ * @return promise
192
+ * @example
193
+ * const fn = async () =>{
194
+ * console.log(1)
195
+ * await sleepFn(2000)
196
+ * console.log(2)
197
+ * }
198
+ * fn()
199
+ * 1
200
+ * //两秒后
201
+ * 2
202
+ */
203
+ function sleepFn(timer) {
204
+ if (timer === void 0) {
205
+ timer = 2000;
206
+ }
207
+ return new Promise(function (resolve) {
208
+ setTimeout(function () {
209
+ resolve();
210
+ }, timer);
211
+ });
212
+ }
213
+ FunctionUtil.sleepFn = sleepFn;
214
+ })(FunctionUtil || (FunctionUtil = {}));
215
+ export default FunctionUtil;
package/esm/index.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ export { default as ArrayUtil } from './array/ArrayUtil';
2
+ export { default as TreeUtil } from './array/TreeUtil';
3
+ export { default as BaseUtil } from './base/BaseUtil';
4
+ export { default as BrowserUtil } from './browser/BrowserUtil';
5
+ export { default as CheckUtil } from './check/CheckUtil';
6
+ export { default as CookieUtil } from './cookie/CookieUtil';
7
+ export { default as DateUtil } from './date/DateUtil';
8
+ export { default as EnvUtil } from './env/EnvUtil';
9
+ export { default as FunctionUtil } from './func/FunctionUtil';
10
+ export { default as NumberUtil } from './number/NumberUtil';
11
+ export { default as ObjectUtil } from './object/ObjectUtil';
12
+ export { default as PasswordUtil } from './pwd/PasswordUtil';
13
+ export { default as RequestUtil } from './request/RequestUtil';
14
+ export { default as StorageUtil } from './storage/StorageUtil';
15
+ export { default as StringUtil } from './string/StringUtil';
16
+ export { default as SystemUtil } from './system/SystemUtil';
17
+ export { default as MapTransferUtil } from './transfer/MapTransferUtil';
18
+ export { default as TransferUtil } from './transfer/TransferUtil';
19
+ export { default as UrlUtil } from './url/UrlUtil';
package/esm/index.js ADDED
@@ -0,0 +1,19 @@
1
+ export { default as ArrayUtil } from './array/ArrayUtil';
2
+ export { default as TreeUtil } from './array/TreeUtil';
3
+ export { default as BaseUtil } from './base/BaseUtil';
4
+ export { default as BrowserUtil } from './browser/BrowserUtil';
5
+ export { default as CheckUtil } from './check/CheckUtil';
6
+ export { default as CookieUtil } from './cookie/CookieUtil';
7
+ export { default as DateUtil } from './date/DateUtil';
8
+ export { default as EnvUtil } from './env/EnvUtil';
9
+ export { default as FunctionUtil } from './func/FunctionUtil';
10
+ export { default as NumberUtil } from './number/NumberUtil';
11
+ export { default as ObjectUtil } from './object/ObjectUtil';
12
+ export { default as PasswordUtil } from './pwd/PasswordUtil';
13
+ export { default as RequestUtil } from './request/RequestUtil';
14
+ export { default as StorageUtil } from './storage/StorageUtil';
15
+ export { default as StringUtil } from './string/StringUtil';
16
+ export { default as SystemUtil } from './system/SystemUtil';
17
+ export { default as MapTransferUtil } from './transfer/MapTransferUtil';
18
+ export { default as TransferUtil } from './transfer/TransferUtil';
19
+ export { default as UrlUtil } from './url/UrlUtil';
@@ -0,0 +1,96 @@
1
+ declare namespace NumberUtil {
2
+ /**
3
+ * 判断是否为整数
4
+ * @param {Number} num 数字
5
+ */
6
+ const isInteger: (num: number) => boolean;
7
+ /**
8
+ * 判断是否为小数
9
+ * @param {Number} num 数字
10
+ */
11
+ const isFloat: (num: number) => boolean;
12
+ /**
13
+ * 判断是否是 NaN
14
+ * @param num 数字
15
+ */
16
+ const isaNaN: (num: number) => boolean;
17
+ /**
18
+ * 判断是否是有理数
19
+ * @param num 数字
20
+ */
21
+ const isaFinite: (num: number) => boolean;
22
+ /**
23
+ * 转为有理数
24
+ * @param value 要转换的值
25
+ *
26
+ * @example
27
+ * toFinite(3.2) => 3.2
28
+ * toFinite(Infinity) => 1.7976e+308
29
+ * toFinite('3.2') => 3.2
30
+ */
31
+ const toFinite: (value: any) => number;
32
+ /**
33
+ * 检查数字是否在指定区间内
34
+ * @param num 要检测的数字
35
+ * @param start 区间的开始,默认值为0
36
+ * @param end 区间的结束(区间不包含此边界值)
37
+ * @example
38
+ * inRange(10,1,100) => true
39
+ */
40
+ const inRange: (num: number, start: number, end: number) => boolean;
41
+ /**
42
+ * 生成随机数,支持随机整数和随机小数
43
+ * @param {Number} lower 下边界,默认0
44
+ * @param {Number} upper 上边界,默认1
45
+ * @param {Boolean} floating 随机小数的位数,默认为0,即随机整数
46
+ *
47
+ * @example
48
+ * random(0, 5) => an integer between 0 and 5
49
+ * random(5) => also random(0, 5)
50
+ * random(1.2, 5.2, 1) => a floating-point number between 1.2 and 5.2
51
+ */
52
+ const random: (lower: number, upper: number, floating?: number) => number;
53
+ /**
54
+ * 保留n位小数
55
+ * @param val 任意类型
56
+ * @param n 小数位数
57
+ * @returns 不是string|number 返回0
58
+ */
59
+ function correctNumberInput(val: any, n?: number, type?: "number" | "string"): string | number;
60
+ /**
61
+ * 解决两个数相加精度丢失问题
62
+ * @param a 任意类型
63
+ * @param b 任意类型
64
+ * @returns {Number} 错误返回0
65
+ */
66
+ function floatAdd(a: any, b: any): number;
67
+ /**
68
+ * 解决两个数相减精度丢失问题
69
+ * @param a 任意类型
70
+ * @param b 任意类型
71
+ * @returns {Number}错误返回0
72
+ */
73
+ function floatSub(a: any, b: any): number;
74
+ /**
75
+ * 解决两个数相乘精度丢失问题
76
+ * @param a 任意类型
77
+ * @param b 任意类型
78
+ * @returns {Number}
79
+ */
80
+ function floatMul(a: any, b: any): number;
81
+ /**
82
+ * 解决两个数相除精度丢失问题
83
+ * @param a 任意类型
84
+ * @param b 任意类型
85
+ * @returns 错误返回0
86
+ */
87
+ function floatDiv(a: any, b: any): number;
88
+ /**
89
+ * n在count中的占比%
90
+ * @param n
91
+ * @param count
92
+ * @returns
93
+ */
94
+ const number2percentage: (n: number, count: number) => string;
95
+ }
96
+ export default NumberUtil;