@cjser/is-port-reachable 4.0.0-cjser.2
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/dist-cjser/index.cjs +60 -0
- package/index.d.ts +30 -0
- package/index.js +32 -0
- package/license +9 -0
- package/package.json +75 -0
- package/readme.md +60 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// packages/@cjser/is-port-reachable.tmp-26-1778152797338/index.js
|
|
30
|
+
var index_exports = {};
|
|
31
|
+
__export(index_exports, {
|
|
32
|
+
default: () => isPortReachable
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(index_exports);
|
|
35
|
+
var import_node_net = __toESM(require("node:net"), 1);
|
|
36
|
+
async function isPortReachable(port, { host, timeout = 1e3 } = {}) {
|
|
37
|
+
if (typeof host !== "string") {
|
|
38
|
+
throw new TypeError("Specify a `host`");
|
|
39
|
+
}
|
|
40
|
+
const promise = new Promise(((resolve, reject) => {
|
|
41
|
+
const socket = new import_node_net.default.Socket();
|
|
42
|
+
const onError = () => {
|
|
43
|
+
socket.destroy();
|
|
44
|
+
reject();
|
|
45
|
+
};
|
|
46
|
+
socket.setTimeout(timeout);
|
|
47
|
+
socket.once("error", onError);
|
|
48
|
+
socket.once("timeout", onError);
|
|
49
|
+
socket.connect(port, host, () => {
|
|
50
|
+
socket.end();
|
|
51
|
+
resolve();
|
|
52
|
+
});
|
|
53
|
+
}));
|
|
54
|
+
try {
|
|
55
|
+
await promise;
|
|
56
|
+
return true;
|
|
57
|
+
} catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface Options {
|
|
2
|
+
/**
|
|
3
|
+
The host to check.
|
|
4
|
+
|
|
5
|
+
Can be a domain (optionally, with a sub-domain) or an IP address.
|
|
6
|
+
|
|
7
|
+
@example 'localhost'
|
|
8
|
+
*/
|
|
9
|
+
readonly host: string;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
The time to wait in milliseconds before giving up.
|
|
13
|
+
|
|
14
|
+
@default 1000
|
|
15
|
+
*/
|
|
16
|
+
readonly timeout?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
Check if a local or remote port is reachable.
|
|
21
|
+
|
|
22
|
+
@example
|
|
23
|
+
```
|
|
24
|
+
import isPortReachable from '@cjser/is-port-reachable';
|
|
25
|
+
|
|
26
|
+
console.log(await isPortReachable(80, {host: 'google.com'}));
|
|
27
|
+
//=> true
|
|
28
|
+
```
|
|
29
|
+
*/
|
|
30
|
+
export default function isPortReachable(port: number, options: Options): Promise<boolean>;
|
package/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import net from 'node:net';
|
|
2
|
+
|
|
3
|
+
export default async function isPortReachable(port, {host, timeout = 1000} = {}) {
|
|
4
|
+
if (typeof host !== 'string') {
|
|
5
|
+
throw new TypeError('Specify a `host`');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const promise = new Promise(((resolve, reject) => {
|
|
9
|
+
const socket = new net.Socket();
|
|
10
|
+
|
|
11
|
+
const onError = () => {
|
|
12
|
+
socket.destroy();
|
|
13
|
+
reject();
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
socket.setTimeout(timeout);
|
|
17
|
+
socket.once('error', onError);
|
|
18
|
+
socket.once('timeout', onError);
|
|
19
|
+
|
|
20
|
+
socket.connect(port, host, () => {
|
|
21
|
+
socket.end();
|
|
22
|
+
resolve();
|
|
23
|
+
});
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
await promise;
|
|
28
|
+
return true;
|
|
29
|
+
} catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
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,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cjser/is-port-reachable",
|
|
3
|
+
"version": "4.0.0-cjser.2",
|
|
4
|
+
"description": "Check if a local or remote port is reachable",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://code.moenext.com/3rdeye/cjser.git"
|
|
9
|
+
},
|
|
10
|
+
"funding": "https://github.com/sponsors/sindresorhus",
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "Sindre Sorhus",
|
|
13
|
+
"email": "sindresorhus@gmail.com",
|
|
14
|
+
"url": "https://sindresorhus.com"
|
|
15
|
+
},
|
|
16
|
+
"contributors": [
|
|
17
|
+
"silverwind <me@silverwind.io> (github.com/silverwind)"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": {
|
|
21
|
+
"require": "./dist-cjser/index.cjs",
|
|
22
|
+
"default": "./index.js"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "xo && ava && tsd"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"index.js",
|
|
32
|
+
"index.d.ts",
|
|
33
|
+
"dist-cjser"
|
|
34
|
+
],
|
|
35
|
+
"keywords": [
|
|
36
|
+
"port",
|
|
37
|
+
"reachable",
|
|
38
|
+
"local",
|
|
39
|
+
"remote",
|
|
40
|
+
"host",
|
|
41
|
+
"ip",
|
|
42
|
+
"localhost",
|
|
43
|
+
"address",
|
|
44
|
+
"connect",
|
|
45
|
+
"connectable",
|
|
46
|
+
"online",
|
|
47
|
+
"socket",
|
|
48
|
+
"tcp",
|
|
49
|
+
"is",
|
|
50
|
+
"check"
|
|
51
|
+
],
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"ava": "^3.15.0",
|
|
54
|
+
"tsd": "^0.17.0",
|
|
55
|
+
"xo": "^0.44.0"
|
|
56
|
+
},
|
|
57
|
+
"main": "./dist-cjser/index.cjs",
|
|
58
|
+
"cjser": {
|
|
59
|
+
"sourceVersion": "4.0.0",
|
|
60
|
+
"cjserVersion": 2,
|
|
61
|
+
"original": {
|
|
62
|
+
"name": "is-port-reachable",
|
|
63
|
+
"version": "4.0.0",
|
|
64
|
+
"exports": "./index.js",
|
|
65
|
+
"repository": "sindresorhus/is-port-reachable",
|
|
66
|
+
"files": [
|
|
67
|
+
"index.js",
|
|
68
|
+
"index.d.ts"
|
|
69
|
+
],
|
|
70
|
+
"scripts": {
|
|
71
|
+
"test": "xo && ava && tsd"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# is-port-reachable
|
|
2
|
+
|
|
3
|
+
> Check if a local or remote port is reachable
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install is-port-reachable
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import isPortReachable from 'is-port-reachable';
|
|
15
|
+
|
|
16
|
+
console.log(await isPortReachable(80, {host: 'google.com'}));
|
|
17
|
+
//=> true
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## API
|
|
21
|
+
|
|
22
|
+
### isPortReachable(options)
|
|
23
|
+
|
|
24
|
+
Returns `Promise<boolean>` for whether the port is reachable.
|
|
25
|
+
|
|
26
|
+
##### port
|
|
27
|
+
|
|
28
|
+
Type: `number`
|
|
29
|
+
|
|
30
|
+
The port to check.
|
|
31
|
+
|
|
32
|
+
#### options
|
|
33
|
+
|
|
34
|
+
Type: `object`
|
|
35
|
+
|
|
36
|
+
##### host
|
|
37
|
+
|
|
38
|
+
**Required**\
|
|
39
|
+
Type: `string`\
|
|
40
|
+
Example: `'localhost'`
|
|
41
|
+
|
|
42
|
+
The host to check.
|
|
43
|
+
|
|
44
|
+
Can be a domain (optionally, with a sub-domain) or an IP address.
|
|
45
|
+
|
|
46
|
+
##### timeout
|
|
47
|
+
|
|
48
|
+
Type: `number`\
|
|
49
|
+
Default: `1000`
|
|
50
|
+
|
|
51
|
+
The time to wait in milliseconds before giving up.
|
|
52
|
+
|
|
53
|
+
## Related
|
|
54
|
+
|
|
55
|
+
- [is-reachable](https://github.com/sindresorhus/is-reachable/) - Check if servers are reachable
|
|
56
|
+
|
|
57
|
+
## cjser
|
|
58
|
+
|
|
59
|
+
This package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
|
|
60
|
+
Original repository: https://github.com/sindresorhus/is-port-reachable
|