URL.canParse(input[, base])


  • input <string> 要解析的绝对或相对输入 URL。如果 input 是相对的,则需要 base。如果 input 是绝对的,则忽略 base。如果 input 不是字符串,则会先进行 转换为字符串
  • base <string> 如果 input 不是绝对路径,则用作解析的基础 URL。如果 base 不是字符串,则首先转为 转换为字符串
  • 返回:<boolean>

检查相对于 baseinput 是否可以解析为 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