@multiformats/multiaddr-to-uri
Convert a Multiaddr to a URI /dnsaddr/ipfs.io/http -> http://ipfs.io
$ npm install @multiformats/multiaddr-to-uri 
SYNC missed versions from official npm registry.

@multiformats/multiaddr-to-uri

multiformats.io codecov CI

Convert a Multiaddr to a URI

About

This module allows easy conversion of Multiaddrs to string URIs.

Example - Converting multiaddrs to string URIs

import { multiaddrToUri } from '@multiformats/multiaddr-to-uri'

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

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

console.log(multiaddrToUri('/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

Install

$ npm i @multiformats/multiaddr-to-uri

Browser <script> tag

Loading this module through a script tag will make it's exports available as MultiformatsMultiaddrToUri in the global namespace.

<script src="https://unpkg.com/@multiformats/multiaddr-to-uri/dist/index.min.js"></script>

API Docs

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Current Tags

  • 10.1.0                                ...           latest (5 months ago)

13 Versions

  • 10.1.0                                ...           5 months ago
  • 10.0.1                                ...           9 months ago
  • 10.0.0                                ...           9 months ago
  • 9.0.8                                ...           9 months ago
  • 9.0.7                                ...           a year ago
  • 9.0.6                                ...           a year ago
  • 9.0.5                                ...           a year ago
  • 9.0.4                                ...           2 years ago
  • 9.0.3                                ...           2 years ago
  • 9.0.2                                ...           2 years ago
  • 9.0.1                                ...           3 years ago
  • 9.0.0                                ...           3 years ago
  • 0.0.0                                ...           3 years ago
Downloads
Total 10
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE