Skip to content

Commit cfc8961

Browse files
BendingBendersindresorhus
authored andcommitted
Add TypeScript definition (#28)
1 parent 70fa23b commit cfc8961

5 files changed

Lines changed: 63 additions & 4 deletions

File tree

index.d.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
export interface Options {
2+
/**
3+
* Include other users' processes as well as your own.
4+
*
5+
* On Windows this has no effect and will always be the users' own processes.
6+
*
7+
* @default true
8+
*/
9+
readonly all?: boolean;
10+
}
11+
12+
export interface ProcessDescriptor {
13+
readonly pid: number;
14+
readonly name: string;
15+
readonly ppid: number;
16+
17+
/**
18+
* Not supported on Windows.
19+
*/
20+
readonly cmd?: string;
21+
22+
/**
23+
* Not supported on Windows.
24+
*/
25+
readonly cpu?: number;
26+
27+
/**
28+
* Not supported on Windows.
29+
*/
30+
readonly memory?: number;
31+
32+
/**
33+
* Not supported on Windows.
34+
*/
35+
readonly uid?: number;
36+
}
37+
38+
/**
39+
* Get running processes.
40+
*
41+
* @returns List of running processes.
42+
*/
43+
export default function psList(options?: Options): Promise<ProcessDescriptor[]>;

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ const main = async (options = {}) => {
5959
};
6060

6161
module.exports = process.platform === 'win32' ? windows : main;
62+
module.exports.default = module.exports;

index.test-d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {expectType} from 'tsd-check';
2+
import psList, {ProcessDescriptor} from '.';
3+
4+
const processes: ProcessDescriptor[] = await psList();
5+
psList({all: false});
6+
7+
expectType<number>(processes[0].pid);
8+
expectType<string>(processes[0].name);
9+
expectType<number>(processes[0].ppid);
10+
expectType<string | undefined>(processes[0].cmd);
11+
expectType<number | undefined>(processes[0].cpu);
12+
expectType<number | undefined>(processes[0].memory);
13+
expectType<number | undefined>(processes[0].uid);

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
"node": ">=8"
1414
},
1515
"scripts": {
16-
"test": "xo && ava"
16+
"test": "xo && ava && tsd-check"
1717
},
1818
"files": [
1919
"index.js",
20+
"index.d.ts",
2021
"fastlist.exe"
2122
],
2223
"keywords": [
@@ -29,7 +30,8 @@
2930
"tasklist"
3031
],
3132
"devDependencies": {
32-
"ava": "^0.25.0",
33-
"xo": "^0.23.0"
33+
"ava": "^1.3.1",
34+
"tsd-check": "^0.3.0",
35+
"xo": "^0.24.0"
3436
}
3537
}

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Type: `Object`
4141
Type: `boolean`<br>
4242
Default: `true`
4343

44-
Return other users' processes as well as your own.
44+
Include other users' processes as well as your own.
4545

4646
On Windows this has no effect and will always be the users' own processes.
4747

0 commit comments

Comments
 (0)