Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@multiformats/multiaddr-matcher

multiformats108.7kApache-2.0 OR MIT1.7.2TypeScript support: included

Match different multiaddr formats

multiaddr

readme

@multiformats/multiaddr-matcher

multiformats.io codecov CI

Match different multiaddr formats

About

This module exports various matchers that can be used to infer the type of a passed multiaddr.

Example

import { multiaddr } from '@multiformats/multiaddr'
import { DNS } from '@multiformats/multiaddr-matcher'

const ma = multiaddr('/dnsaddr/example.org')

DNS.matches(ma) // true - this is a multiaddr with a DNS address at the start

Example

The default matching behaviour ignores any subsequent tuples in the multiaddr. If you want stricter matching you can use .exactMatch:

import { multiaddr } from '@multiformats/multiaddr'
import { DNS, Circuit } from '@multiformats/multiaddr-matcher'

const ma = multiaddr('/dnsaddr/example.org/p2p/QmFoo/p2p-circuit/p2p/QmBar')

DNS.exactMatch(ma) // false - this address has extra tuples after the DNS component
Circuit.matches(ma) // true
Circuit.exactMatch(ma) // true - the extra tuples are circuit relay related

Install

$ npm i @multiformats/multiaddr-matcher

Browser <script> tag

Loading this module through a script tag will make its exports available as MultiformatsMultiaddrMatcher in the global namespace.

<script src="https://unpkg.com/@multiformats/multiaddr-matcher/dist/index.min.js"></script>

API Docs

License

Licensed under either of

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.

changelog

1.7.2 (2025-05-13)

Bug Fixes

  • support ../tcp/1234/tls/http multiaddrs (#52) (a8d8607)

1.7.1 (2025-05-13)

Dependencies

  • dev: bump aegir from 45.1.4 to 46.0.1 (#51) (40e7ffe)

1.7.0 (2025-03-28)

Features

  • add matcher for /p2p/Qmfoo addresses (#46) (9477624)

1.6.0 (2024-11-13)

Features

  • match peer ids in quic addresses (#44) (b7dbfa0)

1.5.1 (2024-11-08)

Bug Fixes

1.5.0 (2024-11-04)

Features

1.4.1 (2024-11-04)

Dependencies

  • dev: bump aegir from 44.1.4 to 45.0.1 (#40) (443cd68)

1.4.0 (2024-10-28)

Features

  • support sni tuple in wss multiaddr (#39) (2b687b4)

1.3.0 (2024-10-11)

Features

  • export functions to make custom matchers (#38) (ede4bdb)

1.2.6 (2024-09-26)

Bug Fixes

  • match peer ids in tcp and dns addresses (#35) (26f2ff6)

1.2.5 (2024-09-26)

Dependencies

  • dev: bump aegir from 43.0.3 to 44.1.1 (#34) (bec98c1)

1.2.4 (2024-06-04)

Bug Fixes

  • make webrtc-direct certhashes optional and require udp (#30) (4ea2f4e)

1.2.3 (2024-06-04)

Dependencies

  • dev: bump aegir from 42.2.11 to 43.0.1 (#29) (a761d48)

1.2.2 (2024-05-28)

Bug Fixes

  • make peer ids optional for webrtc addresses (#27) (0e99f19)

1.2.1 (2024-04-30)

Bug Fixes

  • make certhashes optional in WebTransport addresses (#26) (3d6206a)

1.2.0 (2024-03-14)

Features

  • add matchers for HTTP and HTTPS addresses (#23) (8bfc218)

1.1.2 (2024-01-11)

Dependencies

  • dev: bump aegir from 41.3.5 to 42.1.0 (#22) (318e828)

1.1.1 (2024-01-07)

Dependencies

  • bump multiformats from 12.1.3 to 13.0.0 (#20) (bb82b3e)

1.1.0 (2023-11-06)

Features

  • IP_OR_DOMAIN matcher - e.g. IP or DNS multiaddrs (#19) (3ecef6b)

1.0.3 (2023-11-06)

Dependencies

  • dev: bump aegir from 40.0.13 to 41.1.8 (#18) (69890e2)

1.0.2 (2023-09-19)

Bug Fixes

  • webtrc protocol comes before peer id but after p2p-circuit (#6) (a2429db)

Trivial Changes

  • add or force update .github/workflows/js-test-and-release.yml (#5) (309e2c4)
  • delete templates (#4) (5330a86)

1.0.1 (2023-08-04)

Documentation

  • update quic example to fix typo (#1) (a23a46f)

1.0.0 (2023-08-03)

Features

Bug Fixes

  • remove zone id from ipv6 addresses (e6919e1)

Trivial Changes

Documentation