Add types for parse-path (#37805)

This commit is contained in:
Florian Keller 2019-08-21 18:53:21 +02:00 committed by Sheetal Nandi
parent b08558b7c5
commit fdfe1e8721
4 changed files with 71 additions and 0 deletions

34
types/parse-path/index.d.ts vendored Normal file
View File

@ -0,0 +1,34 @@
// Type definitions for parse-path 4.0
// Project: https://github.com/IonicaBizau/parse-path
// Definitions by: Florian Keller <https://github.com/ffflorian>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace parsePath {
type Protocol = 'http' | 'https' | 'ssh' | 'file' | 'git';
interface ParsedPath {
/** The url hash. */
hash: string;
/** The input url. */
href: string;
/** The url pathname. */
pathname: string;
/** The domain port. */
port: null | number;
/** The first protocol, `"ssh"` (if the url is a ssh url) or `"file"`. */
protocol: Protocol;
/** An array with the url protocols (usually it has one element). */
protocols: Protocol[];
/** The url querystring, parsed as object. */
query: any;
/** The url domain (including subdomains). */
resource: string;
/** The url querystring value. */
search: string;
/** The authentication user (usually for ssh urls). */
user: string;
}
}
declare function parsePath(url: string): parsePath.ParsedPath;
export = parsePath;

View File

@ -0,0 +1,13 @@
import parsePath = require('parse-path');
const parsed = parsePath('http://www.example.com');
parsed.hash; // $ExpectType string
parsed.href; // $ExpectType string
parsed.pathname; // $ExpectType string
parsed.port; // $ExpectType number | null
parsed.protocol; // $ExpectType Protocol
parsed.protocols; // $ExpectType Protocol[]
parsed.resource; // $ExpectType string
parsed.search; // $ExpectType string
parsed.user; // $ExpectType string

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"parse-path-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }