short-host
v0.1.1
Published
Represent any IPv4 based host like `A.B.C.D:P` as a short sequence of 1 to 10 chars
Readme
short-host
Represent any IPv4 based host like A.B.C.D:P as a short sequence of 1 to 10 chars:
A,B,CandDare IPv4 numbers from0to255Pis a network port number from0to65535- Generated chars are lowercase letters or numbers (only
2,3,4,5,6or7)
Examples
192.168.0.15:8080=>p192.168.0.27:8080=>bw192.168.1.182:5173=>3n192.168.0.27:4200=>bwd192.168.1.85:3000=>vkc192.168.1.111:443=>w6os192.168.27.81:4444=>dniqr192.168.27.81:7812=>dnixuq4.15.167.243:8080=>aqh2p4y4.15.167.243:123=>aqh2p44s4.15.167.243:2345=>aqh2p42j64.15.167.243:56789=>aqh2p4zxov
Why?
- I wanted to have fun with a silly idea
- I sometimes need to browse a local dev server on another device of my local network but it's very annoying to type the IP address and the port
How to use?
- Use the bookmarklet below to generate the short host code from device A
- Add this bookmark to browse the short host on device B
bookmarklet:
javascript:(function()%7Bvar%20url%20%3D%20new%20URL('https%3A%2F%2Fhsablonniere.github.io%2Fshort-host')%3B%0Aurl.searchParams.set('host'%2C%20location.host)%3B%0Alocation.href%20%3D%20url.toString()%3B%7D)()%3Bnpm library
You can use this in your projects to display short hosts.
Installation
npm install short-hostJavaScript usage
import { toShortHost, fromShortHost } from 'short-host';
console.log(toShortHost('192.168.0.27:8080'));
// => "bw"
console.log(fromShortHost('bw'));
// => "192.168.0.27:8080"Details
The main goals and constraints were:
- Focus on local IPs starting with
192.168, especially192.168.0and192.168.1. - Favor HTTP ports often used in local dev like
8080,5173or3000 - Be able to represent any IPv4 and port
You can have a look at IMPLEMENTATION_DETAILS.md to learn how the encoding/decoding works.
