Skip to content

Commit c6b3ff7

Browse files
committed
feat!: switch to named export
To better mirror `@multiformats/multiaddr-to-uri`, switch to a named export. BREAKING CHANGE: the default export has been replaced with a named export of `uriToMultiaddr`
1 parent d45f526 commit c6b3ff7

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ repo and examine the changes made.
2323
2424
-->
2525

26-
```js
27-
const toMultiaddr = require('uri-to-multiaddr')
26+
```typescript
27+
import { uriToMultiaddr } from '@multiformats/uri-to-multiaddr'
2828

29-
console.log(toMultiaddr('https://protocol.ai'))
29+
console.log(uriToMultiaddr('https://protocol.ai'))
3030
// -> /dns4/protocol.ai/tcp/443/https
3131
```
3232

@@ -40,10 +40,10 @@ This library assumes `/dns4` when it finds a domain name in the input string.
4040
It makes no attempt query DNS. To override the default assumption, you can pass
4141
in an options object as the second parameter to override it:
4242

43-
```js
44-
const toMultiaddr = require('uri-to-multiaddr')
43+
```typescript
44+
import { uriToMultiaddr } from '@multiformats/uri-to-multiaddr'
4545

46-
console.log(toMultiaddr('https://protocol.ai'), { defaultDnsType: 'dns6' })
46+
console.log(uriToMultiaddr('https://protocol.ai'), { defaultDnsType: 'dns6' })
4747
// -> /dns6/protocol.ai/tcp/443/https
4848
```
4949

@@ -56,7 +56,7 @@ See [test.js](./test.js) for the currently supported conversions.
5656

5757
## Related
5858

59-
- [multiaddr-to-uri](https://github.com/multiformats/js-multiaddr-to-uri) - convert it back again
59+
- [@multiformats/multiaddr-to-uri](https://github.com/multiformats/js-multiaddr-to-uri) - convert it back again
6060

6161
# Install
6262

src/index.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
22
* @packageDocumentation
33
*
4-
* ```js
5-
* const toMultiaddr = require('uri-to-multiaddr')
4+
* ```typescript
5+
* import { uriToMultiaddr } from '@multiformats/uri-to-multiaddr'
66
*
7-
* console.log(toMultiaddr('https://protocol.ai'))
7+
* console.log(uriToMultiaddr('https://protocol.ai'))
88
* // -> /dns4/protocol.ai/tcp/443/https
99
* ```
1010
*
@@ -18,10 +18,10 @@
1818
* It makes no attempt query DNS. To override the default assumption, you can pass
1919
* in an options object as the second parameter to override it:
2020
*
21-
* ```js
22-
* const toMultiaddr = require('uri-to-multiaddr')
21+
* ```typescript
22+
* import { uriToMultiaddr } from '@multiformats/uri-to-multiaddr'
2323
*
24-
* console.log(toMultiaddr('https://protocol.ai'), { defaultDnsType: 'dns6' })
24+
* console.log(uriToMultiaddr('https://protocol.ai'), { defaultDnsType: 'dns6' })
2525
* // -> /dns6/protocol.ai/tcp/443/https
2626
* ```
2727
*
@@ -34,7 +34,7 @@
3434
*
3535
* ## Related
3636
*
37-
* - [multiaddr-to-uri](https://github.com/multiformats/js-multiaddr-to-uri) - convert it back again
37+
* - [@multiformats/multiaddr-to-uri](https://github.com/multiformats/js-multiaddr-to-uri) - convert it back again
3838
*/
3939

4040
import { multiaddr } from '@multiformats/multiaddr'
@@ -66,7 +66,7 @@ export interface MultiaddrFromUriOpts {
6666
* udp://foobar.com:8080 => /dns4/foobar.com/udp/8080
6767
*/
6868

69-
export default function multiaddrFromUri (uriStr: string, opts?: MultiaddrFromUriOpts): Multiaddr {
69+
export function uriToMultiaddr (uriStr: string, opts?: MultiaddrFromUriOpts): Multiaddr {
7070
opts = opts ?? {}
7171
const defaultDnsType = opts.defaultDnsType ?? 'dns4'
7272
const { scheme, hostname, port } = parseUri(uriStr)

test/test.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from 'aegir/chai'
2-
import toMultiaddr from '../src/index.js'
2+
import { uriToMultiaddr } from '../src/index.js'
33
import type { MultiaddrFromUriOpts } from '../src/index.js'
44

55
describe('uri-to-multiaddr', () => {
@@ -33,7 +33,7 @@ describe('uri-to-multiaddr', () => {
3333
data.forEach(d => {
3434
const input = d[1]
3535
const expected = d[0]
36-
const output = toMultiaddr(input).toString()
36+
const output = uriToMultiaddr(input).toString()
3737
expect(output).to.equal(expected, `Converts ${input} to ${expected}`)
3838
})
3939
})
@@ -46,20 +46,20 @@ describe('uri-to-multiaddr', () => {
4646
]
4747

4848
data.forEach(d => {
49-
expect(toMultiaddr(d[1], d[2]).toString()).to.equal(d[0], `Converts ${d[1]} to ${d[0]} with opts ${JSON.stringify(d[2])}`)
49+
expect(uriToMultiaddr(d[1], d[2]).toString()).to.equal(d[0], `Converts ${d[1]} to ${d[0]} with opts ${JSON.stringify(d[2])}`)
5050
})
5151
})
5252

5353
it('should throw for on invalid url', () => {
5454
expect(() => {
55-
toMultiaddr('whoosh.fast')
55+
uriToMultiaddr('whoosh.fast')
5656
}).to.throw(/URL/)
5757
})
5858

5959
it('should throw for unknown protocol', () => {
6060
expect(() => {
6161
// NOTE: `data` is a valid uri protocol but isn't a valid multiaddr protocol yet
62-
toMultiaddr('data:image/svg+xml;base64,test')
62+
uriToMultiaddr('data:image/svg+xml;base64,test')
6363
}).to.throw('no protocol with name: data')
6464
})
6565
})

0 commit comments

Comments
 (0)