Skip to content

Commit b353ded

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 ee4186b commit b353ded

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
@@ -1479,9 +1479,17 @@ added: v0.3.0
14791479
* `input` {string}
14801480
* Returns: {integer}
14811481

1482-
Tests if input is an IP address. Returns `0` for invalid strings,
1483-
returns `4` for IP version 4 addresses, and returns `6` for IP version 6
1484-
addresses.
1482+
Returns `6` if `input` is an IPv6 address. Returns `4` if `input` is an IPv4
1483+
address in [dot-decimal notation][] with no leading zeroes. Otherwise, returns
1484+
`0`.
1485+
1486+
```js
1487+
net.isIP('::1'); // returns 6
1488+
net.isIP('127.0.0.1'); // returns 4
1489+
net.isIP('127.000.000.001'); // returns 0
1490+
net.isIP('127.0.0.1/24'); // returns 0
1491+
net.isIP('fhqwhgads'); // returns 0
1492+
```
14851493

14861494
## `net.isIPv4(input)`
14871495

@@ -1492,7 +1500,15 @@ added: v0.3.0
14921500
* `input` {string}
14931501
* Returns: {boolean}
14941502

1495-
Returns `true` if input is a version 4 IP address, otherwise returns `false`.
1503+
Returns `true` if `input` is an IPv4 address in [dot-decimal notation][] with no
1504+
leading zeroes. Otherwise, returns `false`.
1505+
1506+
```js
1507+
net.isIPv4('127.0.0.1'); // returns true
1508+
net.isIPv4('127.000.000.001'); // returns false
1509+
net.isIPv4('127.0.0.1/24'); // returns false
1510+
net.isIPv4('fhqwhgads'); // returns false
1511+
```
14961512

14971513
## `net.isIPv6(input)`
14981514

@@ -1503,7 +1519,12 @@ added: v0.3.0
15031519
* `input` {string}
15041520
* Returns: {boolean}
15051521

1506-
Returns `true` if input is a version 6 IP address, otherwise returns `false`.
1522+
Returns `true` if `input` is an IPv6 address. Otherwise, returns `false`.
1523+
1524+
```js
1525+
net.isIPv6('::1'); // returns true
1526+
net.isIPv6('fhqwhgads'); // returns false
1527+
```
15071528

15081529
[IPC]: #ipc-support
15091530
[Identifying paths for IPC connections]: #identifying-paths-for-ipc-connections
@@ -1557,6 +1578,7 @@ Returns `true` if input is a version 6 IP address, otherwise returns `false`.
15571578
[`writable.destroyed`]: stream.md#writabledestroyed
15581579
[`writable.end()`]: stream.md#writableendchunk-encoding-callback
15591580
[`writable.writableLength`]: stream.md#writablewritablelength
1581+
[dot-decimal notation]: https://en.wikipedia.org/wiki/Dot-decimal_notation
15601582
[half-closed]: https://tools.ietf.org/html/rfc1122
15611583
[stream_writable_write]: stream.md#writablewritechunk-encoding-callback
15621584
[unspecified IPv4 address]: https://en.wikipedia.org/wiki/0.0.0.0

0 commit comments

Comments
 (0)