You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB

4 years ago
  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. /**
  29. * The lowest port to begin any port search from.
  30. */
  31. export let basePort: number;
  32. /**
  33. * Responds with a unbound port on the current machine.
  34. */
  35. export function getPort(callback: PortfinderCallback): void;
  36. export function getPort(options: PortFinderOptions, callback: PortfinderCallback): void;
  37. export function getPorts(count: number, options: PortFinderOptions, callback: (err: Error, ports: Array<number>) => void): void;
  38. /**
  39. * Responds a promise of an unbound port on the current machine.
  40. */
  41. export function getPortPromise(options?: PortFinderOptions): Promise<number>;