add isAllchar func
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user