You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Returns the given string parsed into an IPv4 or IPv6 address object.
28
20
If the string is not a valid address then the result is null.
29
21
30
22
```js
31
-
parseIP("192.0.2.1"); // IPv4 { ... }
32
-
parseIP("2001:db8::1"); // IPv6 { ... }
33
-
parseIP("non-address"); // null
23
+
IP.parse("192.0.2.1"); // IPv4 { ... }
24
+
IP.parse("2001:db8::1"); // IPv6 { ... }
25
+
IP.parse("non-address"); // null
34
26
```
35
27
36
-
**parseIP** supports IPv6 addresses with embedded IPv4 addresses.
28
+
**IP.parse** supports IPv6 addresses with embedded IPv4 addresses.
37
29
38
30
```js
39
-
parseIP("2001:db8::192.0.2.1"); // IPv6 { ... }
31
+
IP.parse("2001:db8::192.0.2.1"); // IPv6 { ... }
40
32
```
41
33
42
-
## ip.version
34
+
## IP#version
43
35
44
36
Valid IPv4/6 address objects have their version as an attribute.
45
37
46
38
```js
47
-
parseIP("192.0.2.1").version; // 4
48
-
parseIP("2001:db8::1").version; // 6
39
+
IP.parse("192.0.2.1").version; // 4
40
+
IP.parse("2001:db8::1").version; // 6
49
41
```
50
42
51
-
## ip.toString()
43
+
## IP#toString()
52
44
53
45
Address objects implement the **toString** method for turning the addresses back into strings. The strings are printed lower-cased sans any extra leading zeroes. IPv6 formatting follows the [RFC 5952](https://tools.ietf.org/html/rfc5952) recommendations, except that formatting doesn't output IPv6 addresses with embedded IPv4 addresses.
0 commit comments