JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4899
  • Score
    100M100P100Q32979F
  • License MIT

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

Package Exports

  • uri-to-multiaddr

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (uri-to-multiaddr) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

uri-to-multiaddr

Build Status dependencies Status JavaScript Style Guide

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

Install

npm install 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

Contribute

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

License

MIT © TABLEFLIP