lukeed

Send help, I wrote another router

Before writing yet another router, I read everyone else's. Four things stood out.

First, there are far more of them than there were before Polka and Worktop. Second, regexparam is everywhere. Third, most projects inline it rather than import it, sometimes with a link back, sometimes not. I get it: copying 300 bytes is easier than adding a dependency.

import { parse } from 'regexparam';

let { keys, pattern } = parse('/books/:genre/:title?');
pattern.test('/books/horror');          // true
pattern.exec('/books/horror/goosebumps'); // ['…', 'horror', 'goosebumps']

Fourth, and the one that worried me: native URLPattern is still much slower than a compiled RegExp for the same match. It is not a strict one-to-one comparison, since URLPattern does more. But I hoped the native path would be the fast one by now.

So yes. I wrote another router.

— lukeed,