File tree Expand file tree Collapse file tree 2 files changed +12
-11
lines changed
Expand file tree Collapse file tree 2 files changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,6 @@ import type { Multiaddr, Component } from '@multiformats/multiaddr'
4242 */
4343export interface Matcher {
4444 match ( parts : Component [ ] ) : Component [ ] | false
45- pattern : string
4645}
4746
4847/**
Original file line number Diff line number Diff line change 11import type { Matcher , MultiaddrMatcher } from './index.js'
22import type { Multiaddr , Component } from '@multiformats/multiaddr'
33
4+ /**
5+ * Matches a multiaddr component with the specified code but no value
6+ */
47export const code = ( code : number ) : Matcher => {
58 return {
69 match : ( vals ) => {
@@ -11,11 +14,14 @@ export const code = (code: number): Matcher => {
1114 }
1215
1316 return vals . slice ( 1 )
14- } ,
15- pattern : '/p2p/{peerid}'
17+ }
1618 }
1719}
1820
21+ /**
22+ * Matches a multiaddr component with the specified code and value. If the value
23+ * is omitted any non-undefined value is matched.
24+ */
1925export const value = ( code : number , value ?: string ) : Matcher => {
2026 return {
2127 match : ( vals ) => {
@@ -34,8 +40,7 @@ export const value = (code: number, value?: string): Matcher => {
3440 }
3541
3642 return vals . slice ( 1 )
37- } ,
38- pattern : '/p2p/{peerid}'
43+ }
3944 }
4045}
4146
@@ -49,8 +54,7 @@ export const optional = (matcher: Matcher): Matcher => {
4954 }
5055
5156 return result
52- } ,
53- pattern : `optional(${ matcher . pattern } )`
57+ }
5458 }
5559}
5660
@@ -78,8 +82,7 @@ export const or = (...matchers: Matcher[]): Matcher => {
7882 }
7983
8084 return matches
81- } ,
82- pattern : `or(${ matchers . map ( m => m . pattern ) . join ( ', ' ) } )`
85+ }
8386 }
8487}
8588
@@ -99,8 +102,7 @@ export const and = (...matchers: Matcher[]): Matcher => {
99102 }
100103
101104 return vals
102- } ,
103- pattern : `and(${ matchers . map ( m => m . pattern ) . join ( ', ' ) } )`
105+ }
104106 }
105107}
106108
You can’t perform that action at this time.
0 commit comments