[英]Find rules that matches the URL
I have a set of URL rules in the form of array.我有一套数组形式的URL规则。
const rules = [
{"page":"url","containsIgnoreCase":["google.com/something.html"]} ,
{"page":"query","equals":["testing=true","tt="]} ,
{"page":"url","containsIgnoreCase":["www.netflix.com/mx/products.html"]} ,
{"page":"url","containsIgnoreCase":["www.google.com/products/premiere.html","www.google.com/products/premiere-rush.html"]} ,
{"page":"url","containsIgnoreCase":["test=testing"]} ,
{"page":"url","containsIgnoreCase":["facebook.com/free-trial-download.html"]} ,
{
"and":[
{
"equals":["www.google.com"],
"page":"domain"
},
{
"equals":["/fr/products.html/","/fr/products.html"],
"page":"path"
}
]
},
{"and":[{"contains":["https://www.google.com/uk/","https://www.google.com/de/"],"page":"url"},{"page":"path","equalsIgnoreCase":["/uk/","/de/"]}]},
{"or":[
{
"and":[
{
"equals":["www.google.com"],
"page":"domain"
},
{
"equals":["/resources/rlmkt.html/","/resources/rlmkt.html"],
"page":"path"
}
]
},
{
"page":"url",
"containsIgnoreCase":["https://www.netflix.com/resources/rlit.html","https://www.netflix.com/resources/indht.html"]
}
]
} ,
]; ];
I need to write a function, that accepts the url and returns all the rules that matches the URL given.我需要编写一个 function,它接受 url 并返回与给定的 URL 匹配的所有规则。
For ex:例如:
input = "https://google.com/something.html"输入 = "https://google.com/something.html"
output = [{"page":"url","containsIgnoreCase":["google.com/something.html"]}] output = [{"page":"url","containsIgnoreCase":["google.com/something.html"]}]
For ex: input = "https://google.com/something.html" output = [{"page":"url","containsIgnoreCase":["google.com/something.html"]}]
例如:输入 = "https://google.com/something.html" output = [{"page":"url","containsIgnoreCase":["google.com/something.html"]}]
to get above output, use URL要超过 output,请使用URL
const url = new URL('https://google.com/something.html') const containsIgnoreCase = url.hostname + url.pathname console.log(containsIgnoreCase)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.