@@ -348,7 +348,23 @@ const _IP = or(
348
348
_IP6
349
349
)
350
350
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 )
352
368
353
369
/**
354
370
* Matches ip4 addresses.
@@ -401,8 +417,8 @@ export const IP6 = fmt(_IP6)
401
417
*/
402
418
export const IP = fmt ( _IP )
403
419
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 ( ) )
406
422
407
423
const TCP_OR_UDP = or ( _TCP , _UDP )
408
424
@@ -468,7 +484,7 @@ export const QUIC = fmt(_QUIC)
468
484
export const QUICV1 = fmt ( _QUICV1 )
469
485
470
486
const _WEB = or (
471
- IP_OR_DOMAIN ,
487
+ _IP_OR_DOMAIN ,
472
488
_TCP ,
473
489
_UDP ,
474
490
_QUIC ,
@@ -549,7 +565,7 @@ const _P2P = or(
549
565
_WebSocketsSecure ,
550
566
and ( _TCP , optional ( peerId ( ) ) ) ,
551
567
and ( QUIC_V0_OR_V1 , optional ( peerId ( ) ) ) ,
552
- and ( IP_OR_DOMAIN , optional ( peerId ( ) ) ) ,
568
+ and ( _IP_OR_DOMAIN , optional ( peerId ( ) ) ) ,
553
569
_WebRTCDirect ,
554
570
_WebTransport ,
555
571
peerId ( )
0 commit comments