2018-03-21 10:09:39 +00:00
|
|
|
# multiaddr-to-uri
|
2018-03-20 14:39:26 +00:00
|
|
|
|
2018-03-21 10:09:39 +00:00
|
|
|
[![Build Status](https://travis-ci.org/tableflip/multiaddr-to-uri.svg?branch=master)](https://travis-ci.org/tableflip/multiaddr-to-uri) [![dependencies Status](https://david-dm.org/tableflip/multiaddr-to-uri/status.svg)](https://david-dm.org/tableflip/multiaddr-to-uri) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
|
2018-03-20 14:39:26 +00:00
|
|
|
|
|
|
|
|
2018-03-21 10:09:39 +00:00
|
|
|
> Convert a Multiaddr to a URI /dnsaddr/ipfs.io/http -> http://ipfs.io
|
2018-03-20 14:39:26 +00:00
|
|
|
|
|
|
|
## Install
|
|
|
|
|
|
|
|
```sh
|
2018-03-21 10:09:39 +00:00
|
|
|
npm install multiaddr-to-uri
|
2018-03-20 14:39:26 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
```js
|
2018-03-21 10:09:39 +00:00
|
|
|
const toUri = require('multiaddr-to-uri')
|
2018-03-20 14:39:26 +00:00
|
|
|
|
2018-03-21 10:09:39 +00:00
|
|
|
console.log(toUri('/dnsaddr/protocol.ai/https'))
|
2018-03-20 14:39:26 +00:00
|
|
|
// -> https://protocol.ai
|
2019-08-21 10:09:35 +00:00
|
|
|
|
|
|
|
console.log(toUri('/ip4/127.0.0.1/tcp/8080'))
|
|
|
|
// -> http://127.0.0.1:8080
|
|
|
|
|
|
|
|
console.log(toUri('/ip4/127.0.0.1/tcp/8080', { assumeHttp: false }))
|
|
|
|
// -> tcp://127.0.0.1:8080
|
2018-03-20 14:39:26 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Note:
|
|
|
|
|
2019-08-21 10:09:35 +00:00
|
|
|
* 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
|
2018-03-20 14:39:26 +00:00
|
|
|
* Might be lossy - e.g. a DNSv6 multiaddr
|
|
|
|
* Can throw if the passed multiaddr:
|
|
|
|
* is not a valid multiaddr
|
2018-03-21 10:09:39 +00:00
|
|
|
* is not supported as a URI e.g. circuit
|
2018-03-20 14:39:26 +00:00
|
|
|
|
|
|
|
## Contribute
|
|
|
|
|
2018-03-21 10:09:39 +00:00
|
|
|
Feel free to dive in! [Open an issue](https://github.com/tableflip/multiaddr-to-uri/issues/new) or submit PRs.
|
2018-03-20 14:39:26 +00:00
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
|
[MIT](LICENSE) © Alan Shaw
|