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 @@ -460,3 +460,21 @@ const _HTTPS = or(
460460 * ```
461461 */
462462export 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', () => {
309309 '/ip4/0.0.0.0/udp/80/http'
310310 ]
311311
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+
312325 function assertMatches ( p : MultiaddrMatcher , ...tests : string [ ] [ ] ) : void {
313326 tests . forEach ( ( test ) => {
314327 test . forEach ( ( testcase ) => {
@@ -416,4 +429,10 @@ describe('multiaddr matcher', () => {
416429 assertExactMatches ( mafmt . HTTPS , exactHTTPS )
417430 assertMismatches ( mafmt . HTTPS , badHTTPS )
418431 } )
432+
433+ it ( 'Unix addresses' , ( ) => {
434+ assertMatches ( mafmt . Unix , goodUnix )
435+ assertExactMatches ( mafmt . Unix , exactUnix )
436+ assertMismatches ( mafmt . Unix , badUnix )
437+ } )
419438} )
You can’t perform that action at this time.
0 commit comments