Skip to content

Commit

Permalink
Add TypeScript types (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikicho authored Sep 19, 2021
1 parent 1d93e13 commit ce49c17
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
31 changes: 31 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
interface Options {
/**
Milliseconds to wait before giving up.
@default 1000
*/
timeout?: number;

/**
Can be a domain or an IP.
@default 'localhost'
*/
host?: string;
}

/**
Check if a local or remote port is reachable.
@example
```
import isPortReachable from 'is-port-reachable';
if(await isPortReachable(3000)) {
// start server
}
```
*/
declare function isPortReachable(port: number, options?: Options): Promise<boolean>;

export = isPortReachable;
4 changes: 4 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {expectType} from 'tsd';
import isPortReachable = require('.');

expectType<boolean>(await isPortReachable(3000));
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
"node": ">=8"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],
"keywords": [
"port",
Expand All @@ -40,6 +41,7 @@
],
"devDependencies": {
"ava": "^2.4.0",
"xo": "^0.25.3"
"xo": "^0.25.3",
"tsd": "^0.17.0"
}
}

0 comments on commit ce49c17

Please sign in to comment.