Skip to content

Commit

Permalink
Clean-up url types for API extractor (#7326)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigtimebuddy committed Mar 23, 2021
1 parent 05ea7c7 commit da816e6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
4 changes: 1 addition & 3 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ export { EventEmitter };
*/
export { default as earcut } from 'earcut';

import { parse, format, resolve } from './url';

/**
* Node.js compatible URL utilities.
*
Expand All @@ -85,7 +83,7 @@ import { parse, format, resolve } from './url';
* @name url
* @member {object}
*/
export const url = { parse, format, resolve };
export * from './url';

import './settings';

Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/network/determineCrossOrigin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as _url from '../url';
import { url as _url } from '../url';

let tempAnchor: HTMLAnchorElement|undefined;

Expand Down
30 changes: 16 additions & 14 deletions packages/utils/src/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

import { parse as _parse, format as _format, resolve as _resolve } from 'url';

export interface ParsedUrlQuery {
interface ParsedUrlQuery {
[key: string]: string | string[];
}

export interface ParsedUrlQueryInput {
interface ParsedUrlQueryInput {
[key: string]: unknown;
}

export interface UrlObjectCommon {
interface UrlObjectCommon {
auth?: string;
hash?: string;
host?: string;
Expand All @@ -29,48 +29,50 @@ export interface UrlObjectCommon {
}

// Input to `url.format`
export interface UrlObject extends UrlObjectCommon {
interface UrlObject extends UrlObjectCommon {
port?: string | number;
query?: string | null | ParsedUrlQueryInput;
}

// Output of `url.parse`
export interface Url extends UrlObjectCommon {
interface Url extends UrlObjectCommon {
port?: string;
query?: string | null | ParsedUrlQuery;
}

export interface UrlWithParsedQuery extends Url {
interface UrlWithParsedQuery extends Url {
query: ParsedUrlQuery;
}

export interface UrlWithStringQuery extends Url {
interface UrlWithStringQuery extends Url {
query: string | null;
}

export interface URLFormatOptions {
interface URLFormatOptions {
auth?: boolean;
fragment?: boolean;
search?: boolean;
unicode?: boolean;
}

export type ParseFunction = {
type ParseFunction = {
(urlStr: string): UrlWithStringQuery;
(urlStr: string, parseQueryString: false | undefined, slashesDenoteHost?: boolean): UrlWithStringQuery;
(urlStr: string, parseQueryString: true, slashesDenoteHost?: boolean): UrlWithParsedQuery;
(urlStr: string, parseQueryString: boolean, slashesDenoteHost?: boolean): Url;
};

export type FormatFunction = {
type FormatFunction = {
(URL: URL, options?: URLFormatOptions): string;
(urlObject: UrlObject | string): string;
};

export type ResolveFunction = {
type ResolveFunction = {
(from: string, to: string): string;
};

export const parse: ParseFunction = _parse;
export const format: FormatFunction = _format;
export const resolve: ResolveFunction = _resolve;
export const url = {
parse: _parse as ParseFunction,
format: _format as FormatFunction,
resolve: _resolve as ResolveFunction,
};

0 comments on commit da816e6

Please sign in to comment.