summaryrefslogtreecommitdiff
path: root/cli/js/url.ts
diff options
context:
space:
mode:
authorSven Nicolai Viig <sven.viig@gmail.com>2019-10-31 19:55:54 +0100
committerRy Dahl <ry@tinyclouds.org>2019-10-31 14:55:54 -0400
commitd7a5aed5114f3ffd27221ae97bc57f453410427e (patch)
tree7f7a9fc3e14a7597efe2777ba35889adae01943b /cli/js/url.ts
parent4f8c9369744bfa4b1223cec916cb0e5b261831dc (diff)
Adds custom inspect method for URL (#3241)
Diffstat (limited to 'cli/js/url.ts')
-rw-r--r--cli/js/url.ts21
1 files changed, 21 insertions, 0 deletions
diff --git a/cli/js/url.ts b/cli/js/url.ts
index f22198da4..7b06fd64c 100644
--- a/cli/js/url.ts
+++ b/cli/js/url.ts
@@ -3,6 +3,7 @@ import * as urlSearchParams from "./url_search_params.ts";
import * as domTypes from "./dom_types.ts";
import { getRandomValues } from "./get_random_values.ts";
import { window } from "./window.ts";
+import { customInspect } from "./console.ts";
interface URLParts {
protocol: string;
@@ -144,6 +145,26 @@ export class URL {
private _parts: URLParts;
private _searchParams!: urlSearchParams.URLSearchParams;
+ [customInspect](): string {
+ const keys = [
+ "href",
+ "origin",
+ "protocol",
+ "username",
+ "password",
+ "host",
+ "hostname",
+ "port",
+ "pathname",
+ "hash",
+ "search"
+ ];
+ const objectString = keys
+ .map((key: string) => `${key}: "${this[key] || ""}"`)
+ .join(", ");
+ return `URL { ${objectString} }`;
+ }
+
private _updateSearchParams(): void {
const searchParams = new urlSearchParams.URLSearchParams(this.search);