portfinder.d.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. * Set the lowest port to begin any port search from.
  34. */
  35. export function setBasePort(port: number): void;
  36. /**
  37. * The highest port to end any port search from.
  38. */
  39. export let highestPort: number;
  40. /**
  41. * Set the higheset port to end any port search from.
  42. */
  43. export function setHighestPort(port: number): void;
  44. /**
  45. * Responds with a unbound port on the current machine.
  46. */
  47. export function getPort(callback: PortfinderCallback): void;
  48. export function getPort(options: PortFinderOptions, callback: PortfinderCallback): void;
  49. export function getPorts(count: number, options: PortFinderOptions, callback: (err: Error, ports: Array<number>) => void): void;
  50. /**
  51. * Responds a promise of an unbound port on the current machine.
  52. */
  53. export function getPortPromise(options?: PortFinderOptions): Promise<number>;