diff options
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/url.ts | 21 | ||||
-rw-r--r-- | cli/js/url_test.ts | 8 |
2 files changed, 29 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); diff --git a/cli/js/url_test.ts b/cli/js/url_test.ts index 07a8028ce..23f9f5f4b 100644 --- a/cli/js/url_test.ts +++ b/cli/js/url_test.ts @@ -179,3 +179,11 @@ test(function sortingNonExistentParamRemovesQuestionMarkFromURL(): void { assertEquals(url.href, "http://example.com/"); assertEquals(url.search, ""); }); + +test(function customInspectFunction(): void { + const url = new URL("http://example.com/?"); + assertEquals( + Deno.inspect(url), + 'URL { href: "http://example.com/?", origin: "http://example.com", protocol: "http:", username: "", password: "", host: "example.com", hostname: "example.com", port: "", pathname: "/", hash: "", search: "?" }' + ); +}); |