From c79ac3b097154f7c89d349696a299347e020baa8 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Fri, 29 Nov 2024 07:59:46 -0800 Subject: [PATCH] net: add SocketAddress.parse Adds a new `net.SocketAddress.parse(...)` API. ```js const addr = SocketAddress.parse('123.123.123.123:1234'); console.log(addr.address); // 123.123.123.123 console.log(addr.port); 1234 ``` --- doc/api/net.md | 11 ++ lib/internal/socketaddress.js | 34 +++- test/parallel/test-socketaddress.js | 237 ++++++++++++++++------------ 3 files changed, 182 insertions(+), 100 deletions(-) diff --git a/doc/api/net.md b/doc/api/net.md index 7d8a27bf0b1769..c7f5ec335362d6 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -235,6 +235,17 @@ added: * Type {number} +### `SocketAddress.parse(input)` + + + +* `input` {string} An input string containing an IP address and optional port, + e.g. `123.1.2.3:1234` or `[1::1]:1234`. +* Returns: {net.SocketAddress} Returns a `SocketAddress` if parsing was successful. + Otherwise returns `undefined`. + ## Class: `net.Server`