You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ark/docs/public/llms.txt
+12-14Lines changed: 12 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -354,7 +354,13 @@ title: Announcing arkregex
354
354
description: A drop-in replacement for new RegExp() with types
355
355
---
356
356
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.
- **Types**: Infers string types for your existing regular expressions, including positional and named captures
375
381
- **Parity**: Supports 100% of [features](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions) allowed by `new RegExp()`
376
382
- **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
378
384
379
-
## FAQ
385
+
### FAQ
380
386
381
-
### Why aren't some patterns like `[a-Z]` inferred more precisely?
387
+
#### Why aren't some patterns like `[a-Z]` inferred more precisely?
382
388
383
389
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.
384
390
385
391
We've tried to strike a balance between performance and precision while guaranteeing that the inferred types are at worst imprecise and never incorrect.
386
392
387
-
### Why doesn't it work with my massive RegExp?
393
+
#### Why doesn't it work with my massive RegExp?
388
394
389
395
If your expression is especially long or complex, TypeScript won't be able to infer it.
0 commit comments