portfinder.d.ts 2.9 KB

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