URL.canParse(input[, base])
-
input<string> 要解析的绝对或相对的输入网址。如果input是相对的,则需要base。如果input是绝对的,则忽略base。如果input不是字符串,则首先是 转换为字符串。¥
input<string> The absolute or relative input URL to parse. Ifinputis relative, thenbaseis required. Ifinputis absolute, thebaseis ignored. Ifinputis not a string, it is converted to a string first. -
base<string> 如果input不是绝对的,则为要解析的基本网址。如果base不是字符串,则首先是 转换为字符串。¥
base<string> The base URL to resolve against if theinputis not absolute. Ifbaseis not a string, it is converted to a string first. -
返回:<boolean>
¥Returns: <boolean>
检查相对于 base 的 input 是否可以解析为 URL。
¥Checks if an input relative to the base can be parsed to a URL.
const isValid = URL.canParse('/foo', 'https://example.org/'); // true
const isNotValid = URL.canParse('/foo'); // false