|
1 |
| -# @multiformats/multiaddr-matcher <!-- omit in toc --> |
2 |
| - |
3 | 1 | [](http://multiformats.io)
|
4 | 2 | [](https://codecov.io/gh/multiformats/js-multiaddr-matcher)
|
5 | 3 | [](https://github.com/multiformats/js-multiaddr-matcher/actions/workflows/js-test-and-release.yml?query=branch%3Amain)
|
6 | 4 |
|
7 | 5 | > Match different multiaddr formats
|
8 | 6 |
|
9 |
| -## Table of contents <!-- omit in toc --> |
| 7 | +# About |
| 8 | + |
| 9 | +This module exports various matchers that can be used to infer the type of a |
| 10 | +passed multiaddr. |
| 11 | + |
| 12 | +## Example |
| 13 | + |
| 14 | +```ts |
| 15 | +import { multiaddr } from '@multiformats/multiaddr' |
| 16 | +import { DNS } from '@multiformats/multiaddr-matcher' |
| 17 | + |
| 18 | +const ma = multiaddr('/dnsaddr/example.org') |
| 19 | + |
| 20 | +DNS.matches(ma) // true - this is a multiaddr with a DNS address at the start |
| 21 | +``` |
| 22 | + |
| 23 | +## Example |
| 24 | + |
| 25 | +The default matching behaviour ignores any subsequent tuples in the multiaddr. |
| 26 | +If you want stricter matching you can use `.exactMatch`: |
10 | 27 |
|
11 |
| -- [Install](#install) |
12 |
| - - [Browser `<script>` tag](#browser-script-tag) |
13 |
| -- [API Docs](#api-docs) |
14 |
| -- [License](#license) |
15 |
| -- [Contribution](#contribution) |
| 28 | +```ts |
| 29 | +import { multiaddr } from '@multiformats/multiaddr' |
| 30 | +import { DNS, Circuit } from '@multiformats/multiaddr-matcher' |
| 31 | + |
| 32 | +const ma = multiaddr('/dnsaddr/example.org/p2p/QmFoo/p2p-circuit/p2p/QmBar') |
| 33 | + |
| 34 | +DNS.exactMatch(ma) // false - this address has extra tuples after the DNS component |
| 35 | +Circuit.matches(ma) // true |
| 36 | +Circuit.exactMatch(ma) // true - the extra tuples are circuit relay related |
| 37 | +``` |
16 | 38 |
|
17 |
| -## Install |
| 39 | +# Install |
18 | 40 |
|
19 | 41 | ```console
|
20 | 42 | $ npm i @multiformats/multiaddr-matcher
|
21 | 43 | ```
|
22 | 44 |
|
23 |
| -### Browser `<script>` tag |
| 45 | +## Browser `<script>` tag |
24 | 46 |
|
25 | 47 | Loading this module through a script tag will make it's exports available as `MultiformatsMultiaddrMatcher` in the global namespace.
|
26 | 48 |
|
27 | 49 | ```html
|
28 | 50 | <script src="https://unpkg.com/@multiformats/multiaddr-matcher/dist/index.min.js"></script>
|
29 | 51 | ```
|
30 | 52 |
|
31 |
| -## API Docs |
| 53 | +# API Docs |
32 | 54 |
|
33 | 55 | - <https://multiformats.github.io/js-multiaddr-matcher>
|
34 | 56 |
|
35 |
| -## License |
| 57 | +# License |
36 | 58 |
|
37 | 59 | Licensed under either of
|
38 | 60 |
|
39 | 61 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
|
40 | 62 | - MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
|
41 | 63 |
|
42 |
| -## Contribution |
| 64 | +# Contribution |
43 | 65 |
|
44 | 66 | 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.
|
0 commit comments