Skip to content

Commit

Permalink
Improve TypeScript types
Browse files Browse the repository at this point in the history
- correctly type normalization options
- correctly type parsed url
- add type tests via tsd
- add types for ES6 module export
  • Loading branch information
BendingBender committed Oct 28, 2022
1 parent a75e66f commit e16fd98
Show file tree
Hide file tree
Showing 5 changed files with 2,144 additions and 22 deletions.
7 changes: 7 additions & 0 deletions index.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import parseUrl = require("./index");

export type ParsedUrl = parseUrl.ParsedUrl;
export type NormalizeOptions = parseUrl.NormalizeOptions;
export type ParsingError = parseUrl.ParsingError;

export default parseUrl;
33 changes: 18 additions & 15 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
declare interface ParsedUrl {
protocols: string[];
protocol: string;
port?: string;
resource: string;
user: string;
pathname: string;
hash: string;
search: string;
href: string;
query: {
[key: string]: any;
}
import parsePath = require("parse-path");
import normalizeUrl = require("normalize-url");

declare namespace parseUrl {
const MAX_INPUT_LENGTH: 2048;

type NormalizeOptions = normalizeUrl.Options;

type ParsedUrl = parsePath.ParsedPath;

interface ParsingError extends Error {
readonly subject_url: string;
}
}

declare function parseUrl(url: string, normalize?: boolean | Object): ParsedUrl;
declare function parseUrl(
url: string,
normalize?: boolean | parseUrl.NormalizeOptions
): parseUrl.ParsedUrl;

export = parseUrl
export = parseUrl;
Loading

0 comments on commit e16fd98

Please sign in to comment.