import * as UrlLib from "https://deno.land/std/node/url.ts";
const url = "https://www.google.com"
const purl = UrlLib.parse(url)
console.log(`URL: ${purl.protocol}//${purl.host}`)
输出:
URL: https://google.com
Aside from using the ECMA script's native URL class, as illustrated by jsejcksn's answer, you can also use url library from the /std/node compatibility module as follows:
import * as UrlLib from "https://deno.land/std/node/url.ts";
const url = "https://www.google.com"
const purl = UrlLib.parse(url)
console.log(`URL: ${purl.protocol}//${purl.host}`)
发布评论
评论(2)
不需要外部模块来解析 Deno 中的 URL。
URL
类可用作全局的,就像在浏览器中一样:No external module is needed to parse URLs in Deno. The
URL
class is available as a global, just like in your browser:除了使用 ECMA 脚本的本机 URL 类,如图所示通过 jsejcksn 的回答,您还可以使用 url 库来自 /std/node 兼容模块如下:
输出:
Aside from using the ECMA script's native URL class, as illustrated by jsejcksn's answer, you can also use url library from the /std/node compatibility module as follows:
Output: