MCPcopy Index your code
hub / github.com/NobyDa/Script / evalRules

Function evalRules

Rule-Storage/Rule-Storage.js:82–100  ·  view source on GitHub ↗
(host_name, rule_list)

Source from the content-addressed store, hash-verified

80}
81
82function evalRules(host_name, rule_list) {
83 const host_suffix = host_name.split('.').reverse();
84 rule_list = typeof rule_list == 'object' ? rule_list : formatRules(rule_list, 1);
85 for (const i in rule_list) {
86 if (rule_list[i].startsWith('.') && !rule_list[i].endsWith('.')) {
87 const rule_host_suffix = rule_list[i].split('.').reverse().filter((v) => v);
88 if (rule_host_suffix.filter((v, i) => host_suffix[i] === v).length === rule_host_suffix.length) {
89 return true
90 }
91 } else if (rule_list[i].startsWith('.') && rule_list[i].endsWith('.')) {
92 if (host_name.includes(rule_list[i].slice(1, -1))) {
93 return true
94 }
95 } else if (rule_list[i] === host_name) {
96 return true
97 }
98 }
99 return false
100}
101
102function formatRules(list, type) {
103 return (list || '').replace(/\r|\ |(\/\/|#|;).*/g, '').split('\n').map((v) => {

Callers 1

Rule-Storage.jsFile · 0.85

Calls 1

formatRulesFunction · 0.85

Tested by

no test coverage detected