diff --git a/README.md b/README.md index fc17c5cd..23c918a9 100644 --- a/README.md +++ b/README.md @@ -35,10 +35,8 @@ A standard way to represent addresses that ```TypeScript import { multiaddr } from '@multiformats/multiaddr' -const addr = multiaddr("/ip4/127.0.0.1/udp/1234") -// Multiaddr(/ip4/127.0.0.1/udp/1234) -const addr = multiaddr("/ip4/127.0.0.1/udp/1234") +const addr = multiaddr('/ip4/127.0.0.1/udp/1234') // Multiaddr(/ip4/127.0.0.1/udp/1234) addr.bytes @@ -77,9 +75,9 @@ DNSADDR addresses can resolve to multiple multiaddrs, since there is no limit to ```TypeScript import { multiaddr, resolvers } from '@multiformats/multiaddr' -import { dnsaddr } from '@multiformats/multiaddr/resolvers' +import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers' -resolvers.set('dnsaddr', dnsaddr) +resolvers.set('dnsaddr', dnsaddrResolver) const ma = multiaddr('/dnsaddr/bootstrap.libp2p.io') @@ -88,7 +86,7 @@ const resolved = await ma.resolve({ signal: AbortSignal.timeout(5000) }) -console.info(await ma.resolve(resolved) +console.info(resolved) // [Multiaddr('/ip4/147.75...'), Multiaddr('/ip4/147.75...'), Multiaddr('/ip4/147.75...')...] ``` @@ -102,7 +100,9 @@ import { dns } from '@multiformats/dns' import { dnsJsonOverHttps } from '@multiformats/dns/resolvers' const resolver = dns({ - '.': dnsJsonOverHttps('https://cloudflare-dns.com/dns-query') + resolvers: { + '.': dnsJsonOverHttps('https://cloudflare-dns.com/dns-query') + } }) const ma = multiaddr('/dnsaddr/bootstrap.libp2p.io') diff --git a/examples/try.js b/examples/try.js deleted file mode 100644 index 60eee4c4..00000000 --- a/examples/try.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict' - -const { Multiaddr } = require('../src') -// eslint-disable-next-line no-console -const log = console.log - -const addr = new Multiaddr('/ip4/127.0.0.1/udp/1234') -log(addr) -log(addr.bytes) -log(addr.toString()) -log(new Multiaddr(addr.bytes)) - -log(addr.protoCodes()) -log(addr.protoNames()) -log(addr.protos()) - -log(addr.nodeAddress()) -log(Multiaddr.fromNodeAddress(addr.nodeAddress(), 'udp')) - -log(addr.encapsulate('/sctp/5678')) -log(addr.decapsulate('/udp')) - -const printer = new Multiaddr('/ip4/192.168.0.13/tcp/80') -const proxy = new Multiaddr('/ip4/10.20.30.40/tcp/443') -const printerOverProxy = proxy.encapsulate(printer) -log(printerOverProxy) - -const proxyAgain = printerOverProxy.decapsulate('/ip4') -log(proxyAgain) diff --git a/package.json b/package.json index 8ff6ecfd..d12ac8e4 100644 --- a/package.json +++ b/package.json @@ -154,6 +154,7 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "build": "aegir build", "test": "aegir test -f", "test:chrome": "aegir test -t browser --cov", diff --git a/src/convert.ts b/src/convert.ts index 7c48c56a..3cbb8321 100644 --- a/src/convert.ts +++ b/src/convert.ts @@ -1,9 +1,3 @@ -/** - * @packageDocumentation - * - * Provides methods for converting - */ - import { IpNet } from '@chainsafe/netmask' import { base32 } from 'multiformats/bases/base32' import { base58btc } from 'multiformats/bases/base58' diff --git a/src/index.ts b/src/index.ts index dfec2b63..47e691a7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,10 +13,8 @@ * * ```TypeScript * import { multiaddr } from '@multiformats/multiaddr' - * const addr = multiaddr("/ip4/127.0.0.1/udp/1234") - * // Multiaddr(/ip4/127.0.0.1/udp/1234) * - * const addr = multiaddr("/ip4/127.0.0.1/udp/1234") + * const addr = multiaddr('/ip4/127.0.0.1/udp/1234') * // Multiaddr(/ip4/127.0.0.1/udp/1234) * * addr.bytes @@ -55,9 +53,9 @@ * * ```TypeScript * import { multiaddr, resolvers } from '@multiformats/multiaddr' - * import { dnsaddr } from '@multiformats/multiaddr/resolvers' + * import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers' * - * resolvers.set('dnsaddr', dnsaddr) + * resolvers.set('dnsaddr', dnsaddrResolver) * * const ma = multiaddr('/dnsaddr/bootstrap.libp2p.io') * @@ -66,7 +64,7 @@ * signal: AbortSignal.timeout(5000) * }) * - * console.info(await ma.resolve(resolved) + * console.info(resolved) * // [Multiaddr('/ip4/147.75...'), Multiaddr('/ip4/147.75...'), Multiaddr('/ip4/147.75...')...] * ``` * @@ -80,7 +78,9 @@ * import { dnsJsonOverHttps } from '@multiformats/dns/resolvers' * * const resolver = dns({ - * '.': dnsJsonOverHttps('https://cloudflare-dns.com/dns-query') + * resolvers: { + * '.': dnsJsonOverHttps('https://cloudflare-dns.com/dns-query') + * } * }) * * const ma = multiaddr('/dnsaddr/bootstrap.libp2p.io') diff --git a/src/multiaddr.ts b/src/multiaddr.ts index 07895338..a99470e5 100644 --- a/src/multiaddr.ts +++ b/src/multiaddr.ts @@ -1,17 +1,3 @@ -/** - * @packageDocumentation - * - * An implementation of a Multiaddr in JavaScript - * - * @example - * - * ```js - * import { multiaddr } from '@multiformats/multiaddr' - * - * const ma = multiaddr('/ip4/127.0.0.1/tcp/1234') - * ``` - */ - import { base58btc } from 'multiformats/bases/base58' import { CID } from 'multiformats/cid' import { equals as uint8ArrayEquals } from 'uint8arrays/equals' diff --git a/src/resolvers/index.ts b/src/resolvers/index.ts index d55a8cc2..756a04d0 100644 --- a/src/resolvers/index.ts +++ b/src/resolvers/index.ts @@ -5,3 +5,4 @@ export interface Resolver { } export { dnsaddrResolver } from './dnsaddr.js' +export type { DNSADDROptions } from './dnsaddr.js'