Skip to content

Commit c37f471

Browse files
authored
Merge branch 'main' into feat/add-unix
2 parents 72b0c54 + a7a5f2d commit c37f471

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [1.4.1](https://github.com/multiformats/js-multiaddr-matcher/compare/v1.4.0...v1.4.1) (2024-11-04)
2+
3+
### Dependencies
4+
5+
* **dev:** bump aegir from 44.1.4 to 45.0.1 ([#40](https://github.com/multiformats/js-multiaddr-matcher/issues/40)) ([443cd68](https://github.com/multiformats/js-multiaddr-matcher/commit/443cd6841c6623c6e2dc0dc7a83108f1d3dc4a0d))
6+
17
## [1.4.0](https://github.com/multiformats/js-multiaddr-matcher/compare/v1.3.0...v1.4.0) (2024-10-28)
28

39
### Features

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@multiformats/multiaddr-matcher",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "Match different multiaddr formats",
55
"license": "Apache-2.0 OR MIT",
66
"homepage": "https://github.com/multiformats/js-multiaddr-matcher#readme",
@@ -166,6 +166,6 @@
166166
"multiformats": "^13.0.0"
167167
},
168168
"devDependencies": {
169-
"aegir": "^44.1.1"
169+
"aegir": "^45.0.1"
170170
}
171171
}

src/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,23 @@ const _HTTPS = or(
461461
*/
462462
export const HTTPS = fmt(_HTTPS)
463463

464+
const _Memory = or(
465+
and(literal('memory'), string(), optional(peerId()))
466+
)
467+
468+
/**
469+
* Matches Memory addresses
470+
*
471+
* @example
472+
*
473+
* ```ts
474+
* import { Memory } from '@multiformats/multiaddr-matcher'
475+
*
476+
* Memory.matches(multiaddr('/memory/0xDEADBEEF')) // true
477+
* ```
478+
*/
479+
export const Memory = fmt(_Memory)
480+
464481
const _Unix = or(
465482
and(literal('unix'), string(), optional(peerId()))
466483
)

test/index.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,20 @@ describe('multiaddr matcher', () => {
309309
'/ip4/0.0.0.0/udp/80/http'
310310
]
311311

312+
const exactMemory = [
313+
'/memory/0xDEADBEEF',
314+
'/memory/0xDEADBEEF/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v'
315+
]
316+
317+
const goodMemory = [
318+
...exactMemory,
319+
'/memory/0xDEADBEEF/webrtc/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v'
320+
]
321+
322+
const badMemory = [
323+
'/ip4/0.0.0.0/udp/80/http'
324+
]
325+
312326
const exactUnix = [
313327
'/unix/%2Fpath%2Fto%2Funix.socket',
314328
'/unix/%2Fpath%2Fto%2Funix.socket/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v'
@@ -430,6 +444,12 @@ describe('multiaddr matcher', () => {
430444
assertMismatches(mafmt.HTTPS, badHTTPS)
431445
})
432446

447+
it('Memory addresses', () => {
448+
assertMatches(mafmt.Memory, goodMemory)
449+
assertExactMatches(mafmt.Memory, exactMemory)
450+
assertMismatches(mafmt.Memory, badMemory)
451+
})
452+
433453
it('Unix addresses', () => {
434454
assertMatches(mafmt.Unix, goodUnix)
435455
assertExactMatches(mafmt.Unix, exactUnix)

0 commit comments

Comments
 (0)