feat: export port tools

This commit is contained in:
2024-07-19 19:41:59 +02:00
parent dfbfa900e1
commit 7cfd038851
2 changed files with 5 additions and 4 deletions

View File

@@ -4,7 +4,7 @@ export const MAX_PORT = 65535;
/** /**
* Try run listener to check if port is open. * Try run listener to check if port is open.
* *
* @param options * @param options - Deno listen options.
*/ */
export function checkPort(options: Deno.ListenOptions): CheckedPort { export function checkPort(options: Deno.ListenOptions): CheckedPort {
const { port } = options; const { port } = options;
@@ -45,7 +45,7 @@ export function makeRange(from: number, to: number): number[] {
/** /**
* Return a random port between 1024 and 65535. * Return a random port between 1024 and 65535.
* *
* @param hostname * @param hostname - Hostname to check for port availability under. (Optional)
*/ */
export function randomPort(hostname?: string): number { export function randomPort(hostname?: string): number {
const port = Math.ceil(Math.random() * ((MAX_PORT - 1) - MIN_PORT + 1) + MIN_PORT + 1); const port = Math.ceil(Math.random() * ((MAX_PORT - 1) - MIN_PORT + 1) + MIN_PORT + 1);
@@ -59,8 +59,8 @@ export function randomPort(hostname?: string): number {
/** /**
* Return available port. * Return available port.
* *
* @param port * @param port - Wanted port, or list of ports. (Optional)
* @param hostname * @param hostname - Hostname to check for availability under. (Optional)
*/ */
export default function getPort(port?: number | number[], hostname?: string): number { export default function getPort(port?: number | number[], hostname?: string): number {
const listenOptions: Deno.ListenOptions = { const listenOptions: Deno.ListenOptions = {

1
mod.ts
View File

@@ -5,5 +5,6 @@ export type { Docker } from "./docker/libraries/docker.ts";
export type { Exec } from "./docker/libraries/exec.ts"; export type { Exec } from "./docker/libraries/exec.ts";
export type { Image } from "./docker/libraries/image.ts"; export type { Image } from "./docker/libraries/image.ts";
export { modem } from "./docker/libraries/modem.ts"; export { modem } from "./docker/libraries/modem.ts";
export * from "./docker/libraries/port.ts";
export const docker: Docker = new Docker(); export const docker: Docker = new Docker();