當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript path-to-regexp類代碼示例

本文整理匯總了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;未經允許,請勿轉載。