Skip to content

Commit ce49c17

Browse files
author
Michael Solomon
authored
Add TypeScript types (#8)
1 parent 1d93e13 commit ce49c17

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

index.d.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
interface Options {
2+
/**
3+
Milliseconds to wait before giving up.
4+
5+
@default 1000
6+
*/
7+
timeout?: number;
8+
9+
/**
10+
Can be a domain or an IP.
11+
12+
@default 'localhost'
13+
*/
14+
host?: string;
15+
}
16+
17+
/**
18+
Check if a local or remote port is reachable.
19+
20+
@example
21+
```
22+
import isPortReachable from 'is-port-reachable';
23+
24+
if(await isPortReachable(3000)) {
25+
// start server
26+
}
27+
```
28+
*/
29+
declare function isPortReachable(port: number, options?: Options): Promise<boolean>;
30+
31+
export = isPortReachable;

index.test-d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import {expectType} from 'tsd';
2+
import isPortReachable = require('.');
3+
4+
expectType<boolean>(await isPortReachable(3000));

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
"node": ">=8"
1717
},
1818
"scripts": {
19-
"test": "xo && ava"
19+
"test": "xo && ava && tsd"
2020
},
2121
"files": [
22-
"index.js"
22+
"index.js",
23+
"index.d.ts"
2324
],
2425
"keywords": [
2526
"port",
@@ -40,6 +41,7 @@
4041
],
4142
"devDependencies": {
4243
"ava": "^2.4.0",
43-
"xo": "^0.25.3"
44+
"xo": "^0.25.3",
45+
"tsd": "^0.17.0"
4446
}
4547
}

0 commit comments

Comments
 (0)