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

deeleman / spaghettify / 38

pending completion
38

Pull #15

travis-ci-com

web-flow
Merge a524a28d8 into 8bd92c50d
Pull Request #15: build(deps): bump decode-uri-component from 0.2.0 to 0.2.2

63 of 70 branches covered (90.0%)

Branch coverage included in aggregate %.

176 of 190 relevant lines covered (92.63%)

4.9 hits per line

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

100.0
/src/middleware/link-interceptor/link-interceptor.ts
1
import { MiddlewareHandler, MiddlewarePayload } from 'spaghettify/core'
2

3
/**
4
 * The `linkInterceptor` middleware expects a routes array and will return a `MiddlewarePayload` object
5
 * handler. When executed, it will inspect the `href` of the passed `MiddlewarePayload` object
6
 * to assess whether the represented link is eligible for AJAX-driven navigation, shortcircuiting
7
 * the default DOM event if so.
8
 * @param routes Routes array, containing a collection of glob tokens
9
 * representing URLs  whose links spaghettify will act on.
10
 * @returns A `MiddlewarePayload` object if the link is eligible. Otherwise it will return `undefined`.
11
 */
12
export const linkInterceptor = (routes: string[]): MiddlewareHandler => {
2✔
13
  const routeRegexPattern = routes.join('|')
9✔
14
    .replace(/\//g, '\\/')
15
    .replace(/\./g, '\\.')
16
    .replace(/\+/g, '\\+')
17
    .replace(/\?/g, '\\?')
18
    .replace('**/', '(.*\\/)?')
19
    .replace(/\*/g, '.+?')
20
    .replace('.+?.+?\\/', '(.+?.+?\/)?');
21

22
  const routeRegex = new RegExp(routeRegexPattern, 'i');
9✔
23

24
  return (payload: MiddlewarePayload): MiddlewarePayload | undefined => {
9✔
25
    const isEligibleAnchor = routeRegex.test(payload.anchor.href);
9✔
26

27
    if (isEligibleAnchor) {
9✔
28
      payload.event.preventDefault();
5✔
29
    }
30

31
    return isEligibleAnchor ? payload : void 0
9✔
32
  };
33
};
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

© 2025 Coveralls, Inc