# node-match-path

> Dependency-free request URI matcher

Latest version **0.6.3** (published 2021-04-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-match-path
pnpm add node-match-path
yarn add node-match-path
bun add node-match-path
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.3 |
| Published | 2021-04-09 |
| First published | 2019-07-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Artem Zakharchenko |
| Maintainers | kettanaito |
| Keywords | url, uri, path, route, mask, match, matcher, path-to-regexp, regexp, wildcard, params |

## Links

- npm: https://www.npmjs.com/package/node-match-path
- npm.io page: https://npm.io/package/node-match-path

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 0.6.3 (latest) — 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
- … 4 more at https://npm.io/package/node-match-path/versions

## README

[![Package version](https://img.shields.io/npm/v/node-match-path.svg)](https://npmjs.com/package/node-match-path)

# `node-match-path`

Matches a URL against the given path.

## Getting started

### Install

```bash
npm install node-match-path
```

## Usage

```js
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

```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
}
*/
```

## Honorable mentions

- [`path-to-regexp`](https://github.com/pillarjs/path-to-regexp)

---
_Source: https://npm.io/package/node-match-path · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
