1.4.0 • Published 4 months ago

@dressed/matcher v1.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

@dressed/matcher

A tiny utility for creating regexes using expressive, customizable patterns.

🧩 Pattern Syntax

SyntaxDescription
:<argname>Defines a named argument
{...}Marks content inside as optional
(...)Content inside is a custom regex
And more!Easily plug in your own tokens

You can pair arguments with custom regexes to make sure the argument value matches the regex.

Input: i-love-:animal(dogs|cats)\ Output: /^i-love-(?\<animal>(?:dogs|cats))$/\ Will match:

  • i-love-dogs
  • i-love-cats

Examples:

  1. button-:variant matches button-primary, button-secondary, etc.
  2. wait{-:length} matches wait, wait-100, wait-200, etc.
    • For better verboseness, you could use wait{-:length(\d)}
  3. ticket-(open|close) matches ticket-open, ticket-close
  4. ticket-action:(open|close) is the same as 3, except the action is captured

🧮 scorePattern()

Score the pattern based on how dynamic it is (higher is less dynamic)

"my-button"; // Granular
"my-:component"; // Less specific
":name"; // Open-ended

🔮 Params<pattern>

Generates the type that a regex returned options would be.

The returned type is not completely exhaustive, but it provides a pretty good representation.

Params<"i love :animal(dogs|cats)">; // { animal: "dogs" | "cats" }
1.4.0

4 months ago

1.3.0

4 months ago

1.2.0

5 months ago

1.1.0

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago