port-numbers
Advanced tools
Comparing version
58
index.js
"use strict"; | ||
var pn = {}, | ||
ports = require("./ports.json"), | ||
services = require("./services.json"); | ||
var pn = {}; | ||
var ports = require("./ports.json"); | ||
var services = require("./services.json"); | ||
// port -> service | ||
pn.getService = function getService(port, protocol) { | ||
if (typeof port !== "number") { | ||
throw new Error("expected a 'number'"); | ||
} | ||
if (typeof port !== "number") { | ||
throw new Error("expected a 'number'"); | ||
} | ||
if (!protocol) { | ||
protocol = "tcp"; | ||
} | ||
if (!protocol) { | ||
protocol = "tcp"; | ||
} | ||
return ports[port + "/" + protocol] || null; | ||
return ports[port + "/" + protocol] || null; | ||
}; | ||
@@ -23,26 +23,26 @@ | ||
pn.getPort = function getPort(service, protocol) { | ||
var port, entry; | ||
if (typeof service !== "string") { | ||
throw new Error("expected a 'string'"); | ||
} | ||
var port, entry; | ||
if (typeof service !== "string") { | ||
throw new Error("expected a 'string'"); | ||
} | ||
if (!protocol) { | ||
protocol = "tcp"; | ||
} | ||
if (!protocol) { | ||
protocol = "tcp"; | ||
} | ||
// services are always lowercase | ||
entry = services[service.toLowerCase()]; | ||
if (entry) { | ||
// filter non-matching protocols | ||
port = entry.ports.filter(function (port) { | ||
return /\w+$/.exec(port)[0] === protocol; | ||
})[0]; | ||
// return the first matching port | ||
if (port) { | ||
return {port: Number(/^\d+/.exec(port)[0]), protocol: /\w+$/.exec(port)[0], description: entry.description}; | ||
} | ||
// services are always lowercase | ||
entry = services[service.toLowerCase()]; | ||
if (entry) { | ||
// filter non-matching protocols | ||
port = entry.ports.filter(function (port) { | ||
return /\w+$/.exec(port)[0] === protocol; | ||
})[0]; | ||
// return the first matching port | ||
if (port) { | ||
return {port: Number(/^\d+/.exec(port)[0]), protocol: /\w+$/.exec(port)[0], description: entry.description}; | ||
} | ||
return null; | ||
} | ||
return null; | ||
}; | ||
module.exports = pn; |
{ | ||
"name": "port-numbers", | ||
"version": "1.1.18", | ||
"version": "1.1.19", | ||
"description": "Get the information on network port numbers, based on IANA's public listing", | ||
@@ -5,0 +5,0 @@ "author": "silverwind <me@silverwind.io> (https://github.com/silverwind)", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1738409
0.01%89230
0.02%