port-numbers 6.0.0 → 7.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 +13 -13
- package/index.js +8 -8
- package/package.json +18 -31
- package/ports.json +726 -234
- package/services.json +505 -135
- package/LICENSE +0 -22
package/README.md
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
# port-numbers
|
|
2
|
-
[](https://www.npmjs.org/package/port-numbers) [](https://www.npmjs.org/package/port-numbers)
|
|
2
|
+
[](https://www.npmjs.org/package/port-numbers) [](https://www.npmjs.org/package/port-numbers) [](https://packagephobia.com/result?p=port-numbers)
|
|
3
|
+
|
|
3
4
|
> Get information on network port numbers and services, based on [IANA's public listing](http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml).
|
|
4
5
|
|
|
5
|
-
###
|
|
6
|
+
### Usage
|
|
6
7
|
```
|
|
7
8
|
npm i port-numbers
|
|
8
9
|
```
|
|
9
|
-
### Example
|
|
10
10
|
```js
|
|
11
|
-
|
|
11
|
+
import {getService, getPort} from "port-numbers";
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
getService(6379);
|
|
14
14
|
// { name: 'redis', description: 'An advanced key-value cache and store' }
|
|
15
|
-
|
|
15
|
+
getService(26257);
|
|
16
16
|
// { name: 'cockroach', description: 'CockroachDB' }
|
|
17
|
-
|
|
17
|
+
getService(123, 'udp');
|
|
18
18
|
// { name: 'ntp', description: 'Network Time Protocol' }
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
getPort('redis');
|
|
21
21
|
// { port: 6379, protocol: 'tcp', description: 'An advanced key-value cache and store' }
|
|
22
|
-
|
|
22
|
+
getPort('cockroach');
|
|
23
23
|
// { port: 26257, protocol: 'tcp', description: 'CockroachDB' }
|
|
24
|
-
|
|
24
|
+
getPort('ntp', 'udp');
|
|
25
25
|
// { port: 123, protocol: 'udp', description: 'Network Time Protocol' }
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
###
|
|
29
|
-
####
|
|
28
|
+
### API
|
|
29
|
+
#### getService(port[, protocol])
|
|
30
30
|
- `port` *Number* : the port to lookup. Required.
|
|
31
31
|
- `protocol` *String* : the protocol. Default: `tcp`.
|
|
32
32
|
|
|
33
|
-
####
|
|
33
|
+
#### getPort(service[, protocol])
|
|
34
34
|
- `service` *String* : the service to lookup. Required.
|
|
35
35
|
- `protocol` *String* : the protocol. Default: `tcp`.
|
|
36
36
|
|
package/index.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
import {readFileSync} from "node:fs";
|
|
2
2
|
|
|
3
3
|
let ports, services;
|
|
4
4
|
|
|
5
5
|
// port -> service
|
|
6
|
-
|
|
6
|
+
export function getService(port, protocol = "tcp") {
|
|
7
7
|
if (typeof port !== "number") throw new Error("expected a 'number'");
|
|
8
|
-
if (!ports) ports =
|
|
8
|
+
if (!ports) ports = JSON.parse(readFileSync(new URL("ports.json", import.meta.url)));
|
|
9
9
|
return ports[`${port}/${protocol}`] || null;
|
|
10
|
-
}
|
|
10
|
+
}
|
|
11
11
|
|
|
12
12
|
// service -> port
|
|
13
|
-
|
|
13
|
+
export function getPort(service, protocol = "tcp") {
|
|
14
14
|
if (typeof service !== "string") throw new Error("expected a 'string'");
|
|
15
|
-
if (!services) services =
|
|
15
|
+
if (!services) services = JSON.parse(readFileSync(new URL("services.json", import.meta.url)));
|
|
16
16
|
|
|
17
17
|
// services are always lowercase
|
|
18
18
|
const entry = services[service.toLowerCase()];
|
|
19
19
|
if (!entry) return null;
|
|
20
20
|
|
|
21
21
|
// filter non-matching protocols
|
|
22
|
-
const port = entry.ports.
|
|
22
|
+
const port = entry.ports.find(port => /\w+$/.exec(port)[0] === protocol);
|
|
23
23
|
if (!port) return null;
|
|
24
24
|
|
|
25
25
|
// return the first matching port
|
|
@@ -28,4 +28,4 @@ module.exports.getPort = (service, protocol = "tcp") => {
|
|
|
28
28
|
protocol: /\w+$/.exec(port)[0],
|
|
29
29
|
description: entry.description
|
|
30
30
|
};
|
|
31
|
-
}
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,42 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "port-numbers",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Get information on network port numbers and services, based on IANA's public listing",
|
|
5
|
-
"author": "silverwind
|
|
6
|
-
"license": "BSD-2-Clause",
|
|
5
|
+
"author": "silverwind",
|
|
7
6
|
"repository": "silverwind/port-numbers",
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
"license": "BSD-2-Clause",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"sideEffects": false,
|
|
11
10
|
"engines": {
|
|
12
|
-
"node": ">=
|
|
11
|
+
"node": ">=16"
|
|
13
12
|
},
|
|
14
13
|
"files": [
|
|
15
|
-
"index.js",
|
|
16
|
-
"ports.json",
|
|
17
|
-
"services.json"
|
|
18
|
-
],
|
|
19
|
-
"keywords": [
|
|
20
|
-
"port",
|
|
21
|
-
"port-numbers",
|
|
22
|
-
"numbers",
|
|
23
|
-
"tcp",
|
|
24
|
-
"udp",
|
|
25
|
-
"network",
|
|
26
|
-
"networking",
|
|
27
|
-
"iana",
|
|
28
|
-
"well-known"
|
|
14
|
+
"./index.js",
|
|
15
|
+
"./ports.json",
|
|
16
|
+
"./services.json"
|
|
29
17
|
],
|
|
30
18
|
"devDependencies": {
|
|
31
|
-
"
|
|
32
|
-
"eslint": "
|
|
33
|
-
"eslint-config-silverwind": "
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"verbose": false
|
|
19
|
+
"d3-dsv": "3.0.1",
|
|
20
|
+
"eslint": "8.40.0",
|
|
21
|
+
"eslint-config-silverwind": "71.0.3",
|
|
22
|
+
"fetch-enhanced": "11.1.1",
|
|
23
|
+
"got": "12.6.0",
|
|
24
|
+
"undici": "5.22.1",
|
|
25
|
+
"updates": "14.1.0",
|
|
26
|
+
"versions": "11.0.0",
|
|
27
|
+
"vitest": "0.31.0"
|
|
41
28
|
}
|
|
42
29
|
}
|