@bhsd/common 0.6.0 → 0.6.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.
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ declare global {
8
8
  */
9
9
  export declare const rawurldecode: (str: string) => string;
10
10
  /**
11
- * 解码标题
11
+ * 解码标题中的HTML实体和URL编码
12
12
  * @param title 标题
13
13
  */
14
14
  export declare const normalizeTitle: (title: string) => string;
package/dist/index.js CHANGED
@@ -30,18 +30,18 @@ __export(src_exports, {
30
30
  });
31
31
  module.exports = __toCommonJS(src_exports);
32
32
  const CDN = "https://testingcf.jsdelivr.net";
33
- let span;
33
+ let textarea;
34
34
  if (typeof document === "object") {
35
- span = document.createElement("span");
35
+ textarea = document.createElement("textarea");
36
36
  }
37
+ const decodeHTML = (str) => {
38
+ textarea.innerHTML = str;
39
+ return textarea.value;
40
+ };
37
41
  const rawurldecode = (str) => decodeURIComponent(str.replace(/%(?![\da-f]{2})/giu, "%25"));
38
42
  const normalizeTitle = (title) => {
39
43
  const decoded = rawurldecode(title);
40
- if (/[<>[\]|{}]/u.test(decoded)) {
41
- return decoded;
42
- }
43
- span.innerHTML = decoded;
44
- return span.textContent;
44
+ return /[<>[\]|{}]/u.test(decoded) ? decoded : decodeHTML(decoded);
45
45
  };
46
46
  const numToHex = (d) => Math.round(d * 255).toString(16).padStart(2, "0");
47
47
  const splitColors = (str, hsl = true) => {
@@ -54,7 +54,7 @@ const splitColors = (str, hsl = true) => {
54
54
  pieces.push([str.slice(lastIndex, index), lastIndex, index, false]);
55
55
  }
56
56
  ({ lastIndex } = re);
57
- pieces.push([mt[2], index, lastIndex, true]);
57
+ pieces.push([mt[2], index, lastIndex, str.charAt(index - 1) !== "&" || !/^#\d+$/u.test(mt[2])]);
58
58
  mt = re.exec(str);
59
59
  }
60
60
  if (str.length > lastIndex) {
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) => {
@@ -23,7 +23,7 @@ const splitColors = (str, hsl = true) => {
23
23
  pieces.push([str.slice(lastIndex, index), lastIndex, index, false]);
24
24
  }
25
25
  ({ lastIndex } = re);
26
- pieces.push([mt[2], index, lastIndex, true]);
26
+ pieces.push([mt[2], index, lastIndex, str.charAt(index - 1) !== "&" || !/^#\d+$/u.test(mt[2])]);
27
27
  mt = re.exec(str);
28
28
  }
29
29
  if (str.length > lastIndex) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bhsd/common",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "license": "MIT",
5
5
  "author": "Bhsd",
6
6
  "files": [