Debian Codegraph @

portfinder/lib/portfinder.d.ts

raw
1 /**
2 * portfinder.js typescript definitions.
3 *
4 * (C) 2011, Charlie Robbins
5 */
6
7 type PortfinderCallback = (err: Error, port: number) => void;
8
9 interface PortFinderOptions {
10 /**
11 * Host to find available port on.
12 */
13 host?: string;
14 /**
15 * search start port (equals to port when not provided)
16 * This exists because getPort and getPortPromise mutates port state in
17 * recursive calls and doesn't have a way to retrieve begininng port while
18 * searching.
19 */
20 startPort?: number;
21 /**
22 * Minimum port (takes precedence over `basePort`).
23 */
24 port?: number;
25 /**
26 * Maximum port
27 */
28 stopPort?: number;
29 }
30
31 type SocketfinderCallback = (err: Error, socket: string) => void;
32
33 interface SocketFinderOptions {
34 /**
35 * Mode to use when creating folder for socket if it doesn't exist
36 */
37 mod?: number;
38 /**
39 * Path to the socket file to create
40 * (defaults to `${exports.basePath}.sock` if not provided)
41 */
42 path?: string;
43 }
44
45 /**
46 * The lowest port to begin any port search from.
47 */
48 export let basePort: number;
49
50 /**
51 * Set the lowest port to begin any port search from.
52 */
53 export function setBasePort(port: number): void;
54
55 /**
56 * The highest port to end any port search from.
57 */
58 export let highestPort: number;
59
60 /**
61 * Set the higheset port to end any port search from.
62 */
63 export function setHighestPort(port: number): void;
64
65 /**
66 * Default path to begin any socket search from.
67 */
68 export let basePath: string;
69
70 /**
71 * Set the base path to begin any socket search from.
72 */
73 export function setBasePath(path: string): void;
74
75 /**
76 * Responds with a unbound port on the current machine.
77 */
78 export function getPort(options: PortFinderOptions): Promise<number>;
79 export function getPort(callback: PortfinderCallback): void;
80 export function getPort(options: PortFinderOptions, callback: PortfinderCallback): void;
81
82 /**
83 * Responds a promise of an unbound port on the current machine.
84 */
85 export function getPortPromise(options?: PortFinderOptions): Promise<number>;
86
87 /**
88 * Responds with an array of unbound ports on the current machine.
89 */
90 export function getPorts(count: number, options: PortFinderOptions): Promise<Array<number>>;
91 export function getPorts(count: number, callback: (err: Error, ports: Array<number>) => void): void;
92 export function getPorts(count: number, options: PortFinderOptions, callback: (err: Error, ports: Array<number>) => void): void;
93
94 /**
95 * Responds a promise that resolves to an array of unbound ports on the current machine.
96 */
97 export function getPortsPromise(count: number, options?: PortFinderOptions): Promise<Array<number>>;
98
99 export function getSocket(options: SocketFinderOptions): Promise<string>;
100 export function getSocket(callback: SocketfinderCallback): void;
101 export function getSocket(options: SocketFinderOptions, callback: SocketfinderCallback): void;
102
103 export function getSocketPromise(options?: SocketFinderOptions): Promise<string>;