Skip to content

Commit 27c27e4

Browse files
committed
chore: add docs
1 parent 577e6b3 commit 27c27e4

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import type { Multiaddr, Component } from '@multiformats/multiaddr'
4242
*/
4343
export interface Matcher {
4444
match(parts: Component[]): Component[] | false
45-
pattern: string
4645
}
4746

4847
/**

src/utils.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { Matcher, MultiaddrMatcher } from './index.js'
22
import type { Multiaddr, Component } from '@multiformats/multiaddr'
33

4+
/**
5+
* Matches a multiaddr component with the specified code but no value
6+
*/
47
export 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+
*/
1925
export 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

0 commit comments

Comments
 (0)