npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

named-port

4.0.1

@juliangruber

npmHomeRepoSnykSocket
Downloads:579
$ npm install named-port
DailyWeeklyMonthlyYearly

named-port

Deterministically map service names to port numbers (1024,65535).

Usage

$ npx named-port Filecoin Station Core
51806
import namedPort from 'named-port'

console.log(namedPort('Filecoin Station Core'))

Custom port range

console.log(namedPort('Filecoin Station Core', { min: 3000, max: 10000 }))

Algorithm

port = min + H(name) % (max - min + 1)
  • H(name): hash = 0; for each char c: hash = (hash * 31 + c.charCodeAt(0)) >>> 0
  • 31: prime multiplier for even distribution
  • >>> 0: 32-bit unsigned overflow handling