urlPattern.test(input[, baseURL])


输入可以是字符串,也可以是提供单独 URL 部分的对象。对象成员可以是 protocolusernamepasswordhostnameportpathnamesearchhashbaseURL 中的任何一个。

【Input can be a string or an object providing the individual URL parts. The object members can be any of protocol, username, password, hostname, port, pathname, search, hash or baseURL.】

如果未指定 baseURL,它将默认为 undefined

【If baseURL is not specified, it will default to undefined.】

返回一个布尔值,指示输入是否与当前模式匹配。

【Returns a boolean indicating if the input matches the current pattern.】

const myPattern = new URLPattern('https://nodejs.cn/docs/latest/api/*.html');
console.log(myPattern.test('https://nodejs.cn/docs/latest/api/dns.html'));
// Prints: true