UNPKG

3.09 kBTypeScriptView Raw
1// Type definitions for which 2.0
2// Project: https://github.com/isaacs/node-which
3// Definitions by: vvakame <https://github.com/vvakame>
4// cspotcode <https://github.com/cspotcode>
5// Piotr Błażejewicz <https://github.com/peterblazejewicz>
6// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
7
8/** Finds all instances of a specified executable in the PATH environment variable */
9declare function which(
10 cmd: string,
11 options: which.AsyncOptions & which.OptionsAll,
12 cb: (err: Error | null, paths: ReadonlyArray<string> | undefined) => void,
13): void;
14declare function which(
15 cmd: string,
16 options: which.AsyncOptions & which.OptionsFirst,
17 cb: (err: Error | null, path: string | undefined) => void,
18): void;
19declare function which(
20 cmd: string,
21 options: which.AsyncOptions,
22 cb: (err: Error | null, path: string | ReadonlyArray<string> | undefined) => void,
23): void;
24declare function which(cmd: string, cb: (err: Error | null, path: string | undefined) => void): void;
25declare function which(cmd: string, options: which.AsyncOptions & which.OptionsAll): Promise<string[]>;
26declare function which(cmd: string, options?: which.AsyncOptions & which.OptionsFirst): Promise<string>;
27
28declare namespace which {
29 /** Finds all instances of a specified executable in the PATH environment variable */
30 function sync(cmd: string, options: Options & OptionsAll & OptionsNoThrow): ReadonlyArray<string> | null;
31 function sync(cmd: string, options: Options & OptionsFirst & OptionsNoThrow): string | null;
32 function sync(cmd: string, options: Options & OptionsAll & OptionsThrow): ReadonlyArray<string>;
33 function sync(cmd: string, options?: Options & OptionsFirst & OptionsThrow): string;
34 function sync(cmd: string, options: Options): string | ReadonlyArray<string> | null;
35
36 /** Options that ask for all matches. */
37 interface OptionsAll extends AsyncOptions {
38 all: true;
39 }
40
41 /** Options that ask for the first match (the default behavior) */
42 interface OptionsFirst extends AsyncOptions {
43 all?: false;
44 }
45
46 /** Options that ask to receive null instead of a thrown error */
47 interface OptionsNoThrow extends Options {
48 nothrow: true;
49 }
50
51 /** Options that ask for a thrown error if executable is not found (the default behavior) */
52 interface OptionsThrow extends Options {
53 nothrow?: false;
54 }
55
56 /** Options for which() async API */
57 interface AsyncOptions {
58 /** If true, return all matches, instead of just the first one. Note that this means the function returns an array of strings instead of a single string. */
59 all?: boolean;
60 /** Use instead of the PATH environment variable. */
61 path?: string;
62 /** Use instead of the PATHEXT environment variable. */
63 pathExt?: string;
64 }
65
66 /** Options for which() sync and async APIs */
67 interface Options extends AsyncOptions {
68 /** If true, returns null when not found */
69 nothrow?: boolean;
70 }
71}
72
73export = which;