Socket
Book a DemoInstallSign in
Socket

node-match-path

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-match-path

Dependency-free request URI matcher

npmnpm
Version
0.3.1
Version published
Maintainers
1
Created
Source

Package version

node-match-path

Matches a URL against the given path.

Getting started

Install

npm install node-match-path

Usage

const { match } = require('node-match-path')

match('/user/:userId', '/user/5')

API

match(path: RegExp | string, url: string): Match

Returns a match data, if any, between a url and a path.

String path

match('/admin', '/admin')

{
  matches: true,
  params: null
}

Path with parameters

match('/admin/:messageId', '/admin/sh3fe')

{
  matches: true,
  params: {
    messageId: 'sh3fe'
  }
}

Path with wildcard

match('/user/*/inbox', '/user/abcd-1234/inbox')

{
  matches: true,
  params: null
}

Regular expression

match(/\/messages\/.+?\/participants/, '/messages/5/participants')

{
  matches: true,
  params: null
}

Honorable mentions

  • path-to-regexp

Keywords

url

FAQs

Package last updated on 22 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts