Skip to content

Commit

Permalink
feat: export checkPort utils (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Feb 10, 2022
1 parent d807928 commit c248dff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ or npm install get-port-please
```

```js
const { getPort } = require('get-port-please')
const { getPort, checkPort } = require('get-port-please')
// or
import { getPort } from 'get-port-please'
import { getPort, checkPort } from 'get-port-please'
```

```ts
function getPort(options?: GetPortOptions): Promise<number>
function checkPort(port: number, host?: string): Promise<number | false>
```

Try sequence is: port > ports > memo > random
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function getPort (config?: GetPortInput): Promise<number> {
return availablePort
}

async function checkPorts (ports: number[], host: string): Promise<number> {
export async function checkPorts (ports: number[], host?: string): Promise<number> {
for (const port of ports) {
const r = await checkPort(port, host)
if (r) {
Expand All @@ -69,7 +69,7 @@ async function checkPorts (ports: number[], host: string): Promise<number> {
return checkPort(0, host) as unknown as number
}

function checkPort (port: number, host: string): Promise<number|false> {
export function checkPort (port: number, host: string = process.env.HOST || '0.0.0.0'): Promise<number|false> {
return new Promise((resolve) => {
const server = createServer()
server.unref()
Expand Down

0 comments on commit c248dff

Please sign in to comment.