File tree 2 files changed +37
-0
lines changed 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -460,3 +460,21 @@ const _HTTPS = or(
460
460
* ```
461
461
*/
462
462
export const HTTPS = fmt ( _HTTPS )
463
+
464
+ const _Unix = or (
465
+ and ( literal ( 'unix' ) , string ( ) , optional ( peerId ( ) ) )
466
+ )
467
+
468
+ /**
469
+ * Matches Unix addresses
470
+ *
471
+ * @example
472
+ *
473
+ * ```ts
474
+ * import { multiaddr } from '@multiformats/multiaddr'
475
+ * import { Unix } from '@multiformats/multiaddr-matcher'
476
+ *
477
+ * Unix.matches(multiaddr('/unix/%2Fpath%2Fto%2Funix.socket')) // true
478
+ * ```
479
+ */
480
+ export const Unix = fmt ( _Unix )
Original file line number Diff line number Diff line change @@ -309,6 +309,19 @@ describe('multiaddr matcher', () => {
309
309
'/ip4/0.0.0.0/udp/80/http'
310
310
]
311
311
312
+ const exactUnix = [
313
+ '/unix/%2Fpath%2Fto%2Funix.socket' ,
314
+ '/unix/%2Fpath%2Fto%2Funix.socket/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v'
315
+ ]
316
+
317
+ const goodUnix = [
318
+ ...exactUnix
319
+ ]
320
+
321
+ const badUnix = [
322
+ '/ip4/0.0.0.0/tcp/0/https'
323
+ ]
324
+
312
325
function assertMatches ( p : MultiaddrMatcher , ...tests : string [ ] [ ] ) : void {
313
326
tests . forEach ( ( test ) => {
314
327
test . forEach ( ( testcase ) => {
@@ -416,4 +429,10 @@ describe('multiaddr matcher', () => {
416
429
assertExactMatches ( mafmt . HTTPS , exactHTTPS )
417
430
assertMismatches ( mafmt . HTTPS , badHTTPS )
418
431
} )
432
+
433
+ it ( 'Unix addresses' , ( ) => {
434
+ assertMatches ( mafmt . Unix , goodUnix )
435
+ assertExactMatches ( mafmt . Unix , exactUnix )
436
+ assertMismatches ( mafmt . Unix , badUnix )
437
+ } )
419
438
} )
You can’t perform that action at this time.
0 commit comments