File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -460,3 +460,21 @@ const _HTTPS = or(
460460 * ```
461461 */
462462export const HTTPS = fmt ( _HTTPS )
463+
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 { multiaddr } from '@multiformats/multiaddr'
475+ * import { Memory } from '@multiformats/multiaddr-matcher'
476+ *
477+ * Memory.matches(multiaddr('/memory/0xDEADBEEF')) // true
478+ * ```
479+ */
480+ export const Memory = fmt ( _Memory )
Original file line number Diff line number Diff 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 function assertMatches ( p : MultiaddrMatcher , ...tests : string [ ] [ ] ) : void {
313327 tests . forEach ( ( test ) => {
314328 test . forEach ( ( testcase ) => {
@@ -416,4 +430,10 @@ describe('multiaddr matcher', () => {
416430 assertExactMatches ( mafmt . HTTPS , exactHTTPS )
417431 assertMismatches ( mafmt . HTTPS , badHTTPS )
418432 } )
433+
434+ it ( 'Memory addresses' , ( ) => {
435+ assertMatches ( mafmt . Memory , goodMemory )
436+ assertExactMatches ( mafmt . Memory , exactMemory )
437+ assertMismatches ( mafmt . Memory , badMemory )
438+ } )
419439} )
You can’t perform that action at this time.
0 commit comments