vite-uni-dev-tool 0.0.12 → 0.0.13

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 (181) hide show
  1. package/dist/const.d.ts +133 -0
  2. package/dist/const.d.ts.map +1 -0
  3. package/dist/const.js +36 -0
  4. package/dist/core.d.ts +52 -0
  5. package/dist/core.d.ts.map +1 -0
  6. package/dist/core.js +80 -0
  7. package/dist/devConsole/index.d.ts +169 -0
  8. package/dist/devConsole/index.d.ts.map +1 -0
  9. package/dist/devConsole/index.js +270 -0
  10. package/dist/devEvent/index.d.ts +286 -0
  11. package/dist/devEvent/index.d.ts.map +1 -0
  12. package/dist/devEvent/index.js +435 -0
  13. package/dist/devEventBus/index.d.ts +42 -0
  14. package/dist/devEventBus/index.d.ts.map +1 -0
  15. package/dist/devEventBus/index.js +70 -0
  16. package/dist/devIntercept/index.d.ts +119 -0
  17. package/dist/devIntercept/index.d.ts.map +1 -0
  18. package/dist/devIntercept/index.js +582 -0
  19. package/dist/devRunJS/index.d.ts +67 -0
  20. package/dist/devRunJS/index.d.ts.map +1 -0
  21. package/dist/devStore/index.d.ts +178 -0
  22. package/dist/devStore/index.d.ts.map +1 -0
  23. package/dist/devStore/index.js +395 -0
  24. package/dist/devToolInfo/index.d.ts +17 -0
  25. package/dist/devToolInfo/index.d.ts.map +1 -0
  26. package/dist/devToolInfo/index.js +15 -0
  27. package/{dev → dist}/plugins/uniDevTool/uniDevTool.d.ts +7 -1
  28. package/dist/plugins/uniDevTool/uniDevTool.d.ts.map +1 -0
  29. package/dist/plugins/uniDevTool/uniDevTool.js +35 -0
  30. package/{dev → dist}/plugins/utils/index.d.ts +3 -0
  31. package/{dev → dist}/plugins/utils/index.d.ts.map +1 -1
  32. package/dist/plugins/utils/index.js +1 -0
  33. package/dist/type.d.ts +264 -0
  34. package/dist/type.d.ts.map +1 -0
  35. package/dist/utils/array.d.ts +2 -0
  36. package/dist/utils/array.d.ts.map +1 -0
  37. package/dist/utils/array.js +12 -0
  38. package/dist/utils/date.d.ts +19 -0
  39. package/dist/utils/date.d.ts.map +1 -0
  40. package/dist/utils/date.js +40 -0
  41. package/dist/utils/file.d.ts +11 -0
  42. package/dist/utils/file.d.ts.map +1 -0
  43. package/dist/utils/file.js +87 -0
  44. package/dist/utils/function.d.ts +28 -0
  45. package/dist/utils/function.d.ts.map +1 -0
  46. package/dist/utils/function.js +46 -0
  47. package/dist/utils/index.d.ts +11 -0
  48. package/dist/utils/index.d.ts.map +1 -0
  49. package/dist/utils/index.js +55 -0
  50. package/dist/utils/ip.d.ts +5 -0
  51. package/dist/utils/ip.d.ts.map +1 -0
  52. package/dist/utils/ip.js +21 -0
  53. package/dist/utils/language.d.ts +29 -0
  54. package/dist/utils/language.d.ts.map +1 -0
  55. package/dist/utils/language.js +50 -0
  56. package/dist/utils/object.d.ts +49 -0
  57. package/dist/utils/object.d.ts.map +1 -0
  58. package/dist/utils/object.js +118 -0
  59. package/dist/utils/page.d.ts +7 -0
  60. package/dist/utils/page.d.ts.map +1 -0
  61. package/dist/utils/page.js +7 -0
  62. package/dist/utils/platform.d.ts +4 -0
  63. package/dist/utils/platform.d.ts.map +1 -0
  64. package/dist/utils/platform.js +14 -0
  65. package/dist/utils/string.d.ts +45 -0
  66. package/dist/utils/string.d.ts.map +1 -0
  67. package/dist/utils/string.js +88 -0
  68. package/dist/utils/utils.d.ts +16 -0
  69. package/dist/utils/utils.d.ts.map +1 -0
  70. package/dist/v2/AutoSizer/utils.d.ts +5 -0
  71. package/dist/v2/AutoSizer/utils.d.ts.map +1 -0
  72. package/dist/v2/JsonPretty/hooks/useClipboard.d.ts +4 -0
  73. package/dist/v2/JsonPretty/hooks/useClipboard.d.ts.map +1 -0
  74. package/dist/v2/JsonPretty/hooks/useError.d.ts +8 -0
  75. package/dist/v2/JsonPretty/hooks/useError.d.ts.map +1 -0
  76. package/dist/v2/JsonPretty/type.d.ts +93 -0
  77. package/dist/v2/JsonPretty/type.d.ts.map +1 -0
  78. package/dist/v3/AutoSizer/utils.d.ts +5 -0
  79. package/dist/v3/AutoSizer/utils.d.ts.map +1 -0
  80. package/dist/v3/ConsoleList/staticTips.d.ts +13 -0
  81. package/dist/v3/ConsoleList/staticTips.d.ts.map +1 -0
  82. package/dist/v3/JsonPretty/hooks/useClipboard.d.ts +4 -0
  83. package/dist/v3/JsonPretty/hooks/useClipboard.d.ts.map +1 -0
  84. package/dist/v3/JsonPretty/hooks/useError.d.ts +8 -0
  85. package/dist/v3/JsonPretty/hooks/useError.d.ts.map +1 -0
  86. package/dist/v3/JsonPretty/type.d.ts +93 -0
  87. package/dist/v3/JsonPretty/type.d.ts.map +1 -0
  88. package/dist/v3/JsonPretty/utils/index.d.ts +10 -0
  89. package/dist/v3/JsonPretty/utils/index.d.ts.map +1 -0
  90. package/package.json +5 -5
  91. package/dev/components/AppInfo/index.vue +0 -36
  92. package/dev/components/AutoSizer/index.vue +0 -193
  93. package/dev/components/AutoSizer/index1.vue +0 -186
  94. package/dev/components/AutoSizer/utils.ts +0 -49
  95. package/dev/components/Button/index.vue +0 -34
  96. package/dev/components/CaptureScreen/index.vue +0 -62
  97. package/dev/components/Checkbox/index.vue +0 -40
  98. package/dev/components/CloseButton/index.vue +0 -26
  99. package/dev/components/Code/index.vue +0 -230
  100. package/dev/components/Connection/index.vue +0 -88
  101. package/dev/components/ConsoleList/Code.vue +0 -227
  102. package/dev/components/ConsoleList/ConsoleItem.vue +0 -207
  103. package/dev/components/ConsoleList/RunJSInput.vue +0 -237
  104. package/dev/components/ConsoleList/index.vue +0 -139
  105. package/dev/components/ConsoleList/staticTips.ts +0 -1145
  106. package/dev/components/DevTool/index.vue +0 -188
  107. package/dev/components/DevToolButton/index.vue +0 -210
  108. package/dev/components/DevToolTitle/index.vue +0 -21
  109. package/dev/components/DevToolWindow/index.vue +0 -1053
  110. package/dev/components/DeviceInfo/index.vue +0 -32
  111. package/dev/components/Empty/empty.png +0 -0
  112. package/dev/components/Empty/index.vue +0 -28
  113. package/dev/components/FilterInput/index.vue +0 -86
  114. package/dev/components/JsonPretty/components/Brackets/index.vue +0 -23
  115. package/dev/components/JsonPretty/components/Carets/index.vue +0 -59
  116. package/dev/components/JsonPretty/components/CheckController/index.vue +0 -125
  117. package/dev/components/JsonPretty/components/TreeNode/index.vue +0 -349
  118. package/dev/components/JsonPretty/hooks/useClipboard.ts +0 -21
  119. package/dev/components/JsonPretty/hooks/useError.ts +0 -21
  120. package/dev/components/JsonPretty/index.vue +0 -476
  121. package/dev/components/JsonPretty/type.ts +0 -125
  122. package/dev/components/JsonPretty/utils/index.ts +0 -172
  123. package/dev/components/NetworkList/NetworkDetail.vue +0 -194
  124. package/dev/components/NetworkList/NetworkItem.vue +0 -119
  125. package/dev/components/NetworkList/index.vue +0 -128
  126. package/dev/components/PiniaList/index.vue +0 -64
  127. package/dev/components/RouteList/index.vue +0 -121
  128. package/dev/components/RunJS/index.vue +0 -128
  129. package/dev/components/SettingList/index.vue +0 -222
  130. package/dev/components/SourceCode/index.vue +0 -231
  131. package/dev/components/StorageList/index.vue +0 -170
  132. package/dev/components/SystemInfo/index.vue +0 -34
  133. package/dev/components/Tabs/index.vue +0 -123
  134. package/dev/components/Tag/index.vue +0 -89
  135. package/dev/components/UniEvent/UniEventItem.vue +0 -126
  136. package/dev/components/UniEvent/index.vue +0 -98
  137. package/dev/components/UploadList/UploadDetail.vue +0 -204
  138. package/dev/components/UploadList/UploadItem.vue +0 -117
  139. package/dev/components/UploadList/index.vue +0 -117
  140. package/dev/components/VirtualList/index.vue +0 -112
  141. package/dev/components/VirtualListPro/AutoSize.vue +0 -43
  142. package/dev/components/VirtualListPro/index.vue +0 -238
  143. package/dev/components/VirtualListPro/readme.md +0 -40
  144. package/dev/components/VuexList/index.vue +0 -54
  145. package/dev/components/WebSocket/WebSocketItem.vue +0 -103
  146. package/dev/components/WebSocket/WebSocketList.vue +0 -173
  147. package/dev/components/WebSocket/index.vue +0 -124
  148. package/dev/components/WindowInfo/index.vue +0 -33
  149. package/dev/const.ts +0 -164
  150. package/dev/core.ts +0 -118
  151. package/dev/devConsole/index.ts +0 -350
  152. package/dev/devEvent/index.ts +0 -810
  153. package/dev/devEventBus/index.ts +0 -94
  154. package/dev/devIntercept/index.ts +0 -745
  155. package/dev/devRunJS/index.ts +0 -170
  156. package/dev/devStore/index.ts +0 -732
  157. package/dev/devToolInfo/index.ts +0 -26
  158. package/dev/plugins/uniDevTool/uniDevTool.d.ts.map +0 -1
  159. package/dev/plugins/uniDevTool/uniDevTool.js +0 -36
  160. package/dev/plugins/utils/index.js +0 -1
  161. package/dev/shims-uni.d.ts +0 -43
  162. package/dev/type.ts +0 -291
  163. package/dev/utils/array.ts +0 -15
  164. package/dev/utils/date.ts +0 -75
  165. package/dev/utils/file.ts +0 -121
  166. package/dev/utils/function.ts +0 -192
  167. package/dev/utils/index.d.ts +0 -6
  168. package/dev/utils/index.ts +0 -51
  169. package/dev/utils/ip.ts +0 -79
  170. package/dev/utils/language.ts +0 -77
  171. package/dev/utils/object.ts +0 -306
  172. package/dev/utils/page.ts +0 -13
  173. package/dev/utils/platform.ts +0 -14
  174. package/dev/utils/string.ts +0 -133
  175. package/dev/utils/utils.ts +0 -198
  176. /package/{dev → dist}/index.d.ts +0 -0
  177. /package/{dev → dist}/index.d.ts.map +0 -0
  178. /package/{dev → dist}/index.js +0 -0
  179. /package/{dev → dist}/plugins/uniGlobalComponents/uniGlobalComponents.d.ts +0 -0
  180. /package/{dev → dist}/plugins/uniGlobalComponents/uniGlobalComponents.d.ts.map +0 -0
  181. /package/{dev → dist}/plugins/uniGlobalComponents/uniGlobalComponents.js +0 -0
