node-match-path

Dependency-free request URI matcher

MIT 19 个版本
安装
npm install node-match-path
yarn add node-match-path
pnpm add node-match-path
bun add node-match-path
README

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')
/*
{
  matches: true,
  params: {
    userId: '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 parameters

match('/admin/:messageId', '/admin/abc-123')

/*
{
  matches: true,
  params: {
    messageId: 'abc-123'
  }
}
*/

Wildcard

match('/user/*/inbox', '/user/abc-123/inbox')

/*
{
  matches: true,
  params: null
}
*/

Regular expression

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

/*
{
  matches: true,
  params: null
}
*/

Honorable mentions

版本列表
0.6.3 2021-04-09
0.6.2 2021-03-24
0.6.1 2021-01-22
0.6.0 2020-11-06
0.5.2 2020-11-03
0.5.1 2020-09-23
0.5.0 2020-09-14
0.4.4 2020-07-27
0.4.3 2020-06-17
0.4.2 2020-04-24
0.4.1 2020-04-24
0.4.0 2020-04-23
0.3.1 2020-03-22
0.3.0 2020-03-11
0.2.3 2020-03-02
0.2.2 2020-03-02
0.2.1 2020-03-02
0.2.0 2020-03-02
0.1.0 2019-07-24