Skip to content

Commit f0ddd0f

Browse files
committed
improve docs
1 parent 7e20da4 commit f0ddd0f

3 files changed

Lines changed: 9 additions & 29 deletions

File tree

ark/regex/README.md

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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
1010
import { regex } from "arkregex"
1111

12+
const ok = regex("^ok$", "i")
13+
// ^ Regex<"ok" | "oK" | "Ok" | "OK", { flags: "i" }>
14+
1215
const 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

1518
const 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?

ark/regex/__tests__/regex.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,3 +1343,5 @@ contextualize(() => {
13431343
})
13441344
})
13451345
})
1346+
1347+
const ok = regex("^ok$", "i")

ark/regex/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "arkregex",
3-
"description": "A drop-in replacement for `new RegExp()` with types",
3+
"description": "A drop-in replacement for new RegExp() with types",
44
"version": "0.0.1",
55
"license": "MIT",
66
"author": {

0 commit comments

Comments
 (0)