Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Get down to 1KB. Reimplement a subset of path-to-regexpΒ #1

@molefrog

Description

@molefrog

Right now the gzipped library size is 2KB, 70% of which is path-to-regexp dependency. While path-to-regexp provides a well-known way for developer to describe routes, it seems like we could shrink it's functionality to cover the 99% of use cases.

It would be cool to reimplement a limited subset of the library, so that:

  1. We drop that dependency and make it a zero-dependency library 😎
  2. We reduce the size to be less than 1KB (current bundle size without a matcher is 686B).

For users who still want to use the path-to-regexp functionality and get an advanced syntax we could provide an optional entry point:

import { Router } from "wouter";
import makeMatcher from "wouter/matcher"; 
import pathToRegexp from "path-to-regexp";

<Router matchFn={makeMatcher(pathToRegexp)}>
  ...
</Router>

So ideally it would be nice to define a subset of features we would like to support. Here are my ideas:

  • Always case-insensitive
  • Ignores a slash at the end
  • Matches an entire path
  • Supports named segments /:foo/:bar
  • Supports modifiers: :foo?, :foo* and :foo+
  • No support for unnamed params. All params should have a name.
  • No segment constraints e.g. /:foo(\d+)/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions