# @eggjs/path-matching

> match or ignore url path

Latest version **3.1.0** (published 2026-10-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @eggjs/path-matching
pnpm add @eggjs/path-matching
yarn add @eggjs/path-matching
bun add @eggjs/path-matching
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; popular repo.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2026-10-07 |
| First published | 2025-10-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=22.18.0 |
| Dependencies | 1 |
| Unpacked size | 6.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 18984 |
| Author | dead-horse |
| Maintainers | gxkl, eggjs-admin, fengmk2, atian25, hyj1991, killagu, coolme200, akitasummer, elrrrrrrr, niania |
| Keywords | ignore, match, url |

## Links

- npm: https://www.npmjs.com/package/@eggjs/path-matching
- Repository: https://github.com/eggjs/egg
- Homepage: https://github.com/eggjs/egg/tree/next/packages/path-matching
- Issues: https://github.com/eggjs/egg/issues
- npm.io page: https://npm.io/package/@eggjs/path-matching

## Dependencies (1)

- [path-to-regexp](https://npm.io/package/path-to-regexp.md) ^6.3.0

## 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

- 3.1.0 (latest) — 2026-10-07
- 3.0.2-rc.1 (rc) — 2026-10-06
- 3.0.2-beta.27 (beta) — 2026-09-20
- 3.0.2 — 2026-10-06
- 3.0.2-rc.0 — 2026-09-23
- 3.0.2-beta.26 — 2026-08-07
- 3.0.2-beta.25 — 2026-07-13
- 3.0.2-beta.24 — 2026-07-12
- 3.0.2-beta.23 — 2026-07-11
- 3.0.2-beta.22 — 2026-07-11
- 3.0.2-beta.20 — 2026-07-09
- 3.0.2-beta.19 — 2026-06-29
- 3.0.2-beta.17 — 2026-06-28
- 3.0.2-beta.16 — 2026-06-26
- 3.0.2-beta.15 — 2026-06-26
- … 29 more at https://npm.io/package/@eggjs/path-matching/versions

## README

# @eggjs/path-matching

[![NPM version][npm-image]][npm-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/@eggjs/path-matching.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@eggjs/path-matching
[snyk-image]: https://snyk.io/test/npm/@eggjs/path-matching/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/@eggjs/path-matching/badge.svg?style=flat-square
[download-image]: https://img.shields.io/npm/dm/@eggjs/path-matching.svg?style=flat-square
[download-url]: https://npmjs.org/package/@eggjs/path-matching

## Installation

```bash
npm install @eggjs/path-matching
```

## Usage

```ts
import { pathMatching } from '@eggjs/path-matching';

const options = {
  ignore: '/api', // string will use parsed by path-to-regexp
  // support regexp
  ignore: /^\/api/,
  // support function
  ignore: (ctx) => ctx.path.startsWith('/api'),
  // support Array
  ignore: [(ctx) => ctx.path.startsWith('/api'), /^\/foo$/, '/bar'],
  // support match or ignore
  match: '/api',
  // custom path-to-regexp module, default is `path-to-regexp@6`
  // pathToRegexpModule: customPathToRegexp,
};

const match = pathMatching(options);
assert.equal(match({ path: '/api' }), true);
assert.equal(match({ path: '/api/hello' }), true);
assert.equal(match({ path: '/api' }), true);
```

### options

- `match` {String | RegExp | Function | Array} - if request path hit `options.match`, will return `true`, otherwise will return `false`.
- `ignore` {String | RegExp | Function | Array} - if request path hit `options.ignore`, will return `false`, otherwise will return `true`.
- `pathToRegexpModule` {Object | Function} - custom path-to-regexp module. Default is `path-to-regexp@6`. Supports both `path-to-regexp@6` and `path-to-regexp@8+` formats.

`ignore` and `match` can not both be presented.
and if neither `ignore` nor `match` presented, the new function will always return `true`.

### License

[MIT](LICENSE)

## Contributors

[![Contributors](https://contrib.rocks/image?repo=eggjs/egg)](https://github.com/eggjs/egg/graphs/contributors)

Made with [contributors-img](https://contrib.rocks).

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