@eggjs/ 路径匹配
安装
npm install @eggjs/path-matching
使用量
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);
选项
match{String }\ RegExp }\ 函数 { sarray} - 如果请求路径被击中options.match,将返回true,否则将返回false。 。 。 .ignore{String }\ RegExp }\ 函数 { sarray} - 如果请求路径被击中options.ignore,将返回false,否则将返回true。 。 。 .pathToRegexpModule{Object } - 自定义路径到 regexp 模块 。 默认是path-to-regexp@6。支持两者path-to-regexp@6财务报告和审定财务报表path-to-regexp@8+格式.
ignore 财务报告和审定财务报表 match 无法同时呈现.
如果没有 ignore 也没有 match 显示,新函数将永远返回 true。 。 。 .
许可证
贡献者
制造的 贡献者-img。 。 。 .