@eggjs/path-matching
match or ignore url path
Last updated a year ago by GitHub Actions .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @eggjs/path-matching 
SYNC missed versions from official npm registry.

@eggjs/path-matching

NPM version Known Vulnerabilities npm download

Installation

npm install @eggjs/path-matching

Usage

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

Contributors

Contributors

Made with contributors-img.

Current Tags

  • 3.0.2-beta.27                                ...           beta (2 months ago)
  • 3.1.0                                ...           latest (2 months ago)
  • 3.0.2-rc.1                                ...           rc (2 months ago)

44 Versions

  • 3.1.0                                ...           2 months ago
  • 3.0.2                                ...           2 months ago
  • 3.0.2-rc.1                                ...           2 months ago
  • 3.0.2-rc.0                                ...           2 months ago
  • 3.0.2-beta.27                                ...           2 months ago
  • 3.0.2-beta.26                                ...           4 months ago
  • 3.0.2-beta.25                                ...           4 months ago
  • 3.0.2-beta.24                                ...           4 months ago
  • 3.0.2-beta.23                                ...           5 months ago
  • 3.0.2-beta.22                                ...           5 months ago
  • 3.0.2-beta.20                                ...           5 months ago
  • 3.0.2-beta.19                                ...           5 months ago
  • 3.0.2-beta.17                                ...           5 months ago
  • 3.0.2-beta.16                                ...           5 months ago
  • 3.0.2-beta.15                                ...           5 months ago
  • 3.0.2-beta.14                                ...           5 months ago
  • 3.0.2-beta.13                                ...           5 months ago
  • 3.0.2-beta.12                                ...           5 months ago
  • 3.0.2-beta.11                                ...           5 months ago
  • 3.0.2-beta.10                                ...           5 months ago
  • 3.0.2-beta.9                                ...           8 months ago
  • 3.0.2-beta.8                                ...           8 months ago
  • 3.0.2-beta.7                                ...           8 months ago
  • 3.0.2-beta.6                                ...           8 months ago
  • 3.0.2-beta.5                                ...           8 months ago
  • 3.0.2-beta.4                                ...           8 months ago
  • 3.0.2-beta.3                                ...           9 months ago
  • 3.0.2-beta.2                                ...           9 months ago
  • 3.0.2-beta.1                                ...           9 months ago
  • 3.0.2-beta.0                                ...           9 months ago
  • 3.0.1-beta.0                                ...           9 months ago
  • 3.0.0-beta.39                                ...           9 months ago
  • 3.0.0-beta.38                                ...           9 months ago
  • 3.0.0-beta.37                                ...           9 months ago
  • 3.0.0-beta.36                                ...           a year ago
  • 3.0.0-beta.35                                ...           a year ago
  • 3.0.0-beta.34                                ...           a year ago
  • 3.0.0-beta.33                                ...           a year ago
  • 3.0.0-beta.32                                ...           a year ago
  • 3.0.0-beta.31                                ...           a year ago
  • 3.0.0-beta.30                                ...           a year ago
  • 3.0.0-beta.29                                ...           a year ago
  • 3.0.0-beta.28                                ...           a year ago
  • 3.0.0-beta.20                                ...           a year ago
Downloads
Total 155
Today 0
This Week 0
This Month 149
Last Day 0
Last Week 45
Last Month 6
Dependencies (1)
Dev Dependencies (4)

© 2010 - cnpmjs.org x YWFE | Home | YWFE