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,39 @@
1
+ "use strict";
2
+
3
+ var __importDefault = this && this.__importDefault || function (mod) {
4
+ return mod && mod.__esModule ? mod : {
5
+ "default": mod
6
+ };
7
+ };
8
+ Object.defineProperty(exports, "__esModule", {
9
+ value: true
10
+ });
11
+ var env_1 = __importDefault(require("./env"));
12
+ /**
13
+ * 环境判断工具
14
+ * @description
15
+ * @author nanshen
16
+ * @creat 2023-12-15 10:30:30
17
+ */
18
+ var EnvUtil;
19
+ (function (EnvUtil) {
20
+ /** @name Web */
21
+ EnvUtil.isWeb = env_1.default.isWeb;
22
+ /** @name Node.js */
23
+ EnvUtil.isNode = env_1.default.isNode;
24
+ /** @name Weex */
25
+ EnvUtil.isWeex = env_1.default.isWeex;
26
+ /** @name 阿里小程序环境 */
27
+ EnvUtil.isMiniApp = env_1.default.isMiniApp;
28
+ /** @name 字节跳动小程序环境 */
29
+ EnvUtil.isByteDanceMicroApp = env_1.default.isByteDanceMicroApp;
30
+ /** @name 百度小程序环境 */
31
+ EnvUtil.isBaiduSmartProgram = env_1.default.isBaiduSmartProgram;
32
+ /** @name 快手小程序环境 */
33
+ EnvUtil.isKuaiShouMiniProgram = env_1.default.isKuaiShouMiniProgram;
34
+ /** @name 微信小程序环境 */
35
+ EnvUtil.isWeChatMiniProgram = env_1.default.isWeChatMiniProgram;
36
+ /** @name 快应用 */
37
+ EnvUtil.isQuickApp = env_1.default.isQuickApp;
38
+ })(EnvUtil || (EnvUtil = {}));
39
+ exports.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/lib/env/env.js ADDED
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isWindVane = exports.isFRM = exports.isPHA = exports.isQuickApp = exports.isWeChatMiniProgram = exports.isKuaiShouMiniProgram = exports.isBaiduSmartProgram = exports.isByteDanceMicroApp = exports.isMiniApp = exports.isKraken = exports.isWeex = exports.isNode = exports.isWeb = void 0;
7
+ exports.isWeb = typeof window !== 'undefined' && 'onload' in window;
8
+ exports.isNode = typeof process !== 'undefined' && !!(process.versions && process.versions.node);
9
+ exports.isWeex = typeof WXEnvironment !== 'undefined' && WXEnvironment.platform !== 'Web';
10
+ exports.isKraken = typeof __kraken__ !== 'undefined';
11
+ exports.isMiniApp = typeof my !== 'undefined' && my !== null && typeof my.alert !== 'undefined';
12
+ exports.isByteDanceMicroApp = typeof tt !== 'undefined' && tt !== null && typeof tt.showToast !== 'undefined';
13
+ exports.isBaiduSmartProgram = typeof swan !== 'undefined' && swan !== null && typeof swan.showToast !== 'undefined';
14
+ exports.isKuaiShouMiniProgram = typeof ks !== 'undefined' && ks !== null && typeof ks.showToast !== 'undefined';
15
+ // In wechat mini program, wx.login is a function
16
+ // In wechat mini propgram webview, there is no wx.login, but exist wx.miniProgram
17
+ // In bytedance maicro app, there is wx variable.
18
+ // In kuaishou mini program, there is wx variable.
19
+ exports.isWeChatMiniProgram = !exports.isByteDanceMicroApp && typeof wx !== 'undefined' && wx !== null && (typeof wx.request !== 'undefined' || typeof wx.miniProgram !== 'undefined');
20
+ exports.isQuickApp = typeof global !== 'undefined' && global !== null && typeof global.callNative !== 'undefined' && !exports.isWeex;
21
+ exports.isPHA = exports.isWeb && typeof pha === 'object';
22
+ exports.isFRM = exports.isMiniApp && exports.isWeb && my.isFRM;
23
+ // WindVane.call is a function while page importing windvane.js
24
+ var ua = typeof navigator === 'object' ? navigator.userAgent || navigator.swuserAgent : '';
25
+ exports.isWindVane = /.+AliApp\((\w+)\/((?:\d+\.)+\d+)\).* .*(WindVane)(?:\/((?:\d+\.)+\d+))?.*/.test(ua) && exports.isWeb && typeof WindVane !== 'undefined' && typeof WindVane.call !== 'undefined';
26
+ function getGlobal() {
27
+ var global;
28
+ if (exports.isWeb) {
29
+ global = window;
30
+ } else if (exports.isMiniApp) {
31
+ global = my;
32
+ } else if (exports.isWeChatMiniProgram) {
33
+ global = wx;
34
+ } else {
35
+ global = window;
36
+ }
37
+ return global;
38
+ } // 设置全局变量
39
+ function setData(key, val) {
40
+ if (exports.isWeb) {
41
+ window[key] = val;
42
+ } else {
43
+ var app = getApp();
44
+ app[key] = val;
45
+ }
46
+ } // 获取全局变量
47
+ function getData(key) {
48
+ if (exports.isWeb) {
49
+ return window[key];
50
+ } else {
51
+ var app = getApp();
52
+ return app[key];
53
+ }
54
+ } // 获取全局实例
55
+ function getInstance() {
56
+ return exports.isWeb ? window : getApp();
57
+ } // 设置storage
58
+ function setStorageSync(key, val) {
59
+ var global = getGlobal();
60
+ var value = JSON.stringify({
61
+ val: val
62
+ });
63
+ if (exports.isWeb) {
64
+ global.localStorage.setItem(key, value);
65
+ } else if (exports.isMiniApp) {
66
+ global.setStorageSync({
67
+ key: key,
68
+ data: value
69
+ });
70
+ } else if (exports.isWeChatMiniProgram) {
71
+ global.setStorageSync(key, value);
72
+ }
73
+ } // 获取storage值
74
+ function getStorageSync(key) {
75
+ var global = getGlobal();
76
+ var value;
77
+ if (exports.isWeb) {
78
+ value = global.localStorage.getItem(key);
79
+ } else if (exports.isMiniApp) {
80
+ value = global.getStorageSync({
81
+ key: key
82
+ });
83
+ } else if (exports.isWeChatMiniProgram) {
84
+ value = global.getStorageSync(key);
85
+ }
86
+ try {
87
+ return JSON.parse(value).val || value;
88
+ } catch (err) {
89
+ return value;
90
+ }
91
+ }
92
+ exports.default = {
93
+ isWeb: exports.isWeb,
94
+ isNode: exports.isNode,
95
+ isWeex: exports.isWeex,
96
+ isKraken: exports.isKraken,
97
+ isMiniApp: exports.isMiniApp,
98
+ isByteDanceMicroApp: exports.isByteDanceMicroApp,
99
+ isBaiduSmartProgram: exports.isBaiduSmartProgram,
100
+ isKuaiShouMiniProgram: exports.isKuaiShouMiniProgram,
101
+ isWeChatMiniProgram: exports.isWeChatMiniProgram,
102
+ isQuickApp: exports.isQuickApp,
103
+ isPHA: exports.isPHA,
104
+ isWindVane: exports.isWindVane,
105
+ isFRM: exports.isFRM,
106
+ getGlobal: getGlobal,
107
+ getData: getData,
108
+ setData: setData,
109
+ getInstance: getInstance,
110
+ setStorageSync: setStorageSync,
111
+ getStorageSync: getStorageSync
112
+ };
@@ -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,225 @@
1
+ "use strict";
2
+
3
+ var __read = this && this.__read || function (o, n) {
4
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
5
+ if (!m) return o;
6
+ var i = m.call(o),
7
+ r,
8
+ ar = [],
9
+ e;
10
+ try {
11
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
12
+ } catch (error) {
13
+ e = {
14
+ error: error
15
+ };
16
+ } finally {
17
+ try {
18
+ if (r && !r.done && (m = i["return"])) m.call(i);
19
+ } finally {
20
+ if (e) throw e.error;
21
+ }
22
+ }
23
+ return ar;
24
+ };
25
+ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
26
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
27
+ if (ar || !(i in from)) {
28
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
29
+ ar[i] = from[i];
30
+ }
31
+ }
32
+ return to.concat(ar || Array.prototype.slice.call(from));
33
+ };
34
+ var __importDefault = this && this.__importDefault || function (mod) {
35
+ return mod && mod.__esModule ? mod : {
36
+ "default": mod
37
+ };
38
+ };
39
+ Object.defineProperty(exports, "__esModule", {
40
+ value: true
41
+ });
42
+ /**
43
+ * 函数工具
44
+ * @description
45
+ * @author nanshen
46
+ * @creat 2021-09-15 14:22:55
47
+ */
48
+ var BaseUtil_1 = __importDefault(require("../base/BaseUtil"));
49
+ var FunctionUtil;
50
+ (function (FunctionUtil) {
51
+ /**
52
+ * 函数柯里化
53
+ * @param { Function } fn 方法
54
+ * @param { Any } agrs 参数,可选
55
+ * @example
56
+ * // 实现一个判断数据类型的方法
57
+ const checktype = function(type, content) {
58
+ return Object.prototype.toString.call(content) === `[object ${type}]`;
59
+ }
60
+ checktype('Number',2); => true
61
+ // 这种方法总是要把type参数传过去,如果写错了就会影响到正确的结果了,可以考虑下如何做到把“Number“做到复用
62
+
63
+ const checktype = function(type, content) {
64
+ return Object.prototype.toString.call(content) === `[object ${type}]`;
65
+ }
66
+ const curry = curryFn(checktype)
67
+ const isNumber = curry('Number')
68
+ isNumber(2) => true
69
+ */
70
+ function curryFn(fn) {
71
+ var arg = [];
72
+ for (var _i = 1; _i < arguments.length; _i++) {
73
+ arg[_i - 1] = arguments[_i];
74
+ }
75
+ if (!BaseUtil_1.default.isFunction(fn)) throw new Error("第一个参数必须是方法");
76
+ var _this = this;
77
+ var args = Array.from(arguments).slice(1);
78
+ // fn.length 属性指明函数的形参个数。
79
+ var len = fn.length;
80
+ return function () {
81
+ var _args = Array.from(arguments);
82
+ args.push.apply(args, __spreadArray([], __read(_args), false));
83
+ if (args.length < len) {
84
+ return curryFn.call.apply(curryFn, __spreadArray([_this, fn], __read(args), false));
85
+ }
86
+ return fn.apply(_this, args);
87
+ };
88
+ }
89
+ FunctionUtil.curryFn = curryFn;
90
+ /**
91
+ * 函数防抖
92
+ * @param fn 需要防抖的函数
93
+ * @param t 防抖时间,多久以后才能再执行 单位ms
94
+ * @param immediate true: 立刻执行方法且最后一次时间不执行, false: 等t时间之后再执行方法,如果t时间内执行,则在最后一次的t时间之后执行方法,类似动态搜索效果
95
+ * @example
96
+ * const query = debounceFn(()=>console.log(3),2000,true)
97
+ * query() => 3
98
+ * query()
99
+ * query()
100
+ * const query = debounceFn(()=>console.log(3),2000,false)
101
+ * query()
102
+ * query()
103
+ * query() => 3
104
+ */
105
+ function debounceFn(fn, t, immediate) {
106
+ if (t === void 0) {
107
+ t = 2000;
108
+ }
109
+ if (immediate === void 0) {
110
+ immediate = true;
111
+ }
112
+ if (!BaseUtil_1.default.isFunction(fn)) throw new Error("第一个参数必须是方法");
113
+ var time;
114
+ // 立刻执行第一次该方法
115
+ if (immediate) {
116
+ return function () {
117
+ clearTimeout(time);
118
+ if (!time) {
119
+ fn.apply(this, arguments);
120
+ }
121
+ time = setTimeout(function () {
122
+ setTimeout(time);
123
+ time = null;
124
+ }, t);
125
+ };
126
+ } else {
127
+ // 满足 time 时间结束之后自动执行一次该方法
128
+ return function () {
129
+ clearTimeout(time);
130
+ var that = this;
131
+ var arg = arguments;
132
+ time = setTimeout(function () {
133
+ setTimeout(time);
134
+ fn.apply(that, arg);
135
+ time = null;
136
+ }, t);
137
+ };
138
+ }
139
+ }
140
+ FunctionUtil.debounceFn = debounceFn;
141
+ /**
142
+ * 函数节流
143
+ * @param fn 需要节流的函数
144
+ * @param t 节流时间,多久以后执行一次方法 单位ms
145
+ * @example
146
+ * const query = throttleFn(()=>console.log(3),2000)
147
+ * query() => 3
148
+ * query()
149
+ * query()
150
+ */
151
+ function throttleFn(fn, t) {
152
+ if (t === void 0) {
153
+ t = 2000;
154
+ }
155
+ if (!BaseUtil_1.default.isFunction(fn)) throw new Error("第一个参数必须是方法");
156
+ var _fn = fn;
157
+ var time = null;
158
+ var first = true;
159
+ return function () {
160
+ var arg = arguments;
161
+ var _this = this;
162
+ if (first) {
163
+ _fn.apply(_this, arg);
164
+ first = false;
165
+ return;
166
+ }
167
+ if (time) return;
168
+ time = setTimeout(function () {
169
+ setTimeout(time);
170
+ time = null;
171
+ _fn.apply(_this, arg);
172
+ }, t);
173
+ };
174
+ }
175
+ FunctionUtil.throttleFn = throttleFn;
176
+ /**
177
+ * 函数只能调用一次
178
+ * @param { Function } fn 需要被处理的函数
179
+ * @example
180
+ * const canOnlyFireOnce = once(()=>console.log(1));
181
+ * for(let i =1;i<10;i++){
182
+ * canOnlyFireOnce();
183
+ * }
184
+ * // 1
185
+ */
186
+ function once(fn) {
187
+ if (!BaseUtil_1.default.isFunction(fn)) throw new Error("参数必须是方法");
188
+ var result;
189
+ return function () {
190
+ if (fn) {
191
+ result = fn.apply(this, arguments);
192
+ fn = null;
193
+ }
194
+ return result;
195
+ };
196
+ }
197
+ FunctionUtil.once = once;
198
+ /**
199
+ * 睡眠函数, 阻塞代码 timer毫秒
200
+ * @param timer 睡眠时长 (毫秒) 执行后续的操作
201
+ * @return promise
202
+ * @example
203
+ * const fn = async () =>{
204
+ * console.log(1)
205
+ * await sleepFn(2000)
206
+ * console.log(2)
207
+ * }
208
+ * fn()
209
+ * 1
210
+ * //两秒后
211
+ * 2
212
+ */
213
+ function sleepFn(timer) {
214
+ if (timer === void 0) {
215
+ timer = 2000;
216
+ }
217
+ return new Promise(function (resolve) {
218
+ setTimeout(function () {
219
+ resolve();
220
+ }, timer);
221
+ });
222
+ }
223
+ FunctionUtil.sleepFn = sleepFn;
224
+ })(FunctionUtil || (FunctionUtil = {}));
225
+ exports.default = FunctionUtil;
package/lib/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/lib/index.js ADDED
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+
3
+ var __importDefault = this && this.__importDefault || function (mod) {
4
+ return mod && mod.__esModule ? mod : {
5
+ "default": mod
6
+ };
7
+ };
8
+ Object.defineProperty(exports, "__esModule", {
9
+ value: true
10
+ });
11
+ exports.UrlUtil = exports.TransferUtil = exports.MapTransferUtil = exports.SystemUtil = exports.StringUtil = exports.StorageUtil = exports.RequestUtil = exports.PasswordUtil = exports.ObjectUtil = exports.NumberUtil = exports.FunctionUtil = exports.EnvUtil = exports.DateUtil = exports.CookieUtil = exports.CheckUtil = exports.BrowserUtil = exports.BaseUtil = exports.TreeUtil = exports.ArrayUtil = void 0;
12
+ var ArrayUtil_1 = require("./array/ArrayUtil");
13
+ Object.defineProperty(exports, "ArrayUtil", {
14
+ enumerable: true,
15
+ get: function get() {
16
+ return __importDefault(ArrayUtil_1).default;
17
+ }
18
+ });
19
+ var TreeUtil_1 = require("./array/TreeUtil");
20
+ Object.defineProperty(exports, "TreeUtil", {
21
+ enumerable: true,
22
+ get: function get() {
23
+ return __importDefault(TreeUtil_1).default;
24
+ }
25
+ });
26
+ var BaseUtil_1 = require("./base/BaseUtil");
27
+ Object.defineProperty(exports, "BaseUtil", {
28
+ enumerable: true,
29
+ get: function get() {
30
+ return __importDefault(BaseUtil_1).default;
31
+ }
32
+ });
33
+ var BrowserUtil_1 = require("./browser/BrowserUtil");
34
+ Object.defineProperty(exports, "BrowserUtil", {
35
+ enumerable: true,
36
+ get: function get() {
37
+ return __importDefault(BrowserUtil_1).default;
38
+ }
39
+ });
40
+ var CheckUtil_1 = require("./check/CheckUtil");
41
+ Object.defineProperty(exports, "CheckUtil", {
42
+ enumerable: true,
43
+ get: function get() {
44
+ return __importDefault(CheckUtil_1).default;
45
+ }
46
+ });
47
+ var CookieUtil_1 = require("./cookie/CookieUtil");
48
+ Object.defineProperty(exports, "CookieUtil", {
49
+ enumerable: true,
50
+ get: function get() {
51
+ return __importDefault(CookieUtil_1).default;
52
+ }
53
+ });
54
+ var DateUtil_1 = require("./date/DateUtil");
55
+ Object.defineProperty(exports, "DateUtil", {
56
+ enumerable: true,
57
+ get: function get() {
58
+ return __importDefault(DateUtil_1).default;
59
+ }
60
+ });
61
+ var EnvUtil_1 = require("./env/EnvUtil");
62
+ Object.defineProperty(exports, "EnvUtil", {
63
+ enumerable: true,
64
+ get: function get() {
65
+ return __importDefault(EnvUtil_1).default;
66
+ }
67
+ });
68
+ var FunctionUtil_1 = require("./func/FunctionUtil");
69
+ Object.defineProperty(exports, "FunctionUtil", {
70
+ enumerable: true,
71
+ get: function get() {
72
+ return __importDefault(FunctionUtil_1).default;
73
+ }
74
+ });
75
+ var NumberUtil_1 = require("./number/NumberUtil");
76
+ Object.defineProperty(exports, "NumberUtil", {
77
+ enumerable: true,
78
+ get: function get() {
79
+ return __importDefault(NumberUtil_1).default;
80
+ }
81
+ });
82
+ var ObjectUtil_1 = require("./object/ObjectUtil");
83
+ Object.defineProperty(exports, "ObjectUtil", {
84
+ enumerable: true,
85
+ get: function get() {
86
+ return __importDefault(ObjectUtil_1).default;
87
+ }
88
+ });
89
+ var PasswordUtil_1 = require("./pwd/PasswordUtil");
90
+ Object.defineProperty(exports, "PasswordUtil", {
91
+ enumerable: true,
92
+ get: function get() {
93
+ return __importDefault(PasswordUtil_1).default;
94
+ }
95
+ });
96
+ var RequestUtil_1 = require("./request/RequestUtil");
97
+ Object.defineProperty(exports, "RequestUtil", {
98
+ enumerable: true,
99
+ get: function get() {
100
+ return __importDefault(RequestUtil_1).default;
101
+ }
102
+ });
103
+ var StorageUtil_1 = require("./storage/StorageUtil");
104
+ Object.defineProperty(exports, "StorageUtil", {
105
+ enumerable: true,
106
+ get: function get() {
107
+ return __importDefault(StorageUtil_1).default;
108
+ }
109
+ });
110
+ var StringUtil_1 = require("./string/StringUtil");
111
+ Object.defineProperty(exports, "StringUtil", {
112
+ enumerable: true,
113
+ get: function get() {
114
+ return __importDefault(StringUtil_1).default;
115
+ }
116
+ });
117
+ var SystemUtil_1 = require("./system/SystemUtil");
118
+ Object.defineProperty(exports, "SystemUtil", {
119
+ enumerable: true,
120
+ get: function get() {
121
+ return __importDefault(SystemUtil_1).default;
122
+ }
123
+ });
124
+ var MapTransferUtil_1 = require("./transfer/MapTransferUtil");
125
+ Object.defineProperty(exports, "MapTransferUtil", {
126
+ enumerable: true,
127
+ get: function get() {
128
+ return __importDefault(MapTransferUtil_1).default;
129
+ }
130
+ });
131
+ var TransferUtil_1 = require("./transfer/TransferUtil");
132
+ Object.defineProperty(exports, "TransferUtil", {
133
+ enumerable: true,
134
+ get: function get() {
135
+ return __importDefault(TransferUtil_1).default;
136
+ }
137
+ });
138
+ var UrlUtil_1 = require("./url/UrlUtil");
139
+ Object.defineProperty(exports, "UrlUtil", {
140
+ enumerable: true,
141
+ get: function get() {
142
+ return __importDefault(UrlUtil_1).default;
143
+ }
144
+ });