matcher.js 670 B

12345678910111213141516171819202122232425
  1. // src/router/reg-exp-router/matcher.ts
  2. import { METHOD_NAME_ALL } from "../../router.js";
  3. var emptyParam = [];
  4. function match(method, path) {
  5. const matchers = this.buildAllMatchers();
  6. const match2 = ((method2, path2) => {
  7. const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
  8. const staticMatch = matcher[2][path2];
  9. if (staticMatch) {
  10. return staticMatch;
  11. }
  12. const match3 = path2.match(matcher[0]);
  13. if (!match3) {
  14. return [[], emptyParam];
  15. }
  16. const index = match3.indexOf("", 1);
  17. return [matcher[1][index], match3];
  18. });
  19. this.match = match2;
  20. return match2(method, path);
  21. }
  22. export {
  23. emptyParam,
  24. match
  25. };