Detalhes do pacote

@multiformats/uri-to-multiaddr

multiformats40.4kApache-2.0 OR MIT9.0.1

Convert a URI to a Multiaddr

readme (leia-me)

@multiformats/uri-to-multiaddr

multiformats.io codecov CI

Convert a URI to a Multiaddr

About

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

console.log(uriToMultiaddr('https://protocol.ai'))
// -> /dns4/protocol.ai/tcp/443/https

Domain names can represent one of

  • /dns4 - domain resolves to an ipv4 address (default)
  • /dns6 - domain resolves to an ipv6 address
  • /dnsaddr - domain has a DNSLink TXT record pointing to an IPFS CID

This library assumes /dns4 when it finds a domain name in the input string. It makes no attempt query DNS. To override the default assumption, you can pass in an options object as the second parameter to override it:

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

console.log(uriToMultiaddr('https://protocol.ai'), { defaultDnsType: 'dns6' })
// -> /dns6/protocol.ai/tcp/443/https

See test.js for the currently supported conversions.

Note: uri-to-multiaddr will throw if the passed URI:

  • is not a valid, according the WHATWG URL spec implementation used.
  • is not supported yet

Related

Install

$ npm i @multiformats/uri-to-multiaddr

Browser <script> tag

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

<script src="https://unpkg.com/@multiformats/uri-to-multiaddr/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 (log de mudanças)

9.0.1 (2025-03-26)

Bug Fixes

  • prefer /tls/http to /https and /tls/ws to /wss (#56) (8293d85), closes #6

9.0.0 (2025-03-26)

⚠ BREAKING CHANGES

  • returned multiaddrs created from domain names used to start with /dns4, now they start with /dns - pass defaultDnsType: 'dns4' to restore the previous behaviour

Bug Fixes

  • prefer /dns to allow resolving A or AAAA records (#55) (4fbd126), closes #8

8.1.0 (2025-03-26)

Features

8.0.1 (2025-03-26)

Dependencies

  • dev: bump aegir from 42.2.11 to 45.1.4 (#54) (dfd7fa9)

8.0.0 (2024-03-01)

⚠ BREAKING CHANGES

  • the default export has been replaced with a named export of uriToMultiaddr

Features

7.0.1 (2024-03-01)

Dependencies

  • bump @multiformats/multiaddr from 11.6.1 to 12.1.14 (#43) (239564e)
  • dev: bump aegir from 37.12.1 to 42.2.5 (#44) (e59c2d8)

7.0.0 (2022-09-21)

⚠ BREAKING CHANGES

  • this module is now ESM only

Features