├── .circleci └── config.yml ├── .gitignore ├── .prettierrc ├── README.md ├── babel.config.js ├── jest.config.js ├── package.json ├── rollup.config.js ├── src ├── index.ts ├── match.ts ├── pathToRegExp.test.ts └── pathToRegExp.ts ├── test ├── path.test.ts ├── regexp.test.ts ├── setup │ └── runner.ts └── url.test.ts ├── tsconfig.json └── yarn.lock /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | jobs: 4 | build: 5 | working_directory: ~/release 6 | docker: 7 | - image: circleci/node:lts 8 | environment: 9 | TERM: xterm 10 | steps: 11 | - checkout 12 | - restore_cache: 13 | keys: 14 | - v1-deps-{{ .Branch }}-{{ checksum "yarn.lock" }} 15 | - run: 16 | name: 'Environment' 17 | command: | 18 | node --version 19 | npm --version 20 | yarn --version 21 | - run: 22 | name: Installing dependencies 23 | command: yarn --frozen-lockfile 24 | - save_cache: 25 | key: v1-deps-{{ .Branch }}-{{ checksum "yarn.lock" }} 26 | paths: 27 | - .cache 28 | - run: 29 | name: Build 30 | command: yarn build 31 | - run: 32 | name: Tests 33 | command: yarn test 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | .rpt2_cache 3 | node_modules 4 | npm-error* 5 | yarn-error* 6 | 7 | # Build 8 | lib 9 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "useTabs": false, 4 | "singleQuote": true, 5 | "trailingComma": "all", 6 | "arrowParens": "always", 7 | "bracketSpacing": true 8 | } 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Package version](https://img.shields.io/npm/v/node-match-path.svg)](https://npmjs.com/package/node-match-path) 2 | 3 | # `node-match-path` 4 | 5 | Matches a URL against the given path. 6 | 7 | ## Getting started 8 | 9 | ### Install 10 | 11 | ```bash 12 | npm install node-match-path 13 | ``` 14 | 15 | ## Usage 16 | 17 | ```js 18 | const { match } = require('node-match-path') 19 | 20 | match('/user/:userId', '/user/5') 21 | /* 22 | { 23 | matches: true, 24 | params: { 25 | userId: '5' 26 | } 27 | } 28 | */ 29 | ``` 30 | 31 | ## API 32 | 33 | ### `match(path: RegExp | string, url: string): Match` 34 | 35 | Returns a match data, if any, between a url and a path. 36 | 37 | #### String path 38 | 39 | ```js 40 | match('/admin', '/admin') 41 | 42 | /* 43 | { 44 | matches: true, 45 | params: null 46 | } 47 | */ 48 | ``` 49 | 50 | #### Path parameters 51 | 52 | ```js 53 | match('/admin/:messageId', '/admin/abc-123') 54 | 55 | /* 56 | { 57 | matches: true, 58 | params: { 59 | messageId: 'abc-123' 60 | } 61 | } 62 | */ 63 | ``` 64 | 65 | #### Wildcard 66 | 67 | ```js 68 | match('/user/*/inbox', '/user/abc-123/inbox') 69 | 70 | /* 71 | { 72 | matches: true, 73 | params: null 74 | } 75 | */ 76 | ``` 77 | 78 | #### Regular expression 79 | 80 | ```js 81 | match(/\/messages\/.+?\/participants/, '/messages/5/participants') 82 | 83 | /* 84 | { 85 | matches: true, 86 | params: null 87 | } 88 | */ 89 | ``` 90 | 91 | ## Honorable mentions 92 | 93 | - [`path-to-regexp`](https://github.com/pillarjs/path-to-regexp) 94 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [['@babel/preset-env', { modules: false }]], 3 | plugins: ['@babel/plugin-transform-named-capturing-groups-regex'], 4 | } 5 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | transform: { 3 | '^.+\\.tsx?$': 'ts-jest', 4 | }, 5 | } 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-match-path", 3 | "version": "0.6.3", 4 | "description": "Dependency-free request URI matcher", 5 | "esnext": "src/index.ts", 6 | "main": "lib/cjs.js", 7 | "module": "lib/esm.js", 8 | "types": "lib/index.d.ts", 9 | "author": "Artem Zakharchenko ", 10 | "license": "MIT", 11 | "files": [ 12 | "lib", 13 | "README.md" 14 | ], 15 | "repository": { 16 | "type": "git", 17 | "url": "https://github.com/mswjs/node-match-path.git" 18 | }, 19 | "keywords": [ 20 | "url", 21 | "uri", 22 | "path", 23 | "route", 24 | "mask", 25 | "match", 26 | "matcher", 27 | "path-to-regexp", 28 | "regexp", 29 | "wildcard", 30 | "params" 31 | ], 32 | "scripts": { 33 | "test": "jest", 34 | "clean": "rimraf -rf lib", 35 | "build": "yarn clean && rollup -c rollup.config.js", 36 | "prepublishOnly": "yarn test && yarn build" 37 | }, 38 | "devDependencies": { 39 | "@babel/core": "^7.13.10", 40 | "@babel/preset-env": "^7.13.12", 41 | "@types/jest": "^26.0.21", 42 | "jest": "^26.6.3", 43 | "rimraf": "^3.0.2", 44 | "rollup": "^2.42.3", 45 | "rollup-plugin-babel": "^4.4.0", 46 | "rollup-plugin-node-resolve": "^5.2.0", 47 | "rollup-plugin-sourcemaps": "^0.6.3", 48 | "rollup-plugin-typescript2": "^0.30.0", 49 | "ts-jest": "^26.5.4", 50 | "typescript": "^4.2.3" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const resolve = require('rollup-plugin-node-resolve') 3 | const sourceMaps = require('rollup-plugin-sourcemaps') 4 | const babel = require('rollup-plugin-babel') 5 | const typescript = require('rollup-plugin-typescript2') 6 | 7 | const packageJson = require('./package.json') 8 | const babelConfig = require('./babel.config') 9 | 10 | const input = packageJson.esnext 11 | 12 | const buildCjs = { 13 | input, 14 | output: { 15 | file: path.resolve(__dirname, packageJson.main), 16 | format: 'cjs', 17 | exports: 'named', 18 | sourcemap: true, 19 | }, 20 | plugins: [resolve(), typescript(), sourceMaps()], 21 | } 22 | 23 | const buildEsm = { 24 | input, 25 | output: { 26 | file: path.resolve(__dirname, packageJson.module), 27 | format: 'esm', 28 | sourcemap: true, 29 | }, 30 | plugins: [resolve(), typescript(), babel(babelConfig), sourceMaps()], 31 | } 32 | 33 | module.exports = [buildCjs, buildEsm] 34 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export { Path, Match, match } from './match' 2 | export { pathToRegExp } from './pathToRegExp' 3 | -------------------------------------------------------------------------------- /src/match.ts: -------------------------------------------------------------------------------- 1 | import { pathToRegExp } from './pathToRegExp' 2 | 3 | export type Path = RegExp | string 4 | 5 | export interface Match { 6 | matches: boolean 7 | params: Record | null 8 | } 9 | 10 | /** 11 | * Matches a given url against a path. 12 | */ 13 | export const match = (path: Path, url: string): Match => { 14 | const expression = path instanceof RegExp ? path : pathToRegExp(path) 15 | const match = expression.exec(url) || false 16 | 17 | // Matches in strict mode: match string should equal to input (url) 18 | // Otherwise loose matches will be considered truthy: 19 | // match('/messages/:id', '/messages/123/users') // true 20 | const matches = 21 | path instanceof RegExp ? !!match : !!match && match[0] === match.input 22 | 23 | return { 24 | matches, 25 | params: match && matches ? match.groups || null : null, 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/pathToRegExp.test.ts: -------------------------------------------------------------------------------- 1 | import { pathToRegExp } from './pathToRegExp' 2 | 3 | describe('pathToRegExp', () => { 4 | describe('given a plain string path', () => { 5 | it('should transform into expression matching the string', () => { 6 | const exp = pathToRegExp('/users/recent') 7 | expect(exp).toEqual(/\/users\/recent(\/|$)/gi) 8 | }) 9 | }) 10 | 11 | describe('given a path with parameters', () => { 12 | it('should replace parameters with a group', () => { 13 | const exp = pathToRegExp('/user/:userId/') 14 | expect(exp).toEqual(/\/user\/(?[^/]+?)(\/|$)/gi) 15 | }) 16 | }) 17 | 18 | describe('given a path with a one-character parameter', () => { 19 | it('should replace parameter with a group', () => { 20 | const exp = pathToRegExp('/user/:u') 21 | expect(exp).toEqual(/\/user\/(?[^/]+?)(\/|$)/gi) 22 | }) 23 | }) 24 | 25 | describe('given a path with multiple parameters', () => { 26 | it('should replace each parameter with a group', () => { 27 | expect(pathToRegExp('/user/:userId/messages/:messageId')).toEqual( 28 | /\/user\/(?[^/]+?)\/messages\/(?[^/]+?)(\/|$)/gi, 29 | ) 30 | }) 31 | }) 32 | 33 | describe('given a path with a wildcard', () => { 34 | it('should handle wildcard', () => { 35 | const exp = pathToRegExp('/user/*/shipping') 36 | expect(exp).toEqual(/\/user\/.*\/shipping(\/|$)/gi) 37 | }) 38 | }) 39 | 40 | describe('given a path with parameter and wildcard', () => { 41 | it('should handle both', () => { 42 | const exp = pathToRegExp('/user/:userId/*') 43 | expect(exp).toEqual(/\/user\/(?[^/]+?)\/.*(\/|$)/gi) 44 | }) 45 | }) 46 | 47 | describe('given a full url', () => { 48 | it('should escape the url characters', () => { 49 | const exp = pathToRegExp('https://api.github.com/users/:username') 50 | expect(exp).toEqual( 51 | /https:\/\/api\.github\.com\/users\/(?[^/]+?)(\/|$)/gi, 52 | ) 53 | }) 54 | }) 55 | 56 | describe('given a url with a port', () => { 57 | it('should leave port number as-is', () => { 58 | const exp = pathToRegExp('http://localhost:4000') 59 | expect(exp).toEqual(/http:\/\/localhost:4000(\/|$)/gi) 60 | }) 61 | }) 62 | 63 | describe('given a string with a question mark', () => { 64 | it('should escape the question mark', () => { 65 | const exp = pathToRegExp('http://test.msw.io/api/books?id=123') 66 | expect(exp).toEqual(/http:\/\/test\.msw\.io\/api\/books\?id=123(\/|$)/gi) 67 | }) 68 | }) 69 | 70 | describe('given a path with a parameter and extension', () => { 71 | it('should properly parse the parameter', () => { 72 | const exp = pathToRegExp('/user/:userId.json') 73 | expect(exp).toEqual(/\/user\/(?[^/]+?)\.json(\/|$)/gi) 74 | }) 75 | }) 76 | }) 77 | -------------------------------------------------------------------------------- /src/pathToRegExp.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Converts a string path to a Regular Expression. 3 | * Transforms path parameters into named RegExp groups. 4 | */ 5 | export const pathToRegExp = (path: string): RegExp => { 6 | const pattern = path 7 | // Escape literal dots 8 | .replace(/\./g, '\\.') 9 | // Escape literal slashes 10 | .replace(/\//g, '/') 11 | // Escape literal question marks 12 | .replace(/\?/g, '\\?') 13 | // Ignore trailing slashes 14 | .replace(/\/+$/, '') 15 | // Replace wildcard with any zero-to-any character sequence 16 | .replace(/\*+/g, '.*') 17 | // Replace parameters with named capturing groups 18 | .replace( 19 | /:([^\d|^\/][a-zA-Z0-9_]*(?=(?:\/|\\.)|$))/g, 20 | (_, paramName) => `(?<${paramName}>[^\/]+?)`, 21 | ) 22 | // Allow optional trailing slash 23 | .concat('(\\/|$)') 24 | 25 | return new RegExp(pattern, 'gi') 26 | } 27 | -------------------------------------------------------------------------------- /test/path.test.ts: -------------------------------------------------------------------------------- 1 | import { runner } from './setup/runner' 2 | 3 | runner('Path', [ 4 | /** 5 | * Path parameter 6 | */ 7 | { 8 | given: '/user/:userId', 9 | when: [ 10 | { 11 | actual: '/user/abc-123', 12 | it: { 13 | matches: true, 14 | params: { userId: 'abc-123' }, 15 | }, 16 | }, 17 | { 18 | actual: '/user/abc-123/', 19 | it: { 20 | matches: true, 21 | params: { userId: 'abc-123' }, 22 | }, 23 | }, 24 | { 25 | actual: '/user/', 26 | it: { 27 | matches: false, 28 | params: null, 29 | }, 30 | }, 31 | { 32 | actual: '/user/abc-123/messages', 33 | it: { 34 | matches: false, 35 | params: null, 36 | }, 37 | }, 38 | { 39 | actual: '/arbitrary/abc-123', 40 | it: { 41 | matches: false, 42 | params: null, 43 | }, 44 | }, 45 | ], 46 | }, 47 | { 48 | given: '/user/:user_id', 49 | when: [ 50 | { 51 | actual: '/user/abc-123', 52 | it: { 53 | matches: true, 54 | params: { user_id: 'abc-123' }, 55 | }, 56 | }, 57 | { 58 | actual: '/user/abc-123/', 59 | it: { 60 | matches: true, 61 | params: { user_id: 'abc-123' }, 62 | }, 63 | }, 64 | { 65 | actual: '/user/', 66 | it: { 67 | matches: false, 68 | params: null, 69 | }, 70 | }, 71 | { 72 | actual: '/user/abc-123/messages', 73 | it: { 74 | matches: false, 75 | params: null, 76 | }, 77 | }, 78 | { 79 | actual: '/arbitrary/abc-123', 80 | it: { 81 | matches: false, 82 | params: null, 83 | }, 84 | }, 85 | ], 86 | }, 87 | { 88 | given: '/user/:userId/messages', 89 | when: [ 90 | { 91 | actual: '/user/abc-123/messages', 92 | it: { 93 | matches: true, 94 | params: { 95 | userId: 'abc-123', 96 | }, 97 | }, 98 | }, 99 | { 100 | actual: '/user/abc-123/def-456/messages', 101 | it: { 102 | matches: false, 103 | params: null, 104 | }, 105 | }, 106 | { 107 | actual: '/user/abc-123/messages/arbitrary', 108 | it: { 109 | matches: false, 110 | params: null, 111 | }, 112 | }, 113 | { 114 | actual: '/user/abc-123/', 115 | it: { 116 | matches: false, 117 | params: null, 118 | }, 119 | }, 120 | ], 121 | }, 122 | { 123 | given: '/user/:userId/messages/:messageId', 124 | when: [ 125 | { 126 | actual: '/user/abc-123/messages/def-456', 127 | it: { 128 | matches: true, 129 | params: { 130 | userId: 'abc-123', 131 | messageId: 'def-456', 132 | }, 133 | }, 134 | }, 135 | { 136 | actual: '/user/abc-123/messages/def-456/', 137 | it: { 138 | matches: true, 139 | params: { 140 | userId: 'abc-123', 141 | messageId: 'def-456', 142 | }, 143 | }, 144 | }, 145 | { 146 | actual: '/user/abc-123/messages/def-456/arbitrary', 147 | it: { 148 | matches: false, 149 | params: null, 150 | }, 151 | }, 152 | { 153 | actual: '/user/abc-123/messages', 154 | it: { 155 | matches: false, 156 | params: null, 157 | }, 158 | }, 159 | { 160 | actual: '/user/abc-123', 161 | it: { 162 | matches: false, 163 | params: null, 164 | }, 165 | }, 166 | ], 167 | }, 168 | { 169 | given: '/user/:u', 170 | when: [ 171 | { 172 | actual: '/user/abc-123', 173 | it: { 174 | matches: true, 175 | params: { 176 | u: 'abc-123', 177 | }, 178 | }, 179 | }, 180 | { 181 | actual: '/user/abc-123/', 182 | it: { 183 | matches: true, 184 | params: { 185 | u: 'abc-123', 186 | }, 187 | }, 188 | }, 189 | { 190 | actual: '/user/abc-123/arbitrary', 191 | it: { 192 | matches: false, 193 | params: null, 194 | }, 195 | }, 196 | { 197 | actual: '/user/', 198 | it: { 199 | matches: false, 200 | params: null, 201 | }, 202 | }, 203 | ], 204 | }, 205 | { 206 | given: '/files/:filename.json', 207 | when: [ 208 | { 209 | actual: '/files/report.json', 210 | it: { 211 | matches: true, 212 | params: { 213 | filename: 'report', 214 | }, 215 | }, 216 | }, 217 | { 218 | actual: '/files/long-report-name-2.json', 219 | it: { 220 | matches: true, 221 | params: { 222 | filename: 'long-report-name-2', 223 | }, 224 | }, 225 | }, 226 | { 227 | actual: '/files/:filename', 228 | it: { 229 | matches: false, 230 | params: null, 231 | }, 232 | }, 233 | ], 234 | }, 235 | 236 | /** 237 | * Wildcard 238 | */ 239 | { 240 | given: '/user/*/messages', 241 | when: [ 242 | { 243 | actual: '/user/arbitrary/messages', 244 | it: { 245 | matches: true, 246 | params: null, 247 | }, 248 | }, 249 | { 250 | actual: '/user/arbitrary/messages/more', 251 | it: { 252 | matches: false, 253 | params: null, 254 | }, 255 | }, 256 | { 257 | actual: '/user/', 258 | it: { 259 | matches: false, 260 | params: null, 261 | }, 262 | }, 263 | ], 264 | }, 265 | { 266 | given: '/user/*/messages/*', 267 | when: [ 268 | { 269 | actual: '/user/any/messages/abc-123', 270 | it: { 271 | matches: true, 272 | params: null, 273 | }, 274 | }, 275 | { 276 | actual: '/user/any/messages/any/more', 277 | it: { 278 | matches: true, 279 | params: null, 280 | }, 281 | }, 282 | { 283 | actual: '/user/any/', 284 | it: { 285 | matches: false, 286 | params: null, 287 | }, 288 | }, 289 | ], 290 | }, 291 | { 292 | given: '/user/details*', 293 | when: [ 294 | { 295 | actual: '/user/details', 296 | it: { 297 | matches: true, 298 | params: null, 299 | }, 300 | }, 301 | { 302 | actual: '/user/details/arbitrary', 303 | it: { 304 | matches: true, 305 | params: null, 306 | }, 307 | }, 308 | ], 309 | }, 310 | 311 | /** 312 | * Parameter and wildcard 313 | */ 314 | { 315 | given: '/user/:userId/*', 316 | when: [ 317 | { 318 | actual: '/user/abc-123/messages', 319 | it: { 320 | matches: true, 321 | params: { 322 | userId: 'abc-123', 323 | }, 324 | }, 325 | }, 326 | { 327 | actual: '/User/abc-123/messages', 328 | it: { 329 | matches: true, 330 | params: { 331 | userId: 'abc-123', 332 | }, 333 | }, 334 | }, 335 | { 336 | actual: '/user/abc-123/settings/', 337 | it: { 338 | matches: true, 339 | params: { 340 | userId: 'abc-123', 341 | }, 342 | }, 343 | }, 344 | { 345 | actual: '/user/abc-123/messages/def-456', 346 | it: { 347 | matches: true, 348 | params: { 349 | userId: 'abc-123', 350 | }, 351 | }, 352 | }, 353 | { 354 | actual: '/user/abc-123', 355 | it: { 356 | matches: false, 357 | params: null, 358 | }, 359 | }, 360 | { 361 | actual: '/user/', 362 | it: { 363 | matches: false, 364 | params: null, 365 | }, 366 | }, 367 | ], 368 | }, 369 | ]) 370 | -------------------------------------------------------------------------------- /test/regexp.test.ts: -------------------------------------------------------------------------------- 1 | import { runner } from './setup/runner' 2 | 3 | runner('RegExp', [ 4 | { 5 | given: /\/users\//, 6 | when: [ 7 | { 8 | actual: '/users/', 9 | it: { 10 | matches: true, 11 | params: null, 12 | }, 13 | }, 14 | { 15 | actual: '/users/abcd-1234/', 16 | it: { 17 | matches: true, 18 | params: null, 19 | }, 20 | }, 21 | { 22 | actual: '/settings', 23 | it: { 24 | matches: false, 25 | params: null, 26 | }, 27 | }, 28 | ], 29 | }, 30 | { 31 | given: /\/user\/.+?\//, 32 | when: [ 33 | { 34 | actual: '/user/abcd-1234/', 35 | it: { 36 | matches: true, 37 | params: null, 38 | }, 39 | }, 40 | { 41 | actual: '/user/', 42 | it: { 43 | matches: false, 44 | params: null, 45 | }, 46 | }, 47 | ], 48 | }, 49 | ]) 50 | -------------------------------------------------------------------------------- /test/setup/runner.ts: -------------------------------------------------------------------------------- 1 | import { Path, match } from '../../src/match' 2 | 3 | export interface Scenario { 4 | given: Path 5 | when: Array<{ 6 | only?: boolean 7 | actual: string 8 | it: { 9 | [key: string]: any 10 | } & ReturnType 11 | }> 12 | } 13 | 14 | export const runner = (name: string, scenarios: Scenario[]) => { 15 | describe(name, () => { 16 | scenarios.forEach((scenario) => { 17 | describe(`given "${scenario.given}" path`, () => { 18 | scenario.when.forEach((data) => { 19 | describe(`and "${data.actual}" url`, () => { 20 | const test = data.only ? it.only : it 21 | 22 | Object.entries(data.it).forEach(([key, expectedValue]) => { 23 | test(`"${key}": "${JSON.stringify(expectedValue)}"`, () => { 24 | const result = match(scenario.given, data.actual) 25 | expect(result).toHaveProperty(key, expectedValue) 26 | }) 27 | }) 28 | }) 29 | }) 30 | }) 31 | }) 32 | }) 33 | } 34 | -------------------------------------------------------------------------------- /test/url.test.ts: -------------------------------------------------------------------------------- 1 | import { runner } from './setup/runner' 2 | 3 | runner('URL', [ 4 | { 5 | given: '/users', 6 | when: [ 7 | { 8 | actual: '/users', 9 | it: { 10 | matches: true, 11 | params: null, 12 | }, 13 | }, 14 | { 15 | actual: '/Users', 16 | it: { 17 | matches: true, 18 | params: null, 19 | }, 20 | }, 21 | { 22 | actual: '/users/', 23 | it: { 24 | matches: true, 25 | params: null, 26 | }, 27 | }, 28 | { 29 | actual: '/users/arbitrary', 30 | it: { 31 | matches: false, 32 | params: null, 33 | }, 34 | }, 35 | { 36 | actual: '/arbitrary/users', 37 | it: { 38 | matches: false, 39 | params: null, 40 | }, 41 | }, 42 | { 43 | actual: '/use', 44 | it: { 45 | matches: false, 46 | params: null, 47 | }, 48 | }, 49 | ], 50 | }, 51 | { 52 | given: 'https://test.mockserviceworker.io', 53 | when: [ 54 | { 55 | actual: 'https://test.mockserviceworker.io', 56 | it: { 57 | matches: true, 58 | params: null, 59 | }, 60 | }, 61 | { 62 | actual: 'https://test.MOCKSERVICEWORKER.io', 63 | it: { 64 | matches: true, 65 | params: null, 66 | }, 67 | }, 68 | { 69 | actual: 'https://test.mockserviceworker.io/', 70 | it: { 71 | matches: true, 72 | params: null, 73 | }, 74 | }, 75 | ], 76 | }, 77 | { 78 | given: 'https://test.mockserviceworker.io/', 79 | when: [ 80 | { 81 | actual: 'https://test.mockserviceworker.io', 82 | it: { 83 | matches: true, 84 | params: null, 85 | }, 86 | }, 87 | { 88 | actual: 'https://test.mockserviceworker.io/', 89 | it: { 90 | matches: true, 91 | params: null, 92 | }, 93 | }, 94 | ], 95 | }, 96 | { 97 | given: `/resource\\('id'\\)`, 98 | when: [ 99 | { 100 | actual: `/resource('id')`, 101 | it: { 102 | matches: true, 103 | params: null, 104 | }, 105 | }, 106 | { 107 | actual: `/resource('foo')`, 108 | it: { 109 | matches: false, 110 | params: null, 111 | }, 112 | }, 113 | { 114 | actual: '/resource', 115 | it: { 116 | matches: false, 117 | params: null, 118 | }, 119 | }, 120 | ], 121 | }, 122 | ]) 123 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "target": "es2015", 5 | "declaration": true, 6 | "declarationDir": "./lib", 7 | "esModuleInterop": true, 8 | "noImplicitAny": true, 9 | "strictNullChecks": true 10 | }, 11 | "include": ["src/**/*.ts"], 12 | "exclude": ["node_modules", "test/**/*", "**/*.test.ts"] 13 | } 14 | --------------------------------------------------------------------------------