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 CHANGED
@@ -1,36 +1,36 @@
1
1
  # port-numbers
2
- [![](https://img.shields.io/npm/v/port-numbers.svg?style=flat)](https://www.npmjs.org/package/port-numbers) [![](https://img.shields.io/npm/dm/port-numbers.svg)](https://www.npmjs.org/package/port-numbers)
2
+ [![](https://img.shields.io/npm/v/port-numbers.svg?style=flat)](https://www.npmjs.org/package/port-numbers) [![](https://img.shields.io/npm/dm/port-numbers.svg)](https://www.npmjs.org/package/port-numbers) [![](https://packagephobia.com/badge?p=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
- ### Installation
6
+ ### Usage
6
7
  ```
7
8
  npm i port-numbers
8
9
  ```
9
- ### Example
10
10
  ```js
11
- const portNumbers = require('port-numbers');
11
+ import {getService, getPort} from "port-numbers";
12
12
 
13
- portNumbers.getService(6379);
13
+ getService(6379);
14
14
  // { name: 'redis', description: 'An advanced key-value cache and store' }
15
- portNumbers.getService(26257);
15
+ getService(26257);
16
16
  // { name: 'cockroach', description: 'CockroachDB' }
17
- portNumbers.getService(123, 'udp');
17
+ getService(123, 'udp');
18
18
  // { name: 'ntp', description: 'Network Time Protocol' }
19
19
 
20
- portNumbers.getPort('redis');
20
+ getPort('redis');
21
21
  // { port: 6379, protocol: 'tcp', description: 'An advanced key-value cache and store' }
22
- portNumbers.getPort('cockroach');
22
+ getPort('cockroach');
23
23
  // { port: 26257, protocol: 'tcp', description: 'CockroachDB' }
24
- portNumbers.getPort('ntp', 'udp');
24
+ getPort('ntp', 'udp');
25
25
  // { port: 123, protocol: 'udp', description: 'Network Time Protocol' }
26
26
  ```
27
27
 
28
- ### APIs
29
- #### portNumbers.getService(port[, protocol])
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
- #### portNumbers.getPort(service[, protocol])
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
- "use strict";
1
+ import {readFileSync} from "node:fs";
2
2
 
3
3
  let ports, services;
4
4
 
5
5
  // port -> service
6
- module.exports.getService = (port, protocol = "tcp") => {
6
+ export function getService(port, protocol = "tcp") {
7
7
  if (typeof port !== "number") throw new Error("expected a 'number'");
8
- if (!ports) ports = require("./ports.json");
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
- module.exports.getPort = (service, protocol = "tcp") => {
13
+ export function getPort(service, protocol = "tcp") {
14
14
  if (typeof service !== "string") throw new Error("expected a 'string'");
15
- if (!services) services = require("./services.json");
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.filter(port => /\w+$/.exec(port)[0] === protocol)[0];
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": "6.0.0",
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 <me@silverwind.io> (https://github.com/silverwind)",
6
- "license": "BSD-2-Clause",
5
+ "author": "silverwind",
7
6
  "repository": "silverwind/port-numbers",
8
- "scripts": {
9
- "test": "make test"
10
- },
7
+ "license": "BSD-2-Clause",
8
+ "type": "module",
9
+ "sideEffects": false,
11
10
  "engines": {
12
- "node": ">=10"
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
- "csv-parse": "4.8.8",
32
- "eslint": "6.8.0",
33
- "eslint-config-silverwind": "11.0.2",
34
- "got": "10.7.0",
35
- "jest": "25.2.3",
36
- "updates": "10.2.6",
37
- "versions": "8.2.7"
38
- },
39
- "jest": {
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
  }