-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
- Loading branch information
1 parent
4d38bea
commit b733aa2
Showing
3 changed files
with
29 additions
and
2 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,18 @@ | ||
export type Options = Readonly<{ | ||
/** | ||
* A preferred port or an array of preferred ports to use. | ||
*/ | ||
port?: number | ReadonlyArray<number>, | ||
|
||
/** | ||
* The host on which port resolution should be performed. Can be either an IPv4 or IPv6 address. | ||
*/ | ||
host?: string; | ||
}>; | ||
|
||
/** | ||
* Get an available port number. | ||
* | ||
* @returns Port number. | ||
*/ | ||
export default function getPort(options?: Options): Promise<number>; |
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,7 @@ | ||
import {expectType} from 'tsd-check'; | ||
import getPort from '.'; | ||
|
||
expectType<number>(await getPort()); | ||
expectType<number>(await getPort({port: 3000})); | ||
expectType<number>(await getPort({port: [3000, 3001, 3002]})); | ||
expectType<number>(await getPort({host: 'https://localhost'})); |
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