-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(node/net): add missing ip utils and
SocketAddress
class
- Loading branch information
Showing
3 changed files
with
50 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,47 @@ | ||
// https://nodejs.org/api/net.html | ||
import type net from "node:net"; | ||
import { notImplemented } from "../../_internal/utils"; | ||
import * as socket from "./socket"; | ||
import { notImplemented, notImplementedClass } from "../../_internal/utils"; | ||
import { Socket, SocketAddress } from "./socket"; | ||
|
||
export * from "./socket"; | ||
export { Socket, SocketAddress } from "./socket"; | ||
|
||
export const createServer = notImplemented( | ||
"net.createServer", | ||
) as typeof net.createServer; | ||
|
||
export const Server = notImplementedClass("net.Server") as typeof net.Server; | ||
|
||
export const BlockList = notImplementedClass("net.BlockList") as typeof net.BlockList; | ||
|
||
export const connect = notImplemented("net.connect") as typeof net.connect; | ||
|
||
export const createConnection = notImplemented( | ||
"net.createConnection", | ||
) as typeof net.createConnection; | ||
|
||
export default <typeof net>{ | ||
...socket, | ||
const IPV4Regex = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/; | ||
export const isIPv4: typeof net.isIPv4 = ((host: string) => IPV4Regex.test(host)); | ||
|
||
const IPV6Regex = /^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/; | ||
export const isIPv6: typeof net.isIPv6 = ((host: string) => IPV6Regex.test(host)); | ||
|
||
export const isIP: typeof net.isIP = (host: string) => { | ||
if (isIPv4(host)) return 4; | ||
if (isIPv6(host)) return 6; | ||
return 0; | ||
} | ||
|
||
export const exports: typeof net = { | ||
Socket: Socket as any, // TODO | ||
Server, | ||
BlockList, | ||
SocketAddress, | ||
createServer, | ||
connect, | ||
createConnection, | ||
isIPv4, | ||
isIPv6, | ||
isIP, | ||
}; | ||
|
||
export default exports; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters