https://github.com/multiformats/js-multiaddr-to-uri
Convert a Multiaddr to a URI /dnsaddr/ipfs.io/http -> http://ipfs.io
https://github.com/multiformats/js-multiaddr-to-uri
Last synced: about 1 year ago
JSON representation
Convert a Multiaddr to a URI /dnsaddr/ipfs.io/http -> http://ipfs.io
- Host: GitHub
- URL: https://github.com/multiformats/js-multiaddr-to-uri
- Owner: multiformats
- License: other
- Created: 2018-03-20T14:38:47.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2024-11-08T18:55:51.000Z (over 1 year ago)
- Last Synced: 2024-12-11T09:29:04.323Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 501 KB
- Stars: 7
- Watchers: 13
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @multiformats/multiaddr-to-uri
[](http://multiformats.io)
[](https://codecov.io/gh/multiformats/js-multiaddr-to-uri)
[](https://github.com/multiformats/js-multiaddr-to-uri/actions/workflows/js-test-and-release.yml?query=branch%3Amain)
> Convert a Multiaddr to a URI
# About
This module allows easy conversion of Multiaddrs to string URIs.
## Example - Converting multiaddrs to string URIs
```js
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
```console
$ npm i @multiformats/multiaddr-to-uri
```
## Browser `` tag
Loading this module through a script tag will make it's exports available as `MultiformatsMultiaddrToUri` in the global namespace.
```html
<script src="https://unpkg.com/@multiformats/multiaddr-to-uri/dist/index.min.js">
```
# API Docs
-
# License
Licensed under either of
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / )
- MIT ([LICENSE-MIT](LICENSE-MIT) / )
# 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.