@@ -1,192 +0,0 @@
1
- type ThrottleOptions = {
2
- leading?: boolean;
3
- trailing?: boolean;
4
- };
5
-
6
- /**
7
- * 创建一个节流函数,在指定时间间隔内只执行一次原函数
8
- * @param func 需要节流的函数
9
- * @param wait 等待时间(毫秒)
10
- * @param options 配置选项
11
- * @param options.leading 是否在开始时立即执行
12
- * @param options.trailing 是否在延迟结束后执行最后一次调用
13
- * @returns 节流后的函数
14
- */
15
-
16
- export function throttle<T extends (...args: any[]) => any>(
17
- func: T,
18
- wait: number,
19
- options: ThrottleOptions = {},
20
- ): (...args: Parameters<T>) => ReturnType<T> | undefined {
21
- let timeout: NodeJS.Timeout | null = null;
22
- let lastArgs: Parameters<T> | null = null;
23
- let lastThis: any = null;
24
- let result: ReturnType<T> | undefined;
25
- let lastCallTime: number | null = null;
26
-
27
- const { leading = true, trailing = true } = options;
28
-
29
- const invokeFunc = (time: number) => {
30
- const args = lastArgs;
31
- const thisArg = lastThis;
32
- lastArgs = lastThis = null;
33
- lastCallTime = time;
34
- result = func.apply(thisArg, args!);
35
- return result;
36
- };
37
-
38
- const leadingEdge = (time: number) => {
39
- lastCallTime = time;
40
- timeout = null;
41
- return leading ? invokeFunc(time) : undefined;
42
- };
43
-
44
- const trailingEdge = (time: number) => {
45
- timeout = null;
46
- if (lastArgs && trailing) {
47
- return invokeFunc(time);
48
- }
49
- lastArgs = lastThis = null;
50
- return result;
51
- };
52
-
53
- const remainingWait = (time: number) => {
54
- if (lastCallTime === null) return wait;
55
- const timeSinceLastCall = time - lastCallTime;
56
- return wait - timeSinceLastCall;
57
- };
58
-
59
- const shouldInvoke = (time: number) => {
60
- if (lastCallTime === null) return true;
61
- const timeSinceLastCall = time - lastCallTime;
62
- return timeSinceLastCall >= wait || timeSinceLastCall < 0;
63
- };
64
-
65
- const timerExpired = () => {
66
- const time = Date.now();
67
- if (shouldInvoke(time)) {
68
- return trailingEdge(time);
69
- }
70
- timeout = setTimeout(timerExpired, remainingWait(time));
71
- return undefined;
72
- };
73
-
74
- const throttled = function (this: any, ...args: Parameters<T>) {
75
- const time = Date.now();
76
- const isInvoking = shouldInvoke(time);
77
-
78
- lastArgs = args;
79
- lastThis = this;
80
-
81
- if (isInvoking) {
82
- if (timeout === null) {
83
- return leadingEdge(time);
84
- }
85
- }
86
-
87
- if (timeout === null) {
88
- timeout = setTimeout(timerExpired, wait);
89
- }
90
-
91
- return result;
92
- };
93
-
94
- throttled.cancel = () => {
95
- if (timeout !== null) {
96
- clearTimeout(timeout);
97
- }
98
- lastCallTime = null;
99
- timeout = lastArgs = lastThis = null;
100
- };
101
-
102
- return throttled;
103
- }
104
-
105
- type DebouncedFunction<T extends (...args: any[]) => any> = ((
106
- ...args: Parameters<T>
107
- ) => ReturnType<T> | undefined) & {
108
- cancel: () => void;
109
- flush: () => ReturnType<T> | undefined;
110
- };
111
-
112
- /**
113
- * 创建一个防抖函数,该函数在最后一次调用后等待指定时间才执行。
114
- * @param func 需要防抖的函数
115
- * @param wait 等待时间(毫秒)
116
- * @param immediate 是否在第一次调用时立即执行
117
- * @returns 防抖后的函数
118
- */
119
- export function debounce<T extends (...args: any[]) => any>(
120
- func: T,
121
- wait: number,
122
- immediate: boolean = false,
123
- ): DebouncedFunction<T> {
124
- let timeout: ReturnType<typeof setTimeout> | null = null;
125
- let lastArgs: Parameters<T> | null = null;
126
- let lastThis: ThisParameterType<T> | null = null;
127
- let result: ReturnType<T> | undefined;
128
- let lastCallTime: number | null = null;
129
-
130
- const later = (): void => {
131
- const last = lastCallTime !== null ? Date.now() - lastCallTime : 0;
132
-
133
- if (last < wait && last >= 0) {
134
- timeout = setTimeout(later, wait - last);
135
- } else {
136
- timeout = null;
137
- if (!immediate) {
138
- if (lastArgs !== null && lastThis !== null) {
139
- result = func.apply(lastThis, lastArgs);
140
- lastArgs = lastThis = null;
141
- }
142
- }
143
- }
144
- };
145
-
146
- const debounced = function (
147
- this: ThisParameterType<T>,
148
- ...args: Parameters<T>
149
- ): ReturnType<T> | undefined {
150
- lastArgs = args;
151
- lastThis = this;
152
- lastCallTime = Date.now();
153
-
154
- const callNow = immediate && timeout === null;
155
-
156
- if (!timeout) {
157
- timeout = setTimeout(later, wait);
158
- }
159
-
160
- if (callNow) {
161
- result = func.apply(this, args);
162
- lastArgs = lastThis = null;
163
- }
164
-
165
- return result;
166
- };
167
-
168
- debounced.cancel = (): void => {
169
- if (timeout !== null) {
170
- clearTimeout(timeout);
171
- timeout = null;
172
- lastArgs = lastThis = null;
173
- lastCallTime = null;
174
- }
175
- };
176
-
177
- debounced.flush = (): ReturnType<T> | undefined => {
178
- if (timeout !== null) {
179
- clearTimeout(timeout);
180
- timeout = null;
181
- if (!immediate) {
182
- if (lastArgs !== null && lastThis !== null) {
183
- result = func.apply(lastThis, lastArgs);
184
- lastArgs = lastThis = null;
185
- }
186
- }
187
- }
188
- return result;
189
- };
190
-
191
- return debounced;
192
- }
@@ -1,6 +0,0 @@
1
- export declare function findInsertionIndex(lines: string[], condition: (p: string) => boolean): number;
2
- export declare function getContentType(filePath: string): string;
3
- export declare function getLocalIPs(): string[];
4
- export declare function hasImportOnLaunch(str: string): boolean;
5
- export declare function hasImportCurrentInstance(str: string): boolean;
6
- //# sourceMappingURL=index.d.ts.map
@@ -1,51 +0,0 @@
1
- export {
2
- isNil,
3
- isBoolean,
4
- isNumber,
5
- isObject,
6
- isArray,
7
- isFunction,
8
- isString,
9
- isNull,
10
- isSymbol,
11
- isUndefined,
12
- getValueType,
13
- transformValueToView,
14
- } from './language';
15
- export {
16
- setValueByPath,
17
- getValueByPath,
18
- calculateObjectSize,
19
- formatStorageSize,
20
- serializeCircular,
21
- parseValue,
22
- } from './object';
23
-
24
- export { throttle, debounce } from './function';
25
-
26
- export {
27
- getFilePath,
28
- saveTextFileH5,
29
- saveTextFileMicro,
30
- saveTxtFileApp,
31
- } from './file';
32
-
33
- export { getCurrentPagePath } from './page';
34
-
35
- export { getCurrentDate, formatDate, sleep } from './date';
36
-
37
- export {
38
- hightLight,
39
- escapeHTML,
40
- extractUrl,
41
- extractRowAndCol,
42
- parseStock,
43
- isMockWX,
44
- uniqueId,
45
- } from './string';
46
-
47
- export { getWifiIp, getDeviceMac, getLanIp, getMicroAppIp } from './ip';
48
-
49
- export { isAndroid, isH5, isWX } from './platform';
50
-
51
- export { chunk } from './array';
package/dev/utils/ip.ts DELETED
@@ -1,79 +0,0 @@
1
- export function getWifiIp() {
2
- // #ifdef APP-PLUS
3
- const manActivity: any = plus.android.runtimeMainActivity();
4
- const context: any = plus.android.importClass('android.content.Context');
5
- plus.android.importClass('android.net.wifi.WifiManager');
6
- plus.android.importClass('android.net.wifi.WifiInfo');
7
- plus.android.importClass('android.net.wifi.ScanResult');
8
- const wifiManger = manActivity.getSystemService(context.WIFI_SERVICE);
9
- const wifiInfo = wifiManger.getConnectionInfo();
10
- const ipAddress = wifiInfo.getIpAddress();
11
- const wifiIp =
12
- (ipAddress & 0xff) +
13
- '.' +
14
- ((ipAddress >> 8) & 0xff) +
15
- '.' +
16
- ((ipAddress >> 16) & 0xff) +
17
- '.' +
18
- ((ipAddress >> 24) & 0xff);
19
-
20
- return wifiIp;
21
-
22
- // #endif
23
- return '';
24
- }
25
-
26
- export function getLanIp() {
27
- // #ifdef APP-PLUS
28
- const manActivity: any = plus.android.runtimeMainActivity();
29
- const context: any = plus.android.importClass('android.content.Context');
30
- plus.android.importClass('android.net.ConnectivityManager');
31
- const lanManager = manActivity.getSystemService(context.CONNECTIVITY_SERVICE);
32
- const lanInfo = lanManager.getLinkProperties(lanManager.getActiveNetwork());
33
- const lanIpAddress = plus.android.invoke(lanInfo, 'getLinkAddress');
34
- const lanIpAddressStr = lanIpAddress?.toString();
35
- const lanIpAddressArr = lanIpAddressStr?.split(',');
36
- const lanIp = lanIpAddressArr?.[1]?.split('/')?.[0];
37
- return lanIp;
38
-
39
- // #endif
40
- return '';
41
- }
42
-
43
- export function getMicroAppIp() {
44
- // #ifdef MP-WEIXIN
45
- return new Promise((resolve) => {
46
- uni.getLocalIPAddress({
47
- success: (res) => {
48
- resolve(res.localip);
49
- },
50
- fail: (err) => {
51
- resolve('');
52
- },
53
- });
54
- });
55
- // #endif
56
-
57
- return Promise.resolve('');
58
- }
59
-
60
- export function getDeviceMac() {
61
- var deviceMac = '';
62
- var net: any = plus.android.importClass('java.net.NetworkInterface');
63
- var wl0 = net.getByName('wlan0');
64
- var macByte = wl0.getHardwareAddress();
65
- for (var i = 0; i < macByte.length; i++) {
66
- var tmp = '';
67
- var num = macByte[i];
68
- if (num < 0) {
69
- tmp = (255 + num + 1).toString(16);
70
- } else {
71
- tmp = num.toString(16);
72
- }
73
- if (tmp.length == 1) {
74
- tmp = '0' + tmp;
75
- }
76
- deviceMac += tmp;
77
- }
78
- // console.log(deviceMac);
79
- }
@@ -1,77 +0,0 @@
1
- import type { DevTool } from '../type';
2
- export function isNil(value: any): value is null | undefined {
3
- return value === null || value === undefined;
4
- }
5
-
6
- export function isBoolean(value: any): value is boolean {
7
- return typeof value === 'boolean';
8
- }
9
-
10
- export function isNumber(value: any): value is number {
11
- return typeof value === 'number' && !isNaN(value);
12
- }
13
-
14
- export function isObject(value: any): value is object {
15
- return typeof value === 'object' && value !== null;
16
- }
17
-
18
- export function isArray(value: any): value is any[] {
19
- return Array.isArray(value);
20
- }
21
-
22
- export function isString(value: any): value is string {
23
- return typeof value === 'string';
24
- }
25
-
26
- export function isNull(value: any): value is null {
27
- return value === null;
28
- }
29
-
30
- export function isUndefined(value: any): value is undefined {
31
- return value === undefined;
32
- }
33
-
34
- export function isSymbol(value: any): value is symbol {
35
- return typeof value === 'symbol';
36
- }
37
-
38
- export function isFunction(value: any): value is Function {
39
- return typeof value === 'function';
40
- }
41
-
42
- /**
43
- *
44
- *
45
- * @export
46
- * @param {*} value
47
- * @return {*} {DevTool.ValueType}
48
- */
49
- export function getValueType(value: any): DevTool.ValueType {
50
- if (isNull(value)) return 'null';
51
- if (isUndefined(value)) return 'undefined';
52
- if (isNumber(value)) return 'number';
53
- if (isString(value)) return 'string';
54
- if (isArray(value)) return 'array';
55
- if (isObject(value)) return 'object';
56
- if (isSymbol(value)) return 'symbol';
57
- return 'string';
58
- }
59
-
60
- /**
61
- * 将 console 入参转vue 可视值
62
- *
63
- * @export
64
- * @param {*} value
65
- * @return {*} {DevTool.ValueType}
66
- */
67
- export function transformValueToView(value: any): DevTool.ValueType {
68
- if (isNull(value)) return 'null';
69
- if (isUndefined(value)) return 'undefined';
70
- if (isString(value)) return 'string';
71
- if (isNumber(value)) return 'number';
72
- if (isBoolean(value)) return 'boolean';
73
- if (isSymbol(value)) return 'symbol';
74
- if (isArray(value)) return 'array';
75
- if (isObject(value)) return 'object';
76
- return 'string';
77
- }
@@ -1,306 +0,0 @@
1
- import { isBoolean, isNil, isObject, isString, isFunction } from './language';
2
-
3
- /**
4
- * 自定义set函数 - 安全地设置嵌套对象属性
5
- * @param obj 目标对象
6
- * @param path 属性路径数组
7
- * @param value 要设置的值
8
- */
9
- export function setValueByPath(obj: any, path: string, value: any) {
10
- if (obj == null || typeof path !== 'string') {
11
- return;
12
- }
13
-
14
- // 支持两种路径格式: "a.b.c" 或 "a[0].b"
15
- const segments = path
16
-
17
- .replace(/\[(\d+)\]/g, '.$1') // 将 a[0] 转换为 a.0
18
- .split('.')
19
- .filter((segment) => segment !== ''); // 过滤空段
20
-
21
- if (segments.length === 0) {
22
- return;
23
- }
24
-
25
- let current = obj;
26
- const lastIndex = segments.length - 1;
27
-
28
- for (let i = 0; i < lastIndex; i++) {
29
- const key = segments[i];
30
- // 如果路径不存在且不是最后一个属性,创建对象或数组
31
- if (!current[key]) {
32
- // 判断下一级是否为数字索引(数组)
33
- const nextKey = segments[i + 1];
34
- current[key] = /^\d+$/.test(nextKey) ? [] : {};
35
- }
36
- current = current[key];
37
- }
38
-
39
- // 设置最终值
40
- current[segments[lastIndex]] = value;
41
- }
42
-
43
- export function getValueByPath(obj: any, path: string, defaultValue?: any) {
44
- if (obj == null || typeof path !== 'string') {
45
- return defaultValue;
46
- }
47
-
48
- // 支持两种路径格式: "a.b.c" 或 "a[0].b"
49
- const segments = path
50
- .replace(/\[(\d+)\]/g, '.$1') // 将 a[0] 转换为 a.0
51
- .split('.')
52
- .filter((segment) => segment !== ''); // 过滤空段
53
-
54
- let current = obj;
55
- for (const segment of segments) {
56
- if (current == null) {
57
- return defaultValue;
58
- }
59
- current = current[segment];
60
- }
61
-
62
- return current !== undefined ? current : defaultValue;
63
- }
64
-
65
- /**
66
- * 计算对象在内存中的近似大小
67
- * @param obj 要计算大小的对象
68
- * @returns 对象的近似大小(以字节为单位)
69
- */
70
- export function calculateObjectSize(obj: any): number {
71
- obj = parseValue(obj);
72
- // 处理基本类型
73
- if (obj === null || obj === undefined) {
74
- return 0;
75
- }
76
-
77
- // 处理原始类型
78
- const type = typeof obj;
79
- if (type === 'boolean') {
80
- return 4; // 布尔值通常占4字节
81
- }
82
- if (type === 'number') {
83
- return 8; // JavaScript 数字是双精度浮点数(8字节)
84
- }
85
- if (type === 'string') {
86
- // 假设每个 UTF-16 字符占2字节
87
- return obj.length * 2;
88
- }
89
- if (type === 'symbol') {
90
- // 符号在内存中的大小通常与引用大小相同
91
- return 8;
92
- }
93
-
94
- // 处理日期对象
95
- if (obj instanceof Date) {
96
- return 8; // 日期内部表示为时间戳(8字节)
97
- }
98
-
99
- // 处理正则表达式
100
- if (obj instanceof RegExp) {
101
- return calculateObjectSize(obj.source) + calculateObjectSize(obj.flags);
102
- }
103
-
104
- // 处理数组和普通对象
105
- let totalSize = 0;
106
-
107
- // 对象头部信息(简化估算)
108
- totalSize += 24; // 假设对象头部占24字节
109
-
110
- if (Array.isArray(obj)) {
111
- // 数组的长度属性
112
- totalSize += 4;
113
-
114
- // 计算每个元素的大小
115
- for (const item of obj) {
116
- // 数组元素引用(假设每个引用占8字节)
117
- totalSize += 8;
118
- // 元素本身的大小
119
- totalSize += calculateObjectSize(item);
120
- }
121
- } else {
122
- // 计算对象每个属性的大小
123
- for (const key in obj) {
124
- if (obj?.hasOwnProperty?.(key)) {
125
- // 属性名的大小(假设每个字符占2字节)
126
- totalSize += key.length * 2;
127
- // 属性引用(假设每个引用占8字节)
128
- totalSize += 8;
129
- // 属性值的大小
130
- totalSize += calculateObjectSize(obj[key]);
131
- }
132
- }
133
- }
134
-
135
- return totalSize;
136
- }
137
-
138
- /**
139
- * 存储单位转换
140
- * @param bytes 字节数
141
- * @param options 转换选项
142
- * @returns 转换后的存储大小字符串
143
- */
144
- interface FormatStorageOptions {
145
- precision?: number; // 精度,默认为2
146
- useBinary?: boolean; // 是否使用二进制单位,默认为true
147
- includeUnit?: boolean; // 是否包含单位,默认为true
148
- }
149
-
150
- export function formatStorageSize(
151
- bytes: number,
152
- options: FormatStorageOptions = {},
153
- ): string {
154
- const { precision = 2, useBinary = true, includeUnit = true } = options;
155
-
156
- if (bytes === 0) {
157
- return includeUnit ? `0 Bytes` : `0`;
158
- }
159
-
160
- const units = useBinary
161
- ? ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']
162
- : ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
163
-
164
- const base = useBinary ? 1024 : 1000;
165
- let unitIndex = 0;
166
-
167
- while (bytes >= base && unitIndex < units.length - 1) {
168
- bytes /= base;
169
- unitIndex++;
170
- }
171
-
172
- const formattedSize = bytes.toFixed(precision);
173
- return includeUnit ? `${formattedSize} ${units[unitIndex]}` : formattedSize;
174
- }
175
-
176
- /**
177
- * 序列化包含循环引用的对象
178
- * @param {Object} obj - 要序列化的对象
179
- * @param {WeakMap} [visited] - 用于记录已处理的对象(内部递归使用)
180
- * @returns {string} - 序列化后的字符串
181
- */
182
- export function serializeCircular(
183
- obj: any,
184
- options: { maxDepth: number; visited: WeakMap<any, true> } = {
185
- maxDepth: 10,
186
- visited: new WeakMap(),
187
- },
188
- ): string {
189
- const { maxDepth, visited } = options;
190
-
191
- // 处理 null 和基本类型
192
- if (obj === null || typeof obj !== 'object') {
193
- return JSON.stringify(obj);
194
- }
195
-
196
- // 检测循环引用
197
- if (visited.has(obj)) {
198
- return '[Circular]';
199
- }
200
-
201
- // 记录当前对象已处理
202
- visited.set(obj, true);
203
-
204
- // 处理日期对象
205
- if (obj instanceof Date) {
206
- return `"${obj.toISOString()}"`;
207
- }
208
-
209
- // 处理正则表达式
210
- if (obj instanceof RegExp) {
211
- return `/^${obj.source}$/${obj.flags}`;
212
- }
213
-
214
- // 检查是否达到最大深度
215
- if (maxDepth <= 0) {
216
- return typeof obj === 'object' ? '{}' : '[]';
217
- }
218
-
219
- // 递归处理数组
220
- if (Array.isArray(obj)) {
221
- const serializedItems = obj.map((item) =>
222
- serializeCircular(item, { maxDepth: maxDepth - 1, visited }),
223
- );
224
- return `[${serializedItems.join(', ')}]`;
225
- }
226
-
227
- // 递归处理普通对象
228
- const keys = Object.keys(obj);
229
- const serializedProps = keys.map((key) => {
230
- const value = serializeCircular(obj[key], {
231
- maxDepth: maxDepth - 1,
232
- visited,
233
- });
234
- return `"${key}": ${value}`;
235
- });
236
-
237
- return `{${serializedProps.join(', ')}}`;
238
- }
239
-
240
- /**
241
- * 处理value
242
- * 基础类型数据直接返回value
243
- * 引用类型数据判断 value 是否存在循环引用的情况,存在则将循环引用的第二次赋值为 [Circular]
244
- * 最大处理 deep 层数
245
- *
246
- * @export
247
- * @param {*} value
248
- * @param {number} [deep=6]
249
- */
250
- export function parseValue(value: any, deep: number = 6) {
251
- const seen = new WeakMap<object, string[]>(); // 存储对象及其路径
252
-
253
- function process(value: any, currentDeep: number, path: string[] = []): any {
254
- if (isString(value)) {
255
- return `${value}`;
256
- }
257
-
258
- if (isBoolean(value)) {
259
- return `${value}`;
260
- }
261
-
262
- if (isFunction(value)) {
263
- return `f(...) { ... }`;
264
- }
265
-
266
- if (isNil(value)) {
267
- return `${value}`;
268
- }
269
-
270
- // 处理基本类型
271
- if (!isObject(value)) {
272
- return value;
273
- }
274
-
275
- // 检查是否达到最大深度
276
- if (currentDeep <= 0) {
277
- return '[MaxDepth]';
278
- }
279
-
280
- // 检查循环引用
281
- if (seen.has(value)) {
282
- const circularPath = seen.get(value)!.join('.');
283
- return `[Circular: ${circularPath}]`;
284
- }
285
-
286
- // 标记当前对象为已访问,并记录路径
287
- seen.set(value, [...path]);
288
-
289
- // 处理数组
290
- if (Array.isArray(value)) {
291
- return value.map((item, index) =>
292
- process(item, currentDeep - 1, [...path, String(index)]),
293
- );
294
- }
295
-
296
- // 处理对象
297
- const result: Record<string, any> = {};
298
- for (const [key, val] of Object.entries(value)) {
299
- result[key] = process(val, currentDeep - 1, [...path, key]);
300
- }
301
-
302
- return result;
303
- }
304
-
305
- return process(value, deep);
306
- }