-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: typescript support * test: fix test
- Loading branch information
1 parent
b3ab1d8
commit 289827b
Showing
5 changed files
with
86 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ts: false | ||
jsx: false | ||
flow: false | ||
check-coverage: true | ||
coverage: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export interface SecureURLOption { | ||
mode?: 'path' | 'relax' | 'insecure' | ||
keepPort?: boolean | ||
} | ||
|
||
export declare class SecureURL { | ||
constructor(path: string | SecureURL | URL, option?: SecureURLOption) | ||
constructor(path: string | SecureURL | URL, base?: string | SecureURL | URL, option?: SecureURLOption) | ||
|
||
readonly href: string | ||
readonly origin: string | ||
readonly host: string | ||
readonly protocol: string | ||
readonly username: string | ||
readonly password: string | ||
readonly hostname: string | ||
readonly port?: number | ||
readonly pathname: string | ||
readonly hash: string | ||
readonly search: string | ||
readonly searchParams: URLSearchParams | ||
} | ||
|
||
export type URL = SecureURL | ||
|
||
export default SecureURL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { expectAssignable, expectError, expectType } from 'tsd' | ||
import DefaultExport, { SecureURL, SecureURLOption } from '../lib' | ||
|
||
// default export and named export should be the same | ||
expectType<DefaultExport>(new SecureURL('')) | ||
expectType<SecureURL>(new DefaultExport('')) | ||
|
||
// option | ||
expectAssignable<SecureURLOption>({}) | ||
expectAssignable<SecureURLOption>({ mode: 'path' }) | ||
expectAssignable<SecureURLOption>({ mode: 'relax' }) | ||
expectAssignable<SecureURLOption>({ mode: 'insecure' }) | ||
expectAssignable<SecureURLOption>({ keepPort: true }) | ||
expectAssignable<SecureURLOption>({ keepPort: false }) | ||
expectAssignable<SecureURLOption>({ mode: 'path', keepPort: true }) | ||
|
||
// two arguments | ||
expectType<SecureURL>(new SecureURL('', '')) | ||
expectType<SecureURL>(new SecureURL('', {})) | ||
expectType<SecureURL>(new SecureURL('', { mode: 'path', keepPort: true })) | ||
|
||
// three arguments | ||
expectType<SecureURL>(new SecureURL('', '', {})) | ||
expectType<SecureURL>(new SecureURL('', '', { mode: 'path', keepPort: true })) | ||
|
||
// invalid argument | ||
expectError(new SecureURL()) | ||
expectError(new SecureURL(true)) | ||
expectError(new SecureURL({})) | ||
expectError(new SecureURL('', { mode: 'invalid' })) | ||
|
||
const url = new SecureURL('https://localhost.local/') | ||
expectType<string>(url.href) | ||
expectType<string>(url.origin) | ||
expectType<string>(url.host) | ||
expectType<string>(url.protocol) | ||
expectType<string>(url.username) | ||
expectType<string>(url.password) | ||
expectType<string>(url.hostname) | ||
expectType<number | undefined>(url.port) | ||
expectType<string>(url.pathname) | ||
expectType<string>(url.hash) | ||
expectType<string>(url.search) | ||
expectType<URLSearchParams>(url.searchParams) |