vite-uni-dev-tool 0.0.3 → 0.0.5

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.
@@ -0,0 +1,14 @@
1
+ export function isH5(): boolean {
2
+ return process.env.UNI_PLATFORM === 'h5';
3
+ }
4
+
5
+ export function isWX() {
6
+ return process.env.UNI_PLATFORM === 'mp-weixin';
7
+ }
8
+
9
+ export function isAndroid() {
10
+ return (
11
+ process.env.UNI_PLATFORM === 'app' ||
12
+ process.env.UNI_PLATFORM === 'app-plus'
13
+ );
14
+ }
@@ -13,11 +13,109 @@ export function hightLight(str: string = '', search: string = '') {
13
13
  // 转义特殊字符,确保正则表达式安全
14
14
  const escapedSearch = search.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
15
15
  const regex = new RegExp(escapedSearch, 'g');
16
-
16
+
17
17
  const html = str.replace(
18
18
  regex,
19
- `<span style="color:#fff; background-color: var(--dev-tool-main-color);">${search}</span>`
19
+ `<span style="color:#fff; background-color: var(--dev-tool-main-color);">${search}</span>`,
20
20
  );
21
-
21
+
22
22
  return html;
23
- }
23
+ }
24
+
25
+ export function escapeHTML(unsafe: string) {
26
+ if (!unsafe) return '';
27
+
28
+ const escapeMap: Record<string, string> = {
29
+ '&': '&amp;',
30
+ '"': '&quot;',
31
+ "'": '&#39;',
32
+ '>': '&gt;',
33
+ '<': '&lt;',
34
+ '=': '&#61;',
35
+ '+': '&#43;',
36
+ '-': '&#45;',
37
+ '(': '&#40;',
38
+ ')': '&#41;',
39
+ '[': '&#91;',
40
+ ']': '&#93;',
41
+ '{': '&#123;',
42
+ '}': '&#125;',
43
+ '.': '&#46;',
44
+ '?': '&#63;',
45
+ '/': '&#47;',
46
+ ':': '&#58;',
47
+ };
48
+
49
+ return unsafe.replace(
50
+ /[&"'><=+\-().?\/:[\]{}]/g,
51
+ (char) => escapeMap[char] || char,
52
+ );
53
+ }
54
+
55
+ const urlPattern = /https?:\/\/[^\s/$.?#](?:(?!\s|\)).)*/g;
56
+ /**
57
+ * 在字符串中获取url
58
+ *
59
+ * @export
60
+ * @param {string} text
61
+ * @return {*}
62
+ */
63
+ export function extractUrl(text: string) {
64
+ const match = text.match(urlPattern);
65
+ return match ? match[0] : '';
66
+ }
67
+
68
+ const rowAndColPattern = /:(\d+)(?::(\d+))?\)?$/;
69
+ /**
70
+ * 获取url 中末尾的行号和列号
71
+ *
72
+ * @export
73
+ * @param {string} url
74
+ * @return {*}
75
+ */
76
+ export function extractRowAndCol(url: string) {
77
+ const match = url.match(rowAndColPattern);
78
+ if (match) {
79
+ const lineNumber = match[1];
80
+ const columnNumber = match[2];
81
+ return {
82
+ row: parseInt(lineNumber) - 1,
83
+ col: parseInt(columnNumber) - 1,
84
+ };
85
+ }
86
+
87
+ return {
88
+ row: -1,
89
+ col: -1,
90
+ };
91
+ }
92
+
93
+ // at pages/index/index.js:46
94
+ // at pages/index/index.js:46:10
95
+ // at handleClick (http://localhost:8080/pages/main.js:123:4)
96
+ // at http://example.com/app.bundle.js:5:2
97
+ // at init (lib/utils.js:10)
98
+ const stockReg =
99
+ /at\s+(?:([^(]+)\s+\()?((?:[^:\/\s]+(?:\/[^:\/\s]+)*\.[^:\/\s]+)|(?:[^:]+:\/\/[^:\/\s]+(?::\d+)?(?:\/[^:\s]*)*)):(\d+)(?::(\d+))?(?:\s*\)?)?$/;
100
+
101
+ /**
102
+ * 解析栈信息
103
+ *
104
+ * @export
105
+ * @param {string} stock
106
+ * @return {*}
107
+ */
108
+ export function parseStock(stock: string) {
109
+ const match = stock.match(stockReg);
110
+ return {
111
+ info: match?.[1] ?? '',
112
+ path: match?.[2] ?? '',
113
+ row: match?.[3] ? parseInt(match?.[3]) - 1 : -1,
114
+ col: match?.[4] ? parseInt(match?.[4]) - 1 : -1,
115
+ };
116
+ }
117
+
118
+ const mockWXReg = /https?:\/\/usr/;
119
+ export function isMockWX(stock: string) {
120
+ return mockWXReg.test(stock);
121
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-uni-dev-tool",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "vite-uni-dev-tool, debug, uni-app, 一处编写,到处调试",
5
5
  "keywords": [
6
6
  "vite",