Skip to content

Commit ffdc1e5

Browse files
committed
bump
1 parent d398402 commit ffdc1e5

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

ark/docs/public/llms.txt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,13 @@ title: Announcing arkregex
354354
description: A drop-in replacement for new RegExp() with types
355355
---
356356

357-
The `regex` function creates a `Regex` instance with types for `.test()`, `.exec()` and more, statically parsed from native JS syntax.
357+
Regular expressions are ubiquitous in modern code.
358+
359+
A few characters sprinkled into your JavaScript can validate and parse strings that would require dozens of lines of imperative logic.
360+
361+
However, that concision comes at a cost. Complex expressions can be hard to understand and type safety is a pipe dream- or at least, it was.
362+
363+
Introducing `arkregex`, a type-safe wrapper of `new RegExp()`. The `regex` function creates a `Regex` instance with types for `.test()`, `.exec()` and more, statically parsed from native JS syntax.
358364

359365
```ts
360366
import { regex } from "arkregex"
@@ -369,22 +375,22 @@ const email = regex("^(?<name>\\w+)@(?<domain>\\w+\\.\\w+)$")
369375
// ^ Regex<`${string}@${string}.${string}`, { names: { name: string; domain: `${string}.${string}`; }; ...>
370376
```
371377

372-
## Features
378+
### Features
373379

374380
- **Types**: Infers string types for your existing regular expressions, including positional and named captures
375381
- **Parity**: Supports 100% of [features](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions) allowed by `new RegExp()`
376382
- **Safety**: Syntax errors like referencing a group that doesn't exist are now type errors
377-
- **Zero Runtime**: Improves your type safety without impacting your bundle size[\*](#footnote)
383+
- **Zero Runtime**: Improves your type safety without impacting your bundle size
378384

379-
## FAQ
385+
### FAQ
380386

381-
### Why aren't some patterns like `[a-Z]` inferred more precisely?
387+
#### Why aren't some patterns like `[a-Z]` inferred more precisely?
382388

383389
Constructing string literal types for these sorts of expressions is combinatorial and will explode very quickly if we infer character ranges like this as literal characters.
384390

385391
We've tried to strike a balance between performance and precision while guaranteeing that the inferred types are at worst imprecise and never incorrect.
386392

387-
### Why doesn't it work with my massive RegExp?
393+
#### Why doesn't it work with my massive RegExp?
388394

389395
If your expression is especially long or complex, TypeScript won't be able to infer it.
390396

@@ -396,14 +402,6 @@ const complexPattern = regex.cast<`pattern-${string}`, { captures: [string] }>(
396402
)
397403
```
398404

399-
<a id="footnote"></a>
400-
\*The actual runtime bundle size is two lines:
401-
402-
```js
403-
export const regex = (src, flags) => new RegExp(src, flags)
404-
Object.assign(regex, { cast: regex })
405-
```
406-
407405
<MainAutoplayDemo />
408406

409407
⚡ [Starting coding](/docs/intro/setup)

0 commit comments

Comments
 (0)