chanjs 2.0.14 → 2.0.15

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.
package/global/global.js CHANGED
@@ -2,12 +2,7 @@ import { pathToFileURL, fileURLToPath } from "url";
2
2
  import path from "path";
3
3
  const ROOT_PATH = process.cwd();
4
4
  const APP_PATH = path.join(ROOT_PATH, "app");
5
- const __filename = fileURLToPath(import.meta.url);
6
- const __dirname = path.dirname(__filename);
7
-
8
5
  const globals = {
9
- __dirname,
10
- __filename,
11
6
  ROOT_PATH,
12
7
  APP_PATH,
13
8
  CONFIG_PATH: path.join(ROOT_PATH, "config"),
package/helper/html.js CHANGED
@@ -1,5 +1,25 @@
1
1
  /**
2
- * 处理最常用的HTML特殊字符实体
2
+ * 处理最常用的HTML特殊字符实体 - 编码
3
+ * @param {string} str - 需要编码的字符串
4
+ * @returns {string} 编码后的字符串
5
+ */
6
+ export const htmlEncode = (str) => {
7
+ // 非字符串直接返回,避免报错
8
+ if (typeof str !== 'string') return str;
9
+
10
+ // 一次性替换所有特殊字符,减少函数调用
11
+ return str.replace(/[&<>"' ]/g, match => ({
12
+ '&': '&amp;',
13
+ '<': '&lt;',
14
+ '>': '&gt;',
15
+ '"': '&quot;',
16
+ "'": '&#39;',
17
+ ' ': '&nbsp;'
18
+ }[match]));
19
+ };
20
+
21
+ /**
22
+ * 处理最常用的HTML特殊字符实体 - 解码
3
23
  * @param {string} str - 需要解码的字符串
4
24
  * @returns {string} 解码后的字符串
5
25
  */
@@ -16,4 +36,4 @@ export const htmlDecode = (str) => {
16
36
  '&#39;': "'",
17
37
  '&quot;': '"'
18
38
  }[match]));
19
- }
39
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "chanjs",
4
- "version": "2.0.14",
4
+ "version": "2.0.15",
5
5
  "description": "chanjs基于express5 纯js研发的轻量级mvc框架。",
6
6
  "main": "index.js",
7
7
  "module": "index.js",