@multiformats/uri-to-multiaddr
TypeScript icon, indicating that this package has built-in type declarations

7.0.0 • Public • Published

@multiformats/uri-to-multiaddr

multiformats.io codecov CI

Convert a URI to a Multiaddr: https://multiformats.io -> /dns4/multiformats.io/tcp/443/https

Table of contents

Install

$ npm i @multiformats/uri-to-multiaddr

Usage

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

console.log(toMultiaddr('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:

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

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

Contribute

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

License

Licensed under either of

Contribute

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.

Keywords

none

Install

npm i @multiformats/uri-to-multiaddr

DownloadsWeekly Downloads

1,810

Version

7.0.0

License

Apache-2.0 OR MIT

Unpacked Size

17 kB

Total Files

8

Last publish

Collaborators

  • npm-service-account-multiformats
  • alanshaw
  • vascosantos
  • achingbrain
  • lidel
  • rvagg
  • daviddias
  • vmx
  • mikeal
  • hugomrdias