File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -496,3 +496,21 @@ const _Memory = or(
496
496
* ```
497
497
*/
498
498
export const Memory = fmt ( _Memory )
499
+
500
+ const _Unix = or (
501
+ and ( literal ( 'unix' ) , string ( ) , optional ( peerId ( ) ) )
502
+ )
503
+
504
+ /**
505
+ * Matches Unix addresses
506
+ *
507
+ * @example
508
+ *
509
+ * ```ts
510
+ * import { multiaddr } from '@multiformats/multiaddr'
511
+ * import { Unix } from '@multiformats/multiaddr-matcher'
512
+ *
513
+ * Unix.matches(multiaddr('/unix/%2Fpath%2Fto%2Funix.socket')) // true
514
+ * ```
515
+ */
516
+ export const Unix = fmt ( _Unix )
Original file line number Diff line number Diff line change @@ -372,6 +372,19 @@ describe('multiaddr matcher', () => {
372
372
'/memory/0xDEADBEEF'
373
373
]
374
374
375
+ const exactUnix = [
376
+ '/unix/%2Fpath%2Fto%2Funix.socket' ,
377
+ '/unix/%2Fpath%2Fto%2Funix.socket/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v'
378
+ ]
379
+
380
+ const goodUnix = [
381
+ ...exactUnix
382
+ ]
383
+
384
+ const badUnix = [
385
+ '/ip4/0.0.0.0/tcp/0/https'
386
+ ]
387
+
375
388
function assertMatches ( p : MultiaddrMatcher , ...tests : string [ ] [ ] ) : void {
376
389
tests . forEach ( ( test ) => {
377
390
test . forEach ( ( testcase ) => {
@@ -498,4 +511,10 @@ describe('multiaddr matcher', () => {
498
511
assertExactMatches ( mafmt . PEER_ID , exactPeer )
499
512
assertMismatches ( mafmt . PEER_ID , badPeer )
500
513
} )
514
+
515
+ it ( 'Unix addresses' , ( ) => {
516
+ assertMatches ( mafmt . Unix , goodUnix )
517
+ assertExactMatches ( mafmt . Unix , exactUnix )
518
+ assertMismatches ( mafmt . Unix , badUnix )
519
+ } )
501
520
} )
You can’t perform that action at this time.
0 commit comments