Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@multiformats/multiaddr-to-uri

multiformats282.8kApache-2.0 OR MIT11.0.0TypeScript support: included

Convert a Multiaddr to a URI

URL, multiaddr, toString

readme

@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.

changelog

11.0.0 (2024-11-08)

⚠ BREAKING CHANGES

  • p2p-webrtc-direct/p2p-websocket-star support has been removed

Bug Fixes

  • remove deprecated transports and do not append peer ids (#155) (161329c)

Dependencies

  • dev: bump aegir from 44.1.4 to 45.0.1 (#156) (b82d7c0)

10.1.2 (2024-10-28)

Bug Fixes

  • handle ports in multiaddrs with SNI tuples (#154) (9fd5bdb)

10.1.1 (2024-10-26)

Dependencies

  • dev: bump aegir from 43.0.3 to 44.1.4 (#153) (d6cc0a0)

10.1.0 (2024-06-06)

Features

Dependencies

  • dev: bump aegir from 42.2.11 to 43.0.1 (#147) (266001f)

10.0.1 (2024-02-05)

Trivial Changes

Documentation

10.0.0 (2024-02-05)

⚠ BREAKING CHANGES

  • dns addresses previously returned domain names, now they return URLs

Bug Fixes

  • always return a URI for DNS addresses (#130) (dae8350), closes #8

9.0.8 (2024-02-05)

Trivial Changes

  • add or force update .github/workflows/js-test-and-release.yml (#137) (1b886c6)
  • delete templates [skip ci] (#136) (92fae51)

Dependencies

  • dev: bump aegir from 39.0.13 to 41.0.5 (#145) (a90dca4)

9.0.7 (2023-05-19)

Bug Fixes

9.0.6 (2023-05-19)

Dependencies

  • dev: bump aegir from 38.1.8 to 39.0.7 (#128) (8c84ed3)

9.0.5 (2023-05-19)

Bug Fixes

  • Rewrite to interpret multiaddr from right to left (#120) (681d4e3)

9.0.4 (2023-03-20)

Dependencies

  • bump @multiformats/multiaddr from 11.6.1 to 12.0.0 (#123) (dcba0c8)

9.0.3 (2023-03-17)

Dependencies

  • dev: bump aegir from 37.12.1 to 38.1.7 (#119) (f3ee76d)

9.0.2 (2022-09-21)

Trivial Changes

Dependencies

  • update @multiformats/multiaddr to 11.0.0 (#104) (d4a1d16)

9.0.1 (2022-01-08)

Trivial Changes