hifun-tools 1.3.14 → 1.3.16

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.
@@ -1,3 +1,4 @@
1
+ import { isDomainMatch, toStandardUrl } from "./utils";
1
2
  import { AesDecrypt, AesEncrypt } from "./ende";
2
3
  type TenantConfig = {
3
4
  PUBLIC_TITLE: string;
@@ -32,4 +33,4 @@ declare class InitCls {
32
33
  AesDecrypt: typeof AesDecrypt;
33
34
  }
34
35
  declare const HF: InitCls;
35
- export { HF };
36
+ export { HF, isDomainMatch, toStandardUrl, AesEncrypt, AesDecrypt };
@@ -155,4 +155,4 @@ class InitCls {
155
155
  AesDecrypt = AesDecrypt;
156
156
  }
157
157
  const HF = new InitCls();
158
- export { HF };
158
+ export { HF, isDomainMatch, toStandardUrl, AesEncrypt, AesDecrypt };
@@ -18,8 +18,10 @@ export async function getOptimalDecodedString(encodedArray) {
18
18
  throw new Error("输入数组为空或无效");
19
19
  const hostname = window.location.hostname;
20
20
  const isIp = isIPv4(hostname);
21
- // 修正:Base64 解码后再过滤
22
- const decodedList = encodedArray.filter(Boolean);
21
+ // 关键增强:先 trim 再过滤
22
+ const decodedList = encodedArray
23
+ .filter(Boolean)
24
+ .map((v) => v.trim());
23
25
  const ipList = decodedList.filter((v) => isIPv4(v));
24
26
  const domainList = decodedList.filter((v) => !isIPv4(v));
25
27
  const getOptimal = (arr) => new Promise((resolve) => {
@@ -28,6 +30,7 @@ export async function getOptimalDecodedString(encodedArray) {
28
30
  return;
29
31
  }
30
32
  const currentProtocol = window.location.protocol;
33
+ // 过滤协议
31
34
  const filteredArr = arr.filter((url) => url.startsWith("http") ? url.startsWith(currentProtocol) : true);
32
35
  const targetArr = filteredArr.length ? filteredArr : arr;
33
36
  if (targetArr.length === 1)
@@ -86,6 +89,7 @@ const MULTI_LEVEL_TLDS = new Set([
86
89
  */
87
90
  export function extractRootDomain(url) {
88
91
  try {
92
+ url = url.trim(); // ✨ 增加
89
93
  if (!/^https?:\/\//i.test(url)) {
90
94
  url = "http://" + url;
91
95
  }
@@ -94,13 +98,11 @@ export function extractRootDomain(url) {
94
98
  if (parts.length < 2)
95
99
  return hostname;
96
100
  const last2 = parts.slice(-2).join(".");
97
- // 匹配多级 TLD(如 example.com.cn → example.com.cn)
98
101
  if (MULTI_LEVEL_TLDS.has(last2)) {
99
102
  if (parts.length >= 3) {
100
103
  return parts.slice(-3).join(".");
101
104
  }
102
105
  }
103
- // 通用规则:主域 = 最后两段
104
106
  return last2;
105
107
  }
106
108
  catch (e) {
@@ -117,16 +119,15 @@ export function isDomainMatch(list, target) {
117
119
  }
118
120
  export function toStandardUrl(input) {
119
121
  try {
122
+ input = input.trim(); // ✨ 增加
120
123
  let protocol = window?.location?.protocol || "https:";
121
- // 自动补协议
122
124
  if (!/^https?:\/\//i.test(input)) {
123
125
  input = protocol + "//" + input;
124
126
  }
125
127
  const url = new URL(input);
126
- // 输出 protocol://hostname
127
128
  return `${url.protocol}//${url.hostname}`;
128
129
  }
129
130
  catch (e) {
130
- return input; // 当成普通字符串返回
131
+ return input;
131
132
  }
132
133
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hifun-tools",
3
- "version": "1.3.14",
3
+ "version": "1.3.16",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",