• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

silvermine / lambda-express / 12315727107

13 Dec 2024 12:33PM UTC coverage: 98.665% (-0.004%) from 98.669%
12315727107

Pull #92

github

web-flow
Merge 7f0d5a94c into d47be8a44
Pull Request #92: fix: replace usage of deprecated node utils functions

207 of 212 branches covered (97.64%)

Branch coverage included in aggregate %.

2 of 2 new or added lines in 2 files covered. (100.0%)

458 of 462 relevant lines covered (99.13%)

1997.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/chains/RouteMatchingProcessorChain.ts
1
import _ from 'underscore';
4✔
2
import ProcessorChain, { IRequestMatchingProcessorChain } from './ProcessorChain';
4✔
3
import { ErrorHandlingRequestProcessor, PathParams } from '../interfaces';
4
import { Request } from '..';
5
import { StringMap } from '@silvermine/toolbox';
6
const pathToRegexp = require('path-to-regexp');
4✔
7

8
interface PathToRegexpKey {
9
   [name: string]: string;
10
}
11

12
export class RouteMatchingProcessorChain extends ProcessorChain implements IRequestMatchingProcessorChain {
4✔
13

14
   private readonly _method: string | undefined;
15
   private readonly _matcher: RegExp;
16
   private readonly _paramKeys: PathToRegexpKey[] = [];
824✔
17

18
   public constructor(subprocessors: ErrorHandlingRequestProcessor[], path: PathParams, method?: string, caseSensitive: boolean = false) {
172✔
19
      super(subprocessors);
824✔
20
      this._method = method;
824✔
21
      this._matcher = pathToRegexp(path, this._paramKeys, { sensitive: caseSensitive });
824✔
22
   }
23

24
   public matches(req: Request): boolean {
25
      if (this._method !== undefined && req.method !== this._method) {
2,196✔
26
         return false;
884✔
27
      }
28

29
      return this._matcher.test(req.path);
1,312✔
30
   }
31

32
   protected _makeParams(path: string): StringMap {
33
      const params: StringMap = {},
812✔
34
            matches = this._matcher.exec(path);
812✔
35

36
      if (matches && matches.length > 0) {
812✔
37
         // the first match returned is the entire URL
38
         _.each(matches.slice(1), (v, i) => {
804✔
39
            const key = this._paramKeys[i];
768✔
40

41
            if (key && !_.isEmpty(v)) {
768✔
42
               try {
392✔
43
                  params[key.name] = decodeURIComponent(v);
392✔
44
               } catch(err) {
45
                  err.statusCode = 400;
12✔
46
                  throw err;
12✔
47
               }
48
            }
49
         });
50
      }
51

52
      return params;
800✔
53
   }
54

55
   protected _makeSubRequest(req: Request): Request {
56
      const params = this._makeParams(req.path);
728✔
57

58
      return req.makeSubRequest('', params);
716✔
59
   }
60

61
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc