@@ -348,7 +348,23 @@ const _IP = or(
348348 _IP6
349349)
350350
351- const IP_OR_DOMAIN = or ( _IP , _DNS , _DNS4 , _DNS6 , _DNSADDR )
351+ const _IP_OR_DOMAIN = or ( _IP , _DNS , _DNS4 , _DNS6 , _DNSADDR )
352+
353+ /**
354+ * A matcher for addresses that start with IP or DNS tuples.
355+ *
356+ * @example
357+ *
358+ * ```ts
359+ * import { multiaddr } from '@multiformats/multiaddr'
360+ * import { IP_OR_DOMAIN } from '@multiformats/multiaddr-matcher'
361+ *
362+ * IP_OR_DOMAIN.matches(multiaddr('/ip4/123.123.123.123/p2p/QmFoo')) // true
363+ * IP_OR_DOMAIN.matches(multiaddr('/dns/example.com/p2p/QmFoo')) // true
364+ * IP_OR_DOMAIN.matches(multiaddr('/p2p/QmFoo')) // false
365+ * ```
366+ */
367+ export const IP_OR_DOMAIN = fmt ( _IP_OR_DOMAIN )
352368
353369/**
354370 * Matches ip4 addresses.
@@ -401,8 +417,8 @@ export const IP6 = fmt(_IP6)
401417 */
402418export const IP = fmt ( _IP )
403419
404- const _TCP = and ( IP_OR_DOMAIN , literal ( 'tcp' ) , number ( ) )
405- const _UDP = and ( IP_OR_DOMAIN , literal ( 'udp' ) , number ( ) )
420+ const _TCP = and ( _IP_OR_DOMAIN , literal ( 'tcp' ) , number ( ) )
421+ const _UDP = and ( _IP_OR_DOMAIN , literal ( 'udp' ) , number ( ) )
406422
407423const TCP_OR_UDP = or ( _TCP , _UDP )
408424
@@ -468,7 +484,7 @@ export const QUIC = fmt(_QUIC)
468484export const QUICV1 = fmt ( _QUICV1 )
469485
470486const _WEB = or (
471- IP_OR_DOMAIN ,
487+ _IP_OR_DOMAIN ,
472488 _TCP ,
473489 _UDP ,
474490 _QUIC ,
@@ -549,7 +565,7 @@ const _P2P = or(
549565 _WebSocketsSecure ,
550566 and ( _TCP , optional ( peerId ( ) ) ) ,
551567 and ( QUIC_V0_OR_V1 , optional ( peerId ( ) ) ) ,
552- and ( IP_OR_DOMAIN , optional ( peerId ( ) ) ) ,
568+ and ( _IP_OR_DOMAIN , optional ( peerId ( ) ) ) ,
553569 _WebRTCDirect ,
554570 _WebTransport ,
555571 peerId ( )
0 commit comments