From 9b1c19d214dce16c0833a33dd78cf76ccda27f34 Mon Sep 17 00:00:00 2001 From: Hari Sivaramakrishnan Date: Fri, 13 Jul 2018 13:02:09 -0700 Subject: [PATCH] [url-parse] Export URL definition in url-parse (#27125) * Export URL in url-parse * Add to definitions by list --- types/url-parse/index.d.ts | 43 ++++++++++++++++-------------- types/url-parse/url-parse-tests.ts | 8 +++--- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/types/url-parse/index.d.ts b/types/url-parse/index.d.ts index ce8f3647c2..6aed768de9 100644 --- a/types/url-parse/index.d.ts +++ b/types/url-parse/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for url-parse 1.1 // Project: https://github.com/unshiftio/url-parse // Definitions by: Pavlo Chernenko +// Hari Sivaramakrishnan // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 @@ -8,28 +9,30 @@ import URLSearchParams = require("url-search-params"); type UrlQueryParamsParser = (url: string) => string; -declare class URL { - readonly auth: string; - readonly hash: string; - readonly host: string; - readonly hostname: string; - readonly href: string; - readonly origin: string; - readonly password: string; - readonly pathname: string; - readonly port: string; - readonly protocol: string; - query: { [key: string]: string | undefined }; - readonly search: string; - set(property: string, value: string | object | number | undefined): URL; - readonly slashes: boolean; - readonly username: string; - readonly searchParams: URLSearchParams; - toString(): string; +declare namespace parse { + interface URL { + readonly auth: string; + readonly hash: string; + readonly host: string; + readonly hostname: string; + readonly href: string; + readonly origin: string; + readonly password: string; + readonly pathname: string; + readonly port: string; + readonly protocol: string; + query: { [key: string]: string | undefined }; + readonly search: string; + set(property: string, value: string | object | number | undefined): URL; + readonly slashes: boolean; + readonly username: string; + readonly searchParams: URLSearchParams; + toString(): string; + } } -type ParseFunctionNodeType = (url: string, parseQueryString?: boolean, slashesDenoteHost?: boolean) => URL; -type ParseFunctionType = (url: string, baseURL?: object | string, parser?: boolean | UrlQueryParamsParser) => URL; +type ParseFunctionNodeType = (url: string, parseQueryString?: boolean, slashesDenoteHost?: boolean) => parse.URL; +type ParseFunctionType = (url: string, baseURL?: object | string, parser?: boolean | UrlQueryParamsParser) => parse.URL; interface Protocol { slashes: boolean; diff --git a/types/url-parse/url-parse-tests.ts b/types/url-parse/url-parse-tests.ts index 48b2fa016d..61dc650ee1 100644 --- a/types/url-parse/url-parse-tests.ts +++ b/types/url-parse/url-parse-tests.ts @@ -1,10 +1,10 @@ import parse = require("url-parse"); const url1 = new URL("foo/bar", "https://github.com/"); -const url2 = parse("https://github.com/foo/bar?baz=true"); -const url3 = parse("https://github.com/foo/bar", true, true); -const url4 = parse("foo/bar", "https://github.com/"); -const url5 = parse("foo/bar", "https://github.com/", () => "queryParserOverride"); +const url2: parse.URL = parse("https://github.com/foo/bar?baz=true"); +const url3: parse.URL = parse("https://github.com/foo/bar", true, true); +const url4: parse.URL = parse("foo/bar", "https://github.com/"); +const url5: parse.URL = parse("foo/bar", "https://github.com/", () => "queryParserOverride"); url2.hash; url2.hostname;