add isAllchar func

This commit is contained in:
Gabe Yuan
2023-09-07 10:20:08 +08:00
parent 08e14ae11c
commit da13f5e218
2 changed files with 20 additions and 9 deletions

View File

@@ -7,6 +7,7 @@ import {
} from "./storage"; } from "./storage";
import { apiFetchRules } from "../apis"; import { apiFetchRules } from "../apis";
import { checkRules } from "./rules"; import { checkRules } from "./rules";
import { isAllchar } from "./utils";
/** /**
* 同步订阅规则 * 同步订阅规则
@@ -16,7 +17,7 @@ import { checkRules } from "./rules";
export const syncSubRules = async (url, isBg = false) => { export const syncSubRules = async (url, isBg = false) => {
const res = await apiFetchRules(url, isBg); const res = await apiFetchRules(url, isBg);
const rules = checkRules(res).filter( const rules = checkRules(res).filter(
(rule) => rule.pattern.replaceAll(GLOBAL_KEY, "") !== "" ({ pattern }) => !isAllchar(pattern, GLOBAL_KEY)
); );
if (rules.length > 0) { if (rules.length > 0) {
await setSubRules(url, rules); await setSubRules(url, rules);

View File

@@ -57,6 +57,23 @@ export const debounce = (func, delay = 200) => {
}; };
}; };
/**
* 判断字符串全是某个字符
* @param {*} s
* @param {*} c
* @param {*} i
* @returns
*/
export const isAllchar = (s, c, i = 0) => {
while (i < s.length) {
if (s[i] !== c) {
return false;
}
i++;
}
return true;
};
/** /**
* 字符串通配符(*)匹配 * 字符串通配符(*)匹配
* @param {*} s * @param {*} s
@@ -91,14 +108,7 @@ export const isMatch = (s, p) => {
return true; return true;
} }
while (pIndex < p.length) { return isAllchar(p, "*", pIndex);
if (p[pIndex] !== "*") {
return false;
}
pIndex++;
}
return true;
}; };
/** /**