JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 200170
  • Score
    100M100P100Q166253F
  • License MIT

Matches a url against the given path.

Package Exports

  • node-match-path

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-match-path) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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