@common.js/is-ip 5.0.0 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  The [is-ip](https://www.npmjs.com/package/is-ip) package exported as CommonJS modules.
4
4
 
5
- Exported from [is-ip@5.0.0](https://www.npmjs.com/package/is-ip/v/5.0.0) using https://github.com/etienne-martin/common.js.
5
+ Exported from [is-ip@5.0.1](https://www.npmjs.com/package/is-ip/v/5.0.1) using https://github.com/etienne-martin/common.js.
package/index.js CHANGED
@@ -35,20 +35,34 @@ var options = {
35
35
  timeout: 400
36
36
  };
37
37
  function isIP(string) {
38
+ if (string.length > maxIPv6Length) {
39
+ return false;
40
+ }
38
41
  return (0, _superRegex.isMatch)((0, _ipRegex.default)({
39
42
  exact: true
40
- }), string.slice(0, maxIPv6Length), options);
43
+ }), string, options);
41
44
  }
42
45
  function isIPv6(string) {
46
+ if (string.length > maxIPv6Length) {
47
+ return false;
48
+ }
43
49
  return (0, _superRegex.isMatch)(_ipRegex.default.v6({
44
50
  exact: true
45
- }), string.slice(0, maxIPv6Length), options);
51
+ }), string, options);
46
52
  }
47
53
  function isIPv4(string) {
54
+ if (string.length > maxIPv4Length) {
55
+ return false;
56
+ }
48
57
  return (0, _superRegex.isMatch)(_ipRegex.default.v4({
49
58
  exact: true
50
- }), string.slice(0, maxIPv4Length), options);
59
+ }), string, options);
51
60
  }
52
61
  function ipVersion(string) {
53
- return isIP(string) ? isIPv6(string) ? 6 : 4 : undefined;
62
+ if (isIPv6(string)) {
63
+ return 6;
64
+ }
65
+ if (isIPv4(string)) {
66
+ return 4;
67
+ }
54
68
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@common.js/is-ip",
3
- "version": "5.0.0",
4
- "description": "Check if a string is an IP address",
3
+ "version": "5.0.1",
4
+ "description": "is-ip package exported as CommonJS modules",
5
5
  "license": "MIT",
6
6
  "repository": "etienne-martin/common.js",
7
7
  "funding": "https://github.com/sponsors/sindresorhus",
@@ -24,7 +24,7 @@
24
24
  "devDependencies": {
25
25
  "ava": "^4.3.1",
26
26
  "tsd": "^0.22.0",
27
- "xo": "^0.51.0"
27
+ "xo": "^0.54.0"
28
28
  },
29
29
  "homepage": "https://github.com/etienne-martin/common.js#readme",
30
30
  "main": "./index.js"
package/readme.md DELETED
@@ -1,63 +0,0 @@
1
- # is-ip
2
-
3
- > Check if a string is an IP address
4
-
5
- If you only need this for Node.js and don't care about browser support, you may want to use [`net.isIP`](https://nodejs.org/api/net.html#net_net_isip_input) instead. Note that it returns an integer instead of a boolean.
6
-
7
- ## Install
8
-
9
- ```sh
10
- npm install is-ip
11
- ```
12
-
13
- ## Usage
14
-
15
- ```js
16
- import {isIP, isIPv4} from 'is-ip';
17
-
18
- isIP('1:2:3:4:5:6:7:8');
19
- //=> true
20
-
21
- isIP('192.168.0.1');
22
- //=> true
23
-
24
- isIPv4('1:2:3:4:5:6:7:8');
25
- //=> false
26
- ```
27
-
28
- ## API
29
-
30
- ### isIP(string)
31
-
32
- Check if `string` is IPv6 or IPv4.
33
-
34
- ### isIPv6(string)
35
-
36
- Check if `string` is IPv6.
37
-
38
- ### isIPv4(string)
39
-
40
- Check if `string` is IPv4.
41
-
42
- ### ipVersion(string)
43
-
44
- Returns `6` if `string` is IPv6, `4` if `string` is IPv4, or `undefined` if `string` is neither.
45
-
46
- ```js
47
- import {ipVersion} from 'is-ip';
48
-
49
- ipVersion('1:2:3:4:5:6:7:8');
50
- //=> 6
51
-
52
- ipVersion('192.168.0.1');
53
- //=> 4
54
-
55
- ipVersion('abc');
56
- //=> undefined
57
- ```
58
-
59
- ## Related
60
-
61
- - [ip-regex](https://github.com/sindresorhus/ip-regex) - Regular expression for matching IP addresses
62
- - [is-cidr](https://github.com/silverwind/is-cidr) - Check if a string is an IP address in CIDR notation
63
- - [cidr-regex](https://github.com/silverwind/cidr-regex) - Regular expression for matching IP addresses in CIDR notation