Skip to content

Commit

Permalink
馃 Merge PR DefinitelyTyped#65386 Add url.urlToHttpOptions to Node 14 by
Browse files Browse the repository at this point in the history
  • Loading branch information
koterpillar committed May 4, 2023
1 parent 26ec8fa commit 80908e3
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
5 changes: 5 additions & 0 deletions types/node/v14/test/url.ts
@@ -1,4 +1,5 @@
import assert = require('node:assert');
import { RequestOptions } from 'node:http';
import * as url from 'node:url';

{
Expand Down Expand Up @@ -155,6 +156,10 @@ import * as url from 'node:url';
const path: url.URL = url.pathToFileURL('file://test');
}

{
const opts: RequestOptions = url.urlToHttpOptions(new url.URL('test.com'));
}

{
const dataUrl1: URL = new url.URL('file://test');
const dataUrl2: url.URL = new URL('file://test');
Expand Down
5 changes: 5 additions & 0 deletions types/node/v14/ts4.8/test/url.ts
@@ -1,4 +1,5 @@
import assert = require('node:assert');
import { RequestOptions } from 'node:http';
import * as url from 'node:url';

{
Expand Down Expand Up @@ -155,6 +156,10 @@ import * as url from 'node:url';
const path: url.URL = url.pathToFileURL('file://test');
}

{
const opts: RequestOptions = url.urlToHttpOptions(new url.URL('test.com'));
}

{
const dataUrl1: URL = new url.URL('file://test');
const dataUrl2: url.URL = new URL('file://test');
Expand Down
28 changes: 28 additions & 0 deletions types/node/v14/ts4.8/url.d.ts
@@ -1,4 +1,5 @@
declare module 'url' {
import { ClientRequestArgs } from 'node:http';
import { ParsedUrlQuery, ParsedUrlQueryInput } from 'querystring';

// Input to `url.format`
Expand Down Expand Up @@ -71,6 +72,33 @@ declare module 'url' {
* @param url The path to convert to a File URL.
*/
function pathToFileURL(url: string): URL;
/**
* This utility function converts a URL object into an ordinary options object as
* expected by the `http.request()` and `https.request()` APIs.
*
* ```js
* import { urlToHttpOptions } from 'url';
* const myURL = new URL('https://a:b@娓│?abc#foo');
*
* console.log(urlToHttpOptions(myURL));
*
* {
* protocol: 'https:',
* hostname: 'xn--g6w251d',
* hash: '#foo',
* search: '?abc',
* pathname: '/',
* path: '/?abc',
* href: 'https://a:b@xn--g6w251d/?abc#foo',
* auth: 'a:b'
* }
*
* ```
* @since v14.18.0
* @param url The `WHATWG URL` object to convert to an options object.
* @return Options object
*/
function urlToHttpOptions(url: URL): ClientRequestArgs;

interface URLFormatOptions {
auth?: boolean | undefined;
Expand Down
28 changes: 28 additions & 0 deletions types/node/v14/url.d.ts
@@ -1,4 +1,5 @@
declare module 'url' {
import { ClientRequestArgs } from 'node:http';
import { ParsedUrlQuery, ParsedUrlQueryInput } from 'querystring';

// Input to `url.format`
Expand Down Expand Up @@ -71,6 +72,33 @@ declare module 'url' {
* @param url The path to convert to a File URL.
*/
function pathToFileURL(url: string): URL;
/**
* This utility function converts a URL object into an ordinary options object as
* expected by the `http.request()` and `https.request()` APIs.
*
* ```js
* import { urlToHttpOptions } from 'url';
* const myURL = new URL('https://a:b@娓│?abc#foo');
*
* console.log(urlToHttpOptions(myURL));
*
* {
* protocol: 'https:',
* hostname: 'xn--g6w251d',
* hash: '#foo',
* search: '?abc',
* pathname: '/',
* path: '/?abc',
* href: 'https://a:b@xn--g6w251d/?abc#foo',
* auth: 'a:b'
* }
*
* ```
* @since v14.18.0
* @param url The `WHATWG URL` object to convert to an options object.
* @return Options object
*/
function urlToHttpOptions(url: URL): ClientRequestArgs;

interface URLFormatOptions {
auth?: boolean | undefined;
Expand Down

0 comments on commit 80908e3

Please sign in to comment.