Socket
Socket
Sign inDemoInstall

port-numbers

Package Overview
Dependencies
Maintainers
1
Versions
155
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

port-numbers - npm Package Compare versions

Comparing version 5.0.12 to 6.0.0

43

index.js
"use strict";
const portNumbers = module.exports = {};
let ports, services;
// port -> service
portNumbers.getService = function getService(port, protocol) {
if (typeof port !== "number") {
throw new Error("expected a 'number'");
}
if (!protocol) {
protocol = "tcp";
}
if (!ports) {
ports = require("./ports.json");
}
return ports[port + "/" + protocol] || null;
module.exports.getService = (port, protocol = "tcp") => {
if (typeof port !== "number") throw new Error("expected a 'number'");
if (!ports) ports = require("./ports.json");
return ports[`${port}/${protocol}`] || null;
};
// service -> port
portNumbers.getPort = function getPort(service, protocol) {
if (typeof service !== "string") {
throw new Error("expected a 'string'");
}
module.exports.getPort = (service, protocol = "tcp") => {
if (typeof service !== "string") throw new Error("expected a 'string'");
if (!services) services = require("./services.json");
if (!protocol) {
protocol = "tcp";
}
if (!services) {
services = require("./services.json");
}
// services are always lowercase
const entry = services[service.toLowerCase()];
if (!entry) {
return null;
}
if (!entry) return null;
// filter non-matching protocols
const port = entry.ports.filter(port => /\w+$/.exec(port)[0] === protocol)[0];
if (!port) return null;
if (!port) {
return null;
}
// return the first matching port

@@ -51,0 +26,0 @@ return {

{
"name": "port-numbers",
"version": "5.0.12",
"version": "6.0.0",
"description": "Get information on network port numbers and services, based on IANA's public listing",

@@ -12,4 +12,9 @@ "author": "silverwind <me@silverwind.io> (https://github.com/silverwind)",

"engines": {
"node": ">=8"
"node": ">=10"
},
"files": [
"index.js",
"ports.json",
"services.json"
],
"keywords": [

@@ -26,15 +31,14 @@ "port",

],
"files": [
"index.js",
"ports.json",
"services.json"
],
"devDependencies": {
"csv-parse": "4.6.5",
"eslint": "6.6.0",
"eslint-config-silverwind": "5.0.0",
"got": "9.6.0",
"updates": "9.0.1",
"versions": "7.0.2"
"csv-parse": "4.8.8",
"eslint": "6.8.0",
"eslint-config-silverwind": "11.0.2",
"got": "10.7.0",
"jest": "25.2.3",
"updates": "10.2.6",
"versions": "8.2.7"
},
"jest": {
"verbose": false
}
}
# port-numbers
[![](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://api.travis-ci.org/silverwind/port-numbers.svg?style=flat)](https://travis-ci.org/silverwind/port-numbers)
[![](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)
> 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).

@@ -7,3 +7,3 @@

```
$ npm i port-numbers
npm i port-numbers
```

@@ -10,0 +10,0 @@ ### Example

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc