Skip to content

Commit

Permalink
docs(net): complete documentation (#4982)
Browse files Browse the repository at this point in the history
  • Loading branch information
iuioiua committed Jun 7, 2024
1 parent 628814e commit 94bb952
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions _tools/check_docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const ENTRY_POINTS = [
"../internal/mod.ts",
"../jsonc/mod.ts",
"../media_types/mod.ts",
"../net/mod.ts",
"../path/mod.ts",
"../path/posix/mod.ts",
"../path/windows/mod.ts",
Expand Down
12 changes: 10 additions & 2 deletions net/get_available_port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ export interface GetAvailablePortOptions {
/**
* A port to check availability of first. If the port isn't available, fall
* back to another port.
*
* Defaults to port 0, which will let the operating system choose an available
* port.
*
* @default {0}
*/
preferredPort?: number;
}

/**
* Returns an available network port.
*
* @example
* ```ts
* @param options Options for getting an available port.
* @returns An available network port.
*
* @example Usage
* ```ts no-eval no-assert
* import { getAvailablePort } from "@std/net/get-available-port";
*
* const port = getAvailablePort();
Expand Down
14 changes: 6 additions & 8 deletions net/get_network_address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,21 @@
* @returns The IPv4 network address of the machine.
*
* @example Get the IPv4 network address (default)
* ```ts
* ```ts no-assert no-eval
* import { getNetworkAddress } from "@std/net/get-network-address";
* import { assert } from "@std/assert/assert";
*
* const address = getNetworkAddress();
* const hostname = getNetworkAddress();
*
* assert(address !== undefined);
* Deno.serve({ port: 0, hostname }, () => new Response("Hello, world!"));
* ```
*
* @example Get the IPv6 network address
* ```ts
* ```ts no-assert no-eval
* import { getNetworkAddress } from "@std/net/get-network-address";
* import { assert } from "@std/assert/assert";
*
* const address = getNetworkAddress("IPv6");
* const hostname = getNetworkAddress("IPv6");
*
* assert(address !== undefined);
* Deno.serve({ port: 0, hostname }, () => new Response("Hello, world!"));
* ```
*/
export function getNetworkAddress(
Expand Down
8 changes: 8 additions & 0 deletions net/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
/**
* Network utilities.
*
* ```ts no-assert no-eval
* import { getNetworkAddress, getAvailablePort } from "@std/net";
*
* console.log(`My network IP address is ${getNetworkAddress()}`);
*
* Deno.serve({ port: getAvailablePort() }, () => new Response("Hello, world!"));
* ```
*
* @module
*/

Expand Down

0 comments on commit 94bb952

Please sign in to comment.