Dependency-free request URI matcher
npm install node-match-path
node-match-pathMatches a URL against the given path.
``bash`
npm install node-match-path
`js
const { match } = require('node-match-path')
match('/user/:userId', '/user/5')
/*
{
matches: true,
params: {
userId: '5'
}
}
*/
`
Returns a match data, if any, between a url and a path.
#### String path
`js
match('/admin', '/admin')
/*
{
matches: true,
params: null
}
*/
`
#### Path parameters
`js
match('/admin/:messageId', '/admin/abc-123')
/*
{
matches: true,
params: {
messageId: 'abc-123'
}
}
*/
`
#### Wildcard
`js
match('/user/*/inbox', '/user/abc-123/inbox')
/*
{
matches: true,
params: null
}
*/
`
#### Regular expression
`js
match(/\/messages\/.+?\/participants/, '/messages/5/participants')
/*
{
matches: true,
params: null
}
*/
`