@bhsd/common 0.6.1 → 0.6.3

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/dist/index.d.ts CHANGED
@@ -2,13 +2,18 @@ export declare const CDN = "https://testingcf.jsdelivr.net";
2
2
  declare global {
3
3
  const define: unknown;
4
4
  }
5
+ /**
6
+ * 解码HTML实体
7
+ * @param str 要解码的字符串
8
+ */
9
+ export declare const decodeHTML: (str: string) => string;
5
10
  /**
6
11
  * PHP的`rawurldecode`函数的JavaScript实现
7
12
  * @param str 要解码的字符串
8
13
  */
9
14
  export declare const rawurldecode: (str: string) => string;
10
15
  /**
11
- * 解码标题
16
+ * 解码标题中的HTML实体和URL编码
12
17
  * @param title 标题
13
18
  */
14
19
  export declare const normalizeTitle: (title: string) => string;
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ var src_exports = {};
20
20
  __export(src_exports, {
21
21
  CDN: () => CDN,
22
22
  compareVersion: () => compareVersion,
23
+ decodeHTML: () => decodeHTML,
23
24
  getObject: () => getObject,
24
25
  loadScript: () => loadScript,
25
26
  normalizeTitle: () => normalizeTitle,
@@ -30,18 +31,18 @@ __export(src_exports, {
30
31
  });
31
32
  module.exports = __toCommonJS(src_exports);
32
33
  const CDN = "https://testingcf.jsdelivr.net";
33
- let span;
34
+ let textarea;
34
35
  if (typeof document === "object") {
35
- span = document.createElement("span");
36
+ textarea = document.createElement("textarea");
36
37
  }
38
+ const decodeHTML = (str) => {
39
+ textarea.innerHTML = str;
40
+ return textarea.value;
41
+ };
37
42
  const rawurldecode = (str) => decodeURIComponent(str.replace(/%(?![\da-f]{2})/giu, "%25"));
38
43
  const normalizeTitle = (title) => {
39
44
  const decoded = rawurldecode(title);
40
- if (/[<>[\]|{}]/u.test(decoded)) {
41
- return decoded;
42
- }
43
- span.innerHTML = decoded;
44
- return span.textContent;
45
+ return /[<>[\]|{}]/u.test(decoded) ? decoded : decodeHTML(decoded);
45
46
  };
46
47
  const numToHex = (d) => Math.round(d * 255).toString(16).padStart(2, "0");
47
48
  const splitColors = (str, hsl = true) => {
package/dist/index.mjs CHANGED
@@ -1,16 +1,16 @@
1
1
  const CDN = "https://testingcf.jsdelivr.net";
2
- let span;
2
+ let textarea;
3
3
  if (typeof document === "object") {
4
- span = document.createElement("span");
4
+ textarea = document.createElement("textarea");
5
5
  }
6
+ const decodeHTML = (str) => {
7
+ textarea.innerHTML = str;
8
+ return textarea.value;
9
+ };
6
10
  const rawurldecode = (str) => decodeURIComponent(str.replace(/%(?![\da-f]{2})/giu, "%25"));
7
11
  const normalizeTitle = (title) => {
8
12
  const decoded = rawurldecode(title);
9
- if (/[<>[\]|{}]/u.test(decoded)) {
10
- return decoded;
11
- }
12
- span.innerHTML = decoded;
13
- return span.textContent;
13
+ return /[<>[\]|{}]/u.test(decoded) ? decoded : decodeHTML(decoded);
14
14
  };
15
15
  const numToHex = (d) => Math.round(d * 255).toString(16).padStart(2, "0");
16
16
  const splitColors = (str, hsl = true) => {
@@ -67,6 +67,7 @@ const compareVersion = (version, baseVersion) => {
67
67
  export {
68
68
  CDN,
69
69
  compareVersion,
70
+ decodeHTML,
70
71
  getObject,
71
72
  loadScript,
72
73
  normalizeTitle,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bhsd/common",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "license": "MIT",
5
5
  "author": "Bhsd",
6
6
  "files": [