2.0.2 • Published 8 years ago

host-to-port v2.0.2

Weekly downloads
16
License
-
Repository
github
Last release
8 years ago

Host-To-Port

Convert a hostname /[a-z0-9\-\.]{3,255}/ into a valid port.

Installation

Npm

npm install host-to-port

Example

var toPort = require('host-to-port');

toPort("abc.com"); //-> 10307
toPort("abcd.com"); //-> 10357

// Default port range is 10000-49151, you can set this to whatever you need.
// Narrowing the range will increase the likelyhood of collisions.

toPort("abc.com", [10000, 20000]); //-> 10307

Limitations

A hostname will always be converted into a same valid port. However since the number of valid hostnames is 39^255 which JavaScript tells me is infinity there will be collisions. For typical use I haven't found many collisions with this algorithm but they do exist and can happen.

Contributions

  • Use gulp to run tests.

Please feel free to create a PR!

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago