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