https://github.com/multiformats/js-uri-to-multiaddr
Convert a URI to a Multiaddr: https://protocol.ai -> /dns4/protocol.ai/tcp/443/https
https://github.com/multiformats/js-uri-to-multiaddr
Last synced: about 1 year ago
JSON representation
Convert a URI to a Multiaddr: https://protocol.ai -> /dns4/protocol.ai/tcp/443/https
- Host: GitHub
- URL: https://github.com/multiformats/js-uri-to-multiaddr
- Owner: multiformats
- License: other
- Created: 2018-10-02T11:00:25.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-08-12T10:39:52.000Z (almost 2 years ago)
- Last Synced: 2024-10-29T01:21:34.301Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 371 KB
- Stars: 3
- Watchers: 14
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @multiformats/uri-to-multiaddr
[](http://multiformats.io)
[](https://codecov.io/gh/multiformats/js-uri-to-multiaddr)
[](https://github.com/multiformats/js-uri-to-multiaddr/actions/workflows/js-test-and-release.yml?query=branch%3Amain)
> Convert a URI to a Multiaddr
# About
```typescript
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](https://docs.ipfs.io/guides/concepts/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:
```typescript
import { uriToMultiaddr } from '@multiformats/uri-to-multiaddr'
console.log(uriToMultiaddr('https://protocol.ai'), { defaultDnsType: 'dns6' })
// -> /dns6/protocol.ai/tcp/443/https
```
See [test.js](./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
- [@multiformats/multiaddr-to-uri](https://github.com/multiformats/js-multiaddr-to-uri) - convert it back again
# Install
```console
$ npm i @multiformats/uri-to-multiaddr
```
## Browser `` tag
Loading this module through a script tag will make it's exports available as `MultiformatsUriToMultiaddr` in the global namespace.
```html
<script src="https://unpkg.com/@multiformats/uri-to-multiaddr/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.