11# arkregex
22
3- A drop-in replacement for ` new RegExp() ` with types.
3+ A drop-in replacement for ` new RegExp() ` with types
44
55## Usage
66
@@ -9,11 +9,14 @@ The `regex` function creates a `Regex` instance with types for `.test()`, `.exec
99``` ts
1010import { regex } from " arkregex"
1111
12+ const ok = regex (" ^ok$" , " i" )
13+ // ^ Regex<"ok" | "oK" | "Ok" | "OK", { flags: "i" }>
14+
1215const semver = regex (" ^(\\ d*)\\ .(\\ d*)\\ .(\\ d*)$" )
13- // Type: Regex<`${bigint}.${bigint}.${bigint}`, { captures: [`${bigint}`, `${bigint}`, `${bigint}`] }>
16+ // ^ Regex<`${bigint}.${bigint}.${bigint}`, { captures: [`${bigint}`, `${bigint}`, `${bigint}`] }>
1417
1518const email = regex (" ^(?<name>\\ w+)@(?<domain>\\ w+\\ .\\ w+)$" )
16- // Type: Regex<`${string}@${string}.${string}`, { names: { name: string; domain: `${string}.${string}`; }; ...>
19+ // ^ Regex<`${string}@${string}.${string}`, { names: { name: string; domain: `${string}.${string}`; }; ...>
1720```
1821
1922## Features
@@ -23,31 +26,6 @@ const email = regex("^(?<name>\\w+)@(?<domain>\\w+\\.\\w+)$")
2326- ** Safety** : Syntax errors like referencing a group that doesn't exist are now type errors
2427- ** Zero Runtime** : Improves your type safety without impacting your bundle size[ \* ] ( #footnote )
2528
26- ## Examples
27-
28- ``` ts
29- // Anchored patterns
30- const start = regex (" ^hello" ) // Type: Regex<`hello${string}`, {}>
31- const end = regex (" world$" ) // Type: Regex<`${string}world`, {}>
32- const exact = regex (" ^hello$" ) // Type: Regex<"hello", {}>
33-
34- // Quantifiers
35- const optional = regex (" ^colou?r$" ) // Type: Regex<"color" | "colour", {}>
36- const multiple = regex (" ^a+$" ) // Type: Regex<`a${string}`, {}>
37-
38- // Character classes
39- const digits = regex (" ^\\ d+$" ) // Type: Regex<`${bigint}`, {}>
40- const words = regex (" ^\\ w+$" ) // Type: Regex<string, {}>
41-
42- // Capture groups
43- const captured = regex (" ^(\\ w+):(\\ d+)$" )
44- // Type: Regex<`${string}:${bigint}`, { captures: [string, `${bigint}`] }>
45-
46- // Case-insensitive flag
47- const caseInsensitive = regex (" ^ok$" , " i" )
48- // Type: Regex<"ok" | "oK" | "Ok" | "OK", { flags: "i" }>
49- ```
50-
5129## FAQ
5230
5331### Why aren't some patterns like ` [a-Z] ` inferred more precisely?
0 commit comments