本文整理汇总了TypeScript中path-to-regexp类的典型用法代码示例。如果您正苦于以下问题:TypeScript path-to-regexp类的具体用法?TypeScript path-to-regexp怎么用?TypeScript path-to-regexp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了path-to-regexp类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: function
let fty:Route = (path, action:(ctx, args)=> Promise<any> ,opts?) : AppMiddleware => {
const re = pathToRegexp(path, opts);
debug('%s %s -> %s', method || 'ALL', path, re);
return async function (ctx, next:(x?) => Promise<any> ) {
// match method
if (!matches(ctx, method)) {
next();
return
};
// match path
const m = re.exec(ctx.path);
if (m) {
//collect route segments
const args = m.slice(1).map(decode);
debug('%s %s matches %s %j', ctx.method, path, ctx.path, args);
return await action(ctx, args)
}
// miss
return next(true);
}
}
开发者ID:D10221,项目名称:kua,代码行数:27,代码来源:router.ts
示例2: getRegexp
export function getRegexp(pattern: string) {
if (!REGEXP_CACHE.has(pattern)) {
const keys = [];
const regexp = pathToRegexp(pattern, keys, { end: false });
REGEXP_CACHE.set(pattern, { keys, regexp });
}
return REGEXP_CACHE.get(pattern);
}
开发者ID:CoderMonkies,项目名称:router,代码行数:9,代码来源:match-pattern.ts
示例3:
/*
Add an endpoint.
@param {string} method - Endpoint method
@param {string} url - Endopint url
@param {Array.<string>} stores - Stores used by endpoint
@param {function} endopint - Function for computing the HTTP response
*/
add_endpoint(method : string, url: string, stores: Array<string>, endpoint: DbEndpointGen){
// Add to list of endpoints; compile path
this.endpoints.push({
url: path2regexp(url),
stores: stores,
method: method,
endpoint: endpoint
});
}
开发者ID:tayste5000,项目名称:ng-simple-db,代码行数:17,代码来源:db_resource.ts
示例4:
/*
Setup database.
@param {ng.ItthpBackendService} $httpBackend - Angular mocks $httpBackend service
*/
setup($httpBackend : ng.IHttpBackendService) : void{
const api_match = path2regexp(this.apiUrl + "*")
const methods = ['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'JSONP', 'PATCH'];
methods.forEach(method => {$httpBackend['when' + method](api_match).respond(this.manager.mock_request.bind(this.manager))});
methods.forEach(method => {$httpBackend['when' + method](/.*/).passThrough()});
}
开发者ID:tayste5000,项目名称:ng-simple-db,代码行数:14,代码来源:db_store.ts
示例5: async
get(path: string, action: (...args: any[]) => Promise<any>): (ctx, next) => Promise<any> {
let re = pathToRegexp(path);
return async (ctx: Koa.Context, next): Promise<any> => {
let method = ctx.request.method;
let url = ctx.request.url;
let ok = re.test(url);
debug('%s, %s, %s, %s -> %s', method, path, url, ok, re);
if (method == 'GET' && ok) {
action.apply(ctx, []);
return next();
}
next();
}
}
开发者ID:D10221,项目名称:koa-tiny-acl,代码行数:14,代码来源:tests.ts
示例6: route
route(path: string, handler: RouteHandler) {
if (path === '*') {
this.defaultHandler = handler;
return;
}
const keys = [];
const regexp = pathToRegexp(path, keys);
this.routes.push({
regexp,
keys,
handler,
});
}
开发者ID:dittos,项目名称:nuri,代码行数:14,代码来源:app.ts
示例7: next
return (path: string, callback: Function) => {
const re = pathToRegexp(path);
const normalizedPath = path === '/*' ? '' : path;
this.instance.use(normalizedPath, (req, res, next) => {
if (!re.exec(req.originalUrl + '/')) {
return next();
}
if (
requestMethod === RequestMethod.ALL ||
req.method === RequestMethod[requestMethod]
) {
return callback(req, res, next);
}
next();
});
};
开发者ID:SARAVANA1501,项目名称:nest,代码行数:17,代码来源:fastify-adapter.ts
示例8: pathToRegexp
const compile = (route: Route): CompiledRoute => {
const keys: any[] = [];
const regexp = pathToRegexp(route.path, keys);
return { keys, regexp, route };
};
开发者ID:bouzuya,项目名称:boa-router,代码行数:5,代码来源:index.ts
示例9: TypeError
}
let routing = {
set(path: string, handler: Handler) {
if (typeof path !== "string") {
throw new TypeError("expecting path to be a string");
}
if (path === "/" || path === "") {
// home
homeHandler = handler;
return;
}
let keys: any[] = [];
let re = pRegex(path, keys);
// append to object list
objectList[objectList.length] = routeObject(re, keys, handler);
},
get(path: string) {
if (typeof path !== "string") {
throw new TypeError("expecting path to be a string");
}
if (path === "/" || path === "") {
if (homeHandler) {
return {
handler: homeHandler
};
}
开发者ID:mofax,项目名称:leafless,代码行数:31,代码来源:routing.ts
示例10: decodeURI
ProuterPathExp,
ProuterRequestProcessor,
ProuterRequest,
ProuterParsedHandler,
ProuterPathKey
} from './entity';
export const routerHelper = {
getPath() {
return decodeURI(location.pathname + location.search);
},
stringToRegexp(str: string) {
const keys: ProuterPathKey[] = [];
const resp = pathToRegexp(str, keys) as ProuterPathExp;
resp.keys = keys;
return resp;
},
parseQuery(str: string) {
const searchObj: { [key: string]: string } = {};
if (str === '') {
return searchObj;
}
const qs = str.slice(1);
const params = qs.split('&');
开发者ID:rogerpadilla,项目名称:prouter,代码行数:30,代码来源:helper.ts
注:本文中的path-to-regexp类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论