Skip to content

Commit 8b3b51f

Browse files
committed
feat: add isAddressInfo helper function
1 parent 25b1340 commit 8b3b51f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/node/util.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,15 @@ export function isNodeJSErrnoException(error: unknown): error is NodeJS.ErrnoExc
485485
return error !== undefined && (error as NodeJS.ErrnoException).code !== undefined
486486
}
487487

488+
/**
489+
* A helper function which returns a boolean indicating whether
490+
* the given address is AddressInfo and has .address
491+
* and a .port property.
492+
*/
493+
export function isAddressInfo(address: unknown): address is net.AddressInfo {
494+
return address !== null && typeof address !== "string" && (address as net.AddressInfo).port !== undefined
495+
}
496+
488497
// TODO: Replace with proper templating system.
489498
export const escapeJSON = (value: cp.Serializable) => JSON.stringify(value).replace(/"/g, """)
490499

0 commit comments

Comments
 (0)