# egg-path-matching

> match or ignore url path

Latest version **2.1.0** (published 2024-09-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install egg-path-matching
pnpm add egg-path-matching
yarn add egg-path-matching
bun add egg-path-matching
```

## Health

**Score 55/100 (C)** — status: stable.

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

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2024-09-18 |
| First published | 2016-11-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 14.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 28 |
| Author | dead-horse |
| Maintainers | dead_horse, fengmk2 |
| Keywords | url, match, ignore |

## Links

- npm: https://www.npmjs.com/package/egg-path-matching
- Repository: https://github.com/eggjs/egg-path-matching
- Homepage: https://github.com/eggjs/egg-path-matching#readme
- Issues: https://github.com/eggjs/egg-path-matching/issues
- npm.io page: https://npm.io/package/egg-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

- 2.1.0 (latest) — 2024-09-18
- 1.2.0 (release-1.x) — 2025-01-22
- 2.0.0 — 2024-06-15
- 1.1.0 — 2023-12-14
- 1.0.1 — 2017-11-15
- 1.0.0 — 2016-11-15

## README

# egg-path-matching

[![NPM version][npm-image]][npm-url]
[![CI](https://github.com/eggjs/egg-path-matching/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/egg-path-matching/actions/workflows/nodejs.yml)
[![Test coverage](https://img.shields.io/codecov/c/github/eggjs/egg-path-matching.svg?style=flat-square)](https://codecov.io/gh/eggjs/egg-path-matching)
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]

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

## Installation

```bash
npm install egg-path-matching
```

## Usage

```ts
import { pathMatching } from 'egg-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',
};

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

`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-path-matching)](https://github.com/eggjs/egg-path-matching/graphs/contributors)

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

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