js-multiaddr-to-uri/README.md
Marcin Rataj adda9366c1 feat: assume HTTP when multiaddr ends with /tcp (#7)
This makes multiaddrs ending with `/tcp/8080` to default to HTTP unless
an explicit assumeHttp: false is passed.

We also skip default ports for HTTP and HTTPS in the URL.

Motivation:
https://github.com/ipfs/js-ipfs/pull/2358#issue-307463029

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
2019-08-21 11:09:35 +01:00

1.4 KiB

multiaddr-to-uri

Build Status dependencies Status JavaScript Style Guide

Convert a Multiaddr to a URI /dnsaddr/ipfs.io/http -> http://ipfs.io

Install

npm install multiaddr-to-uri

Usage

const toUri = require('multiaddr-to-uri')

console.log(toUri('/dnsaddr/protocol.ai/https'))
// -> https://protocol.ai

console.log(toUri('/ip4/127.0.0.1/tcp/8080'))
// -> http://127.0.0.1:8080

console.log(toUri('/ip4/127.0.0.1/tcp/8080', { assumeHttp: false }))
// -> tcp://127.0.0.1:8080

Note:

  • When /tcp is the last (terminating) protocol HTTP is assumed by default (implicit assumeHttp: true)
    • this means produced URIs will start with http:// instead of tcp://
    • passing { assumeHttp: false } disables this behavior
  • Might be lossy - e.g. a DNSv6 multiaddr
  • Can throw if the passed multiaddr:
    • is not a valid multiaddr
    • is not supported as a URI e.g. circuit

Contribute

Feel free to dive in! Open an issue or submit PRs.

License

MIT © Alan Shaw