Skip to content

Commit 6472311

Browse files
Trottdanielleadams
authored andcommitted
doc: expand entries for isIP(), isIPv4(), and isIPv6()
Closes: #40966 PR-URL: #41028 Fixes: #40966 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Brian White <[email protected]>
1 parent 9691d7d commit 6472311

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

doc/api/net.md

+27-5
Original file line numberDiff line numberDiff line change
@@ -1455,9 +1455,17 @@ added: v0.3.0
14551455
* `input` {string}
14561456
* Returns: {integer}
14571457

1458-
Tests if input is an IP address. Returns `0` for invalid strings,
1459-
returns `4` for IP version 4 addresses, and returns `6` for IP version 6
1460-
addresses.
1458+
Returns `6` if `input` is an IPv6 address. Returns `4` if `input` is an IPv4
1459+
address in [dot-decimal notation][] with no leading zeroes. Otherwise, returns
1460+
`0`.
1461+
1462+
```js
1463+
net.isIP('::1'); // returns 6
1464+
net.isIP('127.0.0.1'); // returns 4
1465+
net.isIP('127.000.000.001'); // returns 0
1466+
net.isIP('127.0.0.1/24'); // returns 0
1467+
net.isIP('fhqwhgads'); // returns 0
1468+
```
14611469

14621470
## `net.isIPv4(input)`
14631471

@@ -1468,7 +1476,15 @@ added: v0.3.0
14681476
* `input` {string}
14691477
* Returns: {boolean}
14701478

1471-
Returns `true` if input is a version 4 IP address, otherwise returns `false`.
1479+
Returns `true` if `input` is an IPv4 address in [dot-decimal notation][] with no
1480+
leading zeroes. Otherwise, returns `false`.
1481+
1482+
```js
1483+
net.isIPv4('127.0.0.1'); // returns true
1484+
net.isIPv4('127.000.000.001'); // returns false
1485+
net.isIPv4('127.0.0.1/24'); // returns false
1486+
net.isIPv4('fhqwhgads'); // returns false
1487+
```
14721488

14731489
## `net.isIPv6(input)`
14741490

@@ -1479,7 +1495,12 @@ added: v0.3.0
14791495
* `input` {string}
14801496
* Returns: {boolean}
14811497

1482-
Returns `true` if input is a version 6 IP address, otherwise returns `false`.
1498+
Returns `true` if `input` is an IPv6 address. Otherwise, returns `false`.
1499+
1500+
```js
1501+
net.isIPv6('::1'); // returns true
1502+
net.isIPv6('fhqwhgads'); // returns false
1503+
```
14831504

14841505
[IPC]: #ipc-support
14851506
[Identifying paths for IPC connections]: #identifying-paths-for-ipc-connections
@@ -1533,6 +1554,7 @@ Returns `true` if input is a version 6 IP address, otherwise returns `false`.
15331554
[`writable.destroyed`]: stream.md#writabledestroyed
15341555
[`writable.end()`]: stream.md#writableendchunk-encoding-callback
15351556
[`writable.writableLength`]: stream.md#writablewritablelength
1557+
[dot-decimal notation]: https://en.wikipedia.org/wiki/Dot-decimal_notation
15361558
[half-closed]: https://tools.ietf.org/html/rfc1122
15371559
[stream_writable_write]: stream.md#writablewritechunk-encoding-callback
15381560
[unspecified IPv4 address]: https://en.wikipedia.org/wiki/0.0.0.0

0 commit comments

Comments
 (0)