mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-04-14 00:58:24 -05:00
12 lines
410 B
TypeScript
12 lines
410 B
TypeScript
import * as net from 'node:net';
|
|
|
|
export function parseListenAddress(address: string | number) {
|
|
const match = ('' + address).match(/^((?:((?:\d+\.){3}\d+)|\[(.*)\]):)?(\d+)$/);
|
|
if (!match || (match[1] && !net.isIP(match[2] || match[3]))) throw new Error('Invalid address/port');
|
|
|
|
const host = match[2] || match[3] || null;
|
|
const port = parseInt(match[4]);
|
|
|
|
return [host, port] as const;
|
|
}
|