Skip to content

Commit 07d68a5

Browse files
committed
Add typescript types
Closes #8
1 parent 2c71d95 commit 07d68a5

File tree

5 files changed

+72
-2
lines changed

5 files changed

+72
-2
lines changed

.appveyor.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ environment:
55
- nodejs_version: '8'
66
- nodejs_version: '6'
77
- nodejs_version: '4'
8+
matrix:
9+
allow_failures:
10+
- nodejs_version: '4'
811
platform:
912
- x86
1013
- x64

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ node_js:
44
- '8'
55
- '6'
66
- '4'
7+
matrix:
8+
allow_failures:
9+
- node_js: '4'
710
os:
811
- linux
912
- osx

index.d.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Type definitions for pidtree 0.3
2+
// Project: https://github.com/simonepri/pidtree
3+
// Definitions by: Silas Rech <https://github.com/lenovouser>
4+
// Definitions: https://github.com/simonepri/pidtree
5+
// TypeScript Version: 3.4
6+
7+
declare namespace pidtree {
8+
export interface Options {
9+
/**
10+
Include the provided PID in the list. Ignored if -1 is passed as PID.
11+
12+
@default false
13+
*/
14+
root?: boolean;
15+
}
16+
17+
export interface AdvancedResult {
18+
/**
19+
PID of the parent.
20+
*/
21+
ppid: number,
22+
/**
23+
PID
24+
*/
25+
pid: number,
26+
}
27+
28+
export type Result = number;
29+
}
30+
31+
/**
32+
Get the list of children and grandchildren pids of the given PID.
33+
34+
@param pid The PID
35+
36+
@example
37+
```
38+
import * as pidtree from 'pidtree';
39+
(async => {
40+
const result = await pidtree(1, { advanced: true });
41+
//=> [{ppid: 1, pid: 530}, {ppid: 1, pid: 42}, ..., {ppid: 1, pid: 41241}]
42+
})();
43+
```
44+
*/
45+
declare function pidtree(pid: string | number, callback: (error: Error | undefined, result: pidtree.Result[]) => void): void;
46+
declare function pidtree(pid: string | number, options: pidtree.Options, callback: (error: Error | undefined, result: pidtree.Result[]) => void): void;
47+
declare function pidtree(pid: string | number, options: pidtree.Options & { advanced: true }, callback: (error: Error | undefined, result: pidtree.AdvancedResult[]) => void): void;
48+
declare function pidtree(pid: string | number): Promise<pidtree.Result[]>;
49+
declare function pidtree(pid: string | number, options: pidtree.Options): Promise<pidtree.Result[]>;
50+
declare function pidtree(pid: string | number, options: pidtree.Options & { advanced: true }): Promise<pidtree.AdvancedResult[]>;
51+
52+
export = pidtree;

index.test-d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { expectType } from 'tsd';
2+
import * as pidtree from '.';
3+
4+
(async () => {
5+
expectType<number[]>(await pidtree(1));
6+
expectType<number[]>(await pidtree('1'));
7+
expectType<Array<{ ppid: number; pid: number }>>(await pidtree(1, { advanced: true }));
8+
expectType<Array<{ ppid: number; pid: number }>>(await pidtree('1', { advanced: true }));
9+
})();

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828
"processes"
2929
],
3030
"main": "index.js",
31+
"types": "index.d.ts",
3132
"bin": {
3233
"pidtree": "./bin/pidtree.js"
3334
},
3435
"files": [
3536
"bin",
3637
"lib",
37-
"index.js"
38+
"index.js",
39+
"index.d.ts"
3840
],
3941
"engines": {
4042
"node": ">=0.10"
@@ -44,7 +46,7 @@
4446
"update": "npm-check -u",
4547
"release": "np",
4648
"lint": "xo",
47-
"test": "npm run lint&& nyc ava -m \"!*benchmark*\"",
49+
"test": "npm run lint && nyc ava -m \"!*benchmark*\" && tsd",
4850
"bench": "ava -m \"*benchmark*\"",
4951
"coverage": "codecov"
5052
},
@@ -60,6 +62,7 @@
6062
"through": "^2.3.8",
6163
"time-span": "^3.1.0",
6264
"tree-kill": "^1.1.0",
65+
"tsd": "^0.7.2",
6366
"xo": "*"
6467
},
6568
"ava": {

0 commit comments

Comments
 (0)