@common.js/is-ip 5.0.0

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 ADDED
@@ -0,0 +1,5 @@
1
+ # @common.js/is-ip
2
+
3
+ The [is-ip](https://www.npmjs.com/package/is-ip) package exported as CommonJS modules.
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.
package/index.d.ts ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ Check if `string` is IPv6 or IPv4.
3
+
4
+ @example
5
+ ```
6
+ import {isIP} from 'is-ip';
7
+
8
+ isIP('1:2:3:4:5:6:7:8');
9
+ //=> true
10
+
11
+ isIP('192.168.0.1');
12
+ //=> true
13
+ ```
14
+ */
15
+ export function isIP(string: string): boolean; // eslint-disable-line @typescript-eslint/naming-convention
16
+
17
+ /**
18
+ Check if `string` is IPv6.
19
+
20
+ @example
21
+ ```
22
+ import {isIPv6} from 'is-ip';
23
+
24
+ isIPv6('1:2:3:4:5:6:7:8');
25
+ //=> true
26
+ ```
27
+ */
28
+ export function isIPv6(string: string): boolean; // eslint-disable-line @typescript-eslint/naming-convention
29
+
30
+ /**
31
+ Check if `string` is IPv4.
32
+
33
+ @example
34
+ ```
35
+ import {isIPv4} from 'is-ip';
36
+
37
+ isIPv4('192.168.0.1');
38
+ //=> true
39
+ ```
40
+ */
41
+ export function isIPv4(string: string): boolean; // eslint-disable-line @typescript-eslint/naming-convention
42
+
43
+ /**
44
+ @returns `6` if `string` is IPv6, `4` if `string` is IPv4, or `undefined` if `string` is neither.
45
+
46
+ @example
47
+ ```
48
+ import {ipVersion} from 'is-ip';
49
+
50
+ ipVersion('1:2:3:4:5:6:7:8');
51
+ //=> 6
52
+
53
+ ipVersion('192.168.0.1');
54
+ //=> 4
55
+
56
+ ipVersion('abc');
57
+ //=> undefined
58
+ ```
59
+ */
60
+ export function ipVersion(string: string): 6 | 4 | undefined;
package/index.js ADDED
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ isIP: function() {
13
+ return isIP;
14
+ },
15
+ isIPv6: function() {
16
+ return isIPv6;
17
+ },
18
+ isIPv4: function() {
19
+ return isIPv4;
20
+ },
21
+ ipVersion: function() {
22
+ return ipVersion;
23
+ }
24
+ });
25
+ var _ipRegex = /*#__PURE__*/ _interopRequireDefault(require("ip-regex"));
26
+ var _superRegex = require("super-regex");
27
+ function _interopRequireDefault(obj) {
28
+ return obj && obj.__esModule ? obj : {
29
+ default: obj
30
+ };
31
+ }
32
+ var maxIPv4Length = 15;
33
+ var maxIPv6Length = 45;
34
+ var options = {
35
+ timeout: 400
36
+ };
37
+ function isIP(string) {
38
+ return (0, _superRegex.isMatch)((0, _ipRegex.default)({
39
+ exact: true
40
+ }), string.slice(0, maxIPv6Length), options);
41
+ }
42
+ function isIPv6(string) {
43
+ return (0, _superRegex.isMatch)(_ipRegex.default.v6({
44
+ exact: true
45
+ }), string.slice(0, maxIPv6Length), options);
46
+ }
47
+ function isIPv4(string) {
48
+ return (0, _superRegex.isMatch)(_ipRegex.default.v4({
49
+ exact: true
50
+ }), string.slice(0, maxIPv4Length), options);
51
+ }
52
+ function ipVersion(string) {
53
+ return isIP(string) ? isIPv6(string) ? 6 : 4 : undefined;
54
+ }
package/license ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@common.js/is-ip",
3
+ "version": "5.0.0",
4
+ "description": "Check if a string is an IP address",
5
+ "license": "MIT",
6
+ "repository": "etienne-martin/common.js",
7
+ "funding": "https://github.com/sponsors/sindresorhus",
8
+ "type": "commonjs",
9
+ "types": "./index.d.ts",
10
+ "engines": {
11
+ "node": ">=14.16"
12
+ },
13
+ "scripts": {
14
+ "test": "xo && ava && tsd"
15
+ },
16
+ "files": [
17
+ "index.js",
18
+ "index.d.ts"
19
+ ],
20
+ "dependencies": {
21
+ "@common.js/ip-regex": "^5.0.0",
22
+ "@common.js/super-regex": "^0.2.0"
23
+ },
24
+ "devDependencies": {
25
+ "ava": "^4.3.1",
26
+ "tsd": "^0.22.0",
27
+ "xo": "^0.51.0"
28
+ },
29
+ "homepage": "https://github.com/etienne-martin/common.js#readme",
30
+ "main": "./index.js"
31
+ }
package/readme.md ADDED
@@ -0,0 +1,63 @@
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