arktype 3.0.0-beta.1 → 3.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (312) hide show
  1. package/README.md +48 -144
  2. package/out/_internal/regex/charset.d.ts +24 -0
  3. package/out/_internal/regex/escape.d.ts +29 -0
  4. package/out/_internal/regex/execArray.d.ts +24 -0
  5. package/out/_internal/regex/group.d.ts +34 -0
  6. package/out/_internal/regex/index.d.ts +2 -0
  7. package/out/_internal/regex/internal.d.ts +9 -0
  8. package/out/_internal/regex/parse.d.ts +10 -0
  9. package/out/_internal/regex/quantify.d.ts +59 -0
  10. package/out/_internal/regex/regex.d.ts +38 -0
  11. package/out/_internal/regex/state.d.ts +383 -0
  12. package/out/_internal/schema/codecs.d.ts +2 -0
  13. package/out/_internal/schema/config.d.ts +103 -0
  14. package/out/_internal/schema/constraint.d.ts +78 -0
  15. package/out/_internal/schema/errors.d.ts +1 -0
  16. package/out/_internal/schema/generic.d.ts +85 -0
  17. package/out/_internal/schema/i18n.d.ts +3 -0
  18. package/out/_internal/schema/index.d.ts +54 -0
  19. package/out/_internal/schema/internal.d.ts +15 -0
  20. package/out/_internal/schema/intrinsic.d.ts +28 -0
  21. package/out/_internal/schema/kinds.d.ts +76 -0
  22. package/out/_internal/schema/module.d.ts +23 -0
  23. package/out/_internal/schema/mutatesInput.d.ts +2 -0
  24. package/out/_internal/schema/node.d.ts +349 -0
  25. package/out/_internal/schema/parse.d.ts +77 -0
  26. package/out/_internal/schema/parseSchema.d.ts +116 -0
  27. package/out/_internal/schema/predicate.d.ts +46 -0
  28. package/out/_internal/schema/refinements/after.d.ts +32 -0
  29. package/out/_internal/schema/refinements/before.d.ts +32 -0
  30. package/out/_internal/schema/refinements/divisor.d.ts +41 -0
  31. package/out/_internal/schema/refinements/exactLength.d.ts +43 -0
  32. package/out/_internal/schema/refinements/kinds.d.ts +40 -0
  33. package/out/_internal/schema/refinements/max.d.ts +33 -0
  34. package/out/_internal/schema/refinements/maxLength.d.ts +32 -0
  35. package/out/_internal/schema/refinements/min.d.ts +33 -0
  36. package/out/_internal/schema/refinements/minLength.d.ts +32 -0
  37. package/out/_internal/schema/refinements/notEqual.d.ts +38 -0
  38. package/out/_internal/schema/refinements/notEqualLength.d.ts +38 -0
  39. package/out/_internal/schema/refinements/pattern.d.ts +43 -0
  40. package/out/_internal/schema/refinements/range.d.ts +101 -0
  41. package/out/_internal/schema/roots/alias.d.ts +49 -0
  42. package/out/_internal/schema/roots/basis.d.ts +12 -0
  43. package/out/_internal/schema/roots/domain.d.ts +45 -0
  44. package/out/_internal/schema/roots/intersection.d.ts +72 -0
  45. package/out/_internal/schema/roots/morph.d.ts +59 -0
  46. package/out/_internal/schema/roots/proto.d.ts +42 -0
  47. package/out/_internal/schema/roots/root.d.ts +163 -0
  48. package/out/_internal/schema/roots/union.d.ts +146 -0
  49. package/out/_internal/schema/roots/unit.d.ts +36 -0
  50. package/out/_internal/schema/runtime.d.ts +29 -0
  51. package/out/_internal/schema/runtimeLean.d.ts +2 -0
  52. package/out/_internal/schema/runtimeNone.d.ts +2 -0
  53. package/out/_internal/schema/runtimeNoneLean.d.ts +2 -0
  54. package/out/_internal/schema/scope.d.ts +203 -0
  55. package/out/_internal/schema/shared/codecs.d.ts +5 -0
  56. package/out/_internal/schema/shared/compile.d.ts +144 -0
  57. package/out/_internal/schema/shared/configured.d.ts +14 -0
  58. package/out/_internal/schema/shared/declare.d.ts +100 -0
  59. package/out/_internal/schema/shared/disjoint.d.ts +45 -0
  60. package/out/_internal/schema/shared/enWriters.d.ts +30 -0
  61. package/out/_internal/schema/shared/errorModes.d.ts +25 -0
  62. package/out/_internal/schema/shared/errorWriters.d.ts +34 -0
  63. package/out/_internal/schema/shared/errors.d.ts +264 -0
  64. package/out/_internal/schema/shared/implement.d.ts +154 -0
  65. package/out/_internal/schema/shared/inPlace.d.ts +8 -0
  66. package/out/_internal/schema/shared/issueFeatures.d.ts +38 -0
  67. package/out/_internal/schema/shared/issues.d.ts +261 -0
  68. package/out/_internal/schema/shared/issuesLean.d.ts +80 -0
  69. package/out/_internal/schema/shared/issuesNone.d.ts +22 -0
  70. package/out/_internal/schema/shared/issuesNoneLean.d.ts +20 -0
  71. package/out/_internal/schema/shared/issuesUndetailed.d.ts +25 -0
  72. package/out/_internal/schema/shared/jsonSchema.d.ts +153 -0
  73. package/out/_internal/schema/shared/listed.d.ts +15 -0
  74. package/out/_internal/schema/shared/locale.d.ts +149 -0
  75. package/out/_internal/schema/shared/registry.d.ts +16 -0
  76. package/out/_internal/schema/shared/render.d.ts +3 -0
  77. package/out/_internal/schema/shared/rootApply.d.ts +19 -0
  78. package/out/_internal/schema/shared/sets.d.ts +26 -0
  79. package/out/_internal/schema/shared/standardFailure.d.ts +22 -0
  80. package/out/_internal/schema/shared/standardSchema.d.ts +124 -0
  81. package/out/_internal/schema/shared/toJsonSchema.d.ts +229 -0
  82. package/out/_internal/schema/shared/transform.d.ts +35 -0
  83. package/out/_internal/schema/shared/traversal.d.ts +288 -0
  84. package/out/_internal/schema/shared/utils.d.ts +59 -0
  85. package/out/_internal/schema/structure/index.d.ts +43 -0
  86. package/out/_internal/schema/structure/optional.d.ts +61 -0
  87. package/out/_internal/schema/structure/prop.d.ts +45 -0
  88. package/out/_internal/schema/structure/required.d.ts +49 -0
  89. package/out/_internal/schema/structure/sequence.d.ts +127 -0
  90. package/out/_internal/schema/structure/shared.d.ts +3 -0
  91. package/out/_internal/schema/structure/structure.d.ts +178 -0
  92. package/out/_internal/schema/units.d.ts +123 -0
  93. package/out/_internal/sets/algebra.d.ts +26 -0
  94. package/out/_internal/sets/constraint.d.ts +19 -0
  95. package/out/_internal/sets/engine.d.ts +2 -0
  96. package/out/_internal/sets/formats.d.ts +23 -0
  97. package/out/_internal/sets/fromJsonSchema.d.ts +15 -0
  98. package/out/_internal/sets/implement.d.ts +16 -0
  99. package/out/_internal/sets/index.d.ts +2 -0
  100. package/out/_internal/sets/internal.d.ts +20 -0
  101. package/out/_internal/sets/intersections.d.ts +5 -0
  102. package/out/_internal/sets/kinds.d.ts +3 -0
  103. package/out/_internal/sets/refinements.d.ts +14 -0
  104. package/out/_internal/sets/roots/alias.d.ts +3 -0
  105. package/out/_internal/sets/roots/domain.d.ts +3 -0
  106. package/out/_internal/sets/roots/intersection.d.ts +4 -0
  107. package/out/_internal/sets/roots/morph.d.ts +4 -0
  108. package/out/_internal/sets/roots/proto.d.ts +3 -0
  109. package/out/_internal/sets/roots/union.d.ts +16 -0
  110. package/out/_internal/sets/roots/unit.d.ts +3 -0
  111. package/out/_internal/sets/structure/index.d.ts +3 -0
  112. package/out/_internal/sets/structure/prop.d.ts +8 -0
  113. package/out/_internal/sets/structure/sequence.d.ts +3 -0
  114. package/out/_internal/sets/structure/structure.d.ts +3 -0
  115. package/out/_internal/sets/toJsonSchema.d.ts +25 -0
  116. package/out/_internal/util/arrays.d.ts +130 -0
  117. package/out/_internal/util/clone.d.ts +4 -0
  118. package/out/_internal/util/describe.d.ts +25 -0
  119. package/out/_internal/util/domain.d.ts +49 -0
  120. package/out/_internal/util/errors.d.ts +29 -0
  121. package/out/_internal/util/facts.d.ts +22 -0
  122. package/out/_internal/util/flatMorph.d.ts +41 -0
  123. package/out/_internal/util/formats.d.ts +8 -0
  124. package/out/_internal/util/functions.d.ts +33 -0
  125. package/out/_internal/util/generics.d.ts +65 -0
  126. package/out/_internal/util/get.d.ts +9 -0
  127. package/out/_internal/util/hkt.d.ts +27 -0
  128. package/out/_internal/util/i18n.d.ts +12 -0
  129. package/out/_internal/util/index.d.ts +28 -0
  130. package/out/_internal/util/internal.d.ts +2 -0
  131. package/out/_internal/util/intersections.d.ts +50 -0
  132. package/out/_internal/util/isomorphic.d.ts +8 -0
  133. package/out/_internal/util/keys.d.ts +18 -0
  134. package/out/_internal/util/lazily.d.ts +7 -0
  135. package/out/_internal/util/numbers.d.ts +82 -0
  136. package/out/_internal/util/objectKinds.d.ts +157 -0
  137. package/out/_internal/util/path.d.ts +16 -0
  138. package/out/_internal/util/primitive.d.ts +16 -0
  139. package/out/_internal/util/records.d.ts +173 -0
  140. package/out/_internal/util/registry.d.ts +13 -0
  141. package/out/_internal/util/scanner.d.ts +110 -0
  142. package/out/_internal/util/serialize.d.ts +40 -0
  143. package/out/_internal/util/strings.d.ts +35 -0
  144. package/out/_internal/util/traits.d.ts +89 -0
  145. package/out/_internal/util/unionToTuple.d.ts +14 -0
  146. package/out/_internal/util/weak.d.ts +8 -0
  147. package/out/attributes.d.ts +15 -11
  148. package/out/checkers.d.ts +1 -1
  149. package/out/chunk-22RQSVV3.js +0 -0
  150. package/out/chunk-3HZC67MT.js +965 -0
  151. package/out/chunk-3KBOPH3J.js +1564 -0
  152. package/out/chunk-3SH2BQ4T.js +15 -0
  153. package/out/chunk-46PLKNON.js +126 -0
  154. package/out/{chunk-G45P2CLE.js → chunk-4FTHWK63.js} +6 -1
  155. package/out/{chunk-UK5UGFOX.js → chunk-4HREHNIV.js} +23 -11
  156. package/out/chunk-4NZCLVBD.js +14 -0
  157. package/out/chunk-6FMBO47M.js +7 -0
  158. package/out/chunk-7TALAWYX.js +10 -0
  159. package/out/{chunk-DLWCO4RV.js → chunk-BCYKO54Z.js} +11 -2
  160. package/out/chunk-BDJVONP7.js +168 -0
  161. package/out/{chunk-E3DZXEZK.js → chunk-C2JOL5M2.js} +4 -2
  162. package/out/{chunk-2U2AWCI3.js → chunk-C2V6QPE3.js} +126 -97
  163. package/out/chunk-C3B4IFQL.js +6408 -0
  164. package/out/chunk-CWSF57VM.js +10 -0
  165. package/out/chunk-F5BACUJS.js +7 -0
  166. package/out/{chunk-EVCML554.js → chunk-FWRSDUJ2.js} +14 -5
  167. package/out/chunk-GID3FSQA.js +161 -0
  168. package/out/chunk-I2KLQ2HA.js +22 -0
  169. package/out/chunk-K7SLP5D2.js +84 -0
  170. package/out/chunk-KQPSKGUI.js +9 -0
  171. package/out/chunk-KXOC3JEX.js +8234 -0
  172. package/out/chunk-KXOSUYRA.js +405 -0
  173. package/out/chunk-LHNEY6QW.js +0 -0
  174. package/out/chunk-MTWKGAGO.js +323 -0
  175. package/out/chunk-NU73GNCX.js +170 -0
  176. package/out/{chunk-RAZ3TXOE.js → chunk-P5W67FQH.js} +34 -19
  177. package/out/chunk-PDLTEX6Z.js +1118 -0
  178. package/out/{chunk-VV6YDN2D.js → chunk-QUS4IAXJ.js} +304 -263
  179. package/out/chunk-R7WXIH5P.js +94 -0
  180. package/out/chunk-TACLEIDM.js +95 -0
  181. package/out/chunk-UJJGG4VQ.js +71 -0
  182. package/out/chunk-US6BWOGJ.js +109 -0
  183. package/out/chunk-VMMMOO4R.js +945 -0
  184. package/out/chunk-VYMXHSFR.js +439 -0
  185. package/out/chunk-W2XOI5DY.js +141 -0
  186. package/out/chunk-WC5L5YRP.js +25 -0
  187. package/out/{chunk-NRIGTMPM.js → chunk-WKOSL2G6.js} +4 -1
  188. package/out/chunk-XLG66ZDF.js +0 -0
  189. package/out/{chunk-5U2ZMDNI.js → chunk-XNUAQSJ4.js} +52 -30
  190. package/out/chunk-ZRYEHGSG.js +79 -0
  191. package/out/cli.d.ts +28 -0
  192. package/out/cli.js +636 -0
  193. package/out/codecs.d.ts +6 -5
  194. package/out/codecs.js +23 -7
  195. package/out/config.d.ts +5 -17
  196. package/out/config.js +11 -2
  197. package/out/declare.d.ts +40 -12
  198. package/out/deferred.d.ts +2 -2
  199. package/out/errors.d.ts +1 -1
  200. package/out/errors.js +10 -2
  201. package/out/fn.d.ts +20 -13
  202. package/out/fromJsonSchema.d.ts +18 -0
  203. package/out/generic.d.ts +9 -6
  204. package/out/i18n.d.ts +2 -2
  205. package/out/i18n.js +9 -2
  206. package/out/index.d.ts +16 -7
  207. package/out/index.js +25 -8
  208. package/out/internal.d.ts +4 -0
  209. package/out/internal.js +41 -17
  210. package/out/island.js +22 -6
  211. package/out/islandDependency.js +42 -18
  212. package/out/jsonSchema/infer.d.ts +805 -0
  213. package/out/jsonSchema/validate.d.ts +416 -0
  214. package/out/keywords/Array.d.ts +2 -2
  215. package/out/keywords/builtins.d.ts +3 -3
  216. package/out/keywords/constructors.d.ts +1 -1
  217. package/out/keywords/functions.d.ts +5 -192
  218. package/out/keywords/keywords.d.ts +3 -3
  219. package/out/keywords/number.d.ts +2 -2
  220. package/out/keywords/phrases.d.ts +4 -191
  221. package/out/keywords/string.d.ts +3 -3
  222. package/out/keywords/ts.d.ts +18 -18
  223. package/out/keywords/ts.js +19 -4
  224. package/out/locale.d.ts +6 -2
  225. package/out/locales/de.js +9 -2
  226. package/out/locales/en.js +21 -5
  227. package/out/match.d.ts +13 -10
  228. package/out/module.d.ts +2 -2
  229. package/out/mutatesInput.js +18 -3
  230. package/out/nary.d.ts +220 -194
  231. package/out/parser/ast/bounds.d.ts +2 -2
  232. package/out/parser/ast/default.d.ts +2 -2
  233. package/out/parser/ast/divisor.d.ts +2 -2
  234. package/out/parser/ast/generic.d.ts +2 -2
  235. package/out/parser/ast/infer.d.ts +1 -1
  236. package/out/parser/ast/keyof.d.ts +2 -2
  237. package/out/parser/ast/utils.d.ts +1 -1
  238. package/out/parser/ast/validate.d.ts +2 -2
  239. package/out/parser/definition.d.ts +4 -4
  240. package/out/parser/objectLiteral.d.ts +2 -2
  241. package/out/parser/property.d.ts +2 -2
  242. package/out/parser/reduce/dynamic.d.ts +2 -2
  243. package/out/parser/reduce/shared.d.ts +1 -1
  244. package/out/parser/reduce/static.d.ts +1 -1
  245. package/out/parser/shift/operand/enclosed.d.ts +2 -2
  246. package/out/parser/shift/operand/genericArgs.d.ts +2 -2
  247. package/out/parser/shift/operand/operand.d.ts +1 -1
  248. package/out/parser/shift/operand/unenclosed.d.ts +2 -2
  249. package/out/parser/shift/operand/unresolvable.d.ts +2 -2
  250. package/out/parser/shift/operator/bounds.d.ts +2 -2
  251. package/out/parser/shift/operator/brand.d.ts +2 -2
  252. package/out/parser/shift/operator/default.d.ts +4 -4
  253. package/out/parser/shift/operator/divisor.d.ts +1 -1
  254. package/out/parser/shift/operator/operator.d.ts +1 -1
  255. package/out/parser/shift/tokens.d.ts +1 -1
  256. package/out/parser/string.d.ts +2 -2
  257. package/out/parser/tupleExpressions.d.ts +6 -8
  258. package/out/parser/tupleLiteral.d.ts +2 -2
  259. package/out/precompiled.d.ts +1 -1
  260. package/out/precompiled.js +16 -2
  261. package/out/regex.d.ts +1 -0
  262. package/out/regex.js +2 -0
  263. package/out/runtime.d.ts +10 -8
  264. package/out/runtime.js +6 -4
  265. package/out/runtimeDevelopment.js +70 -52
  266. package/out/schema.d.ts +1 -0
  267. package/out/schema.js +15 -0
  268. package/out/schemaInternal.d.ts +1 -0
  269. package/out/schemaInternal.js +1401 -0
  270. package/out/schemaIssueFeatures.d.ts +1 -0
  271. package/out/schemaRuntime.d.ts +1 -0
  272. package/out/schemaRuntime.js +7 -0
  273. package/out/schemaRuntimeLean.d.ts +1 -0
  274. package/out/schemaRuntimeLean.js +1870 -0
  275. package/out/schemaRuntimeNone.d.ts +1 -0
  276. package/out/schemaRuntimeNone.js +1774 -0
  277. package/out/schemaRuntimeNoneLean.d.ts +1 -0
  278. package/out/schemaRuntimeNoneLean.js +1767 -0
  279. package/out/scope.d.ts +3 -4
  280. package/out/shared/issueFeatures.d.ts +38 -0
  281. package/out/shared/issueFeatures.js +40 -0
  282. package/out/standalone/artifact.d.ts +6 -6
  283. package/out/standalone/baking.d.ts +2 -2
  284. package/out/standalone/combinators.d.ts +1 -1
  285. package/out/standalone/compilers.d.ts +1 -1
  286. package/out/standalone/fallbacks.d.ts +1 -1
  287. package/out/standalone/keys.d.ts +1 -1
  288. package/out/standalone/sites.d.ts +3 -3
  289. package/out/standalone/units.d.ts +1 -1
  290. package/out/standalone/values.d.ts +1 -1
  291. package/out/type.d.ts +6 -6
  292. package/out/util.d.ts +1 -0
  293. package/out/util.js +137 -0
  294. package/out/variants/array.d.ts +6 -6
  295. package/out/variants/base.d.ts +61 -10
  296. package/out/variants/date.d.ts +5 -5
  297. package/out/variants/instantiate.d.ts +1 -1
  298. package/out/variants/number.d.ts +6 -6
  299. package/out/variants/object.d.ts +25 -12
  300. package/out/variants/string.d.ts +8 -8
  301. package/package.json +183 -8
  302. package/skills/arktype/SKILL.md +93 -93
  303. package/skills/arktype/references/migrating.md +144 -158
  304. package/skills/arktype/references/precompile.md +7 -7
  305. package/out/chunk-4CUA5XIP.js +0 -7
  306. package/out/chunk-GPNK5353.js +0 -2529
  307. package/out/chunk-MLKGABMK.js +0 -9
  308. package/out/chunk-PRTMQCHS.js +0 -3
  309. package/out/chunk-R5G57XC7.js +0 -7
  310. package/out/chunk-SWOOCAHN.js +0 -4
  311. package/out/chunk-TAHPKDNM.js +0 -3
  312. package/out/chunk-UETB6YE2.js +0 -14
package/README.md CHANGED
@@ -1,13 +1,34 @@
1
- <h1 align="center">ArkType</h1>
2
- <h3 align="center"><i>TypeScript's 1:1 validator, optimized from editor to runtime</i></h3>
1
+ <p align="center">
2
+ <a href="https://arktype.io">
3
+ <img
4
+ src="https://arktype.io/3/image/og.png"
5
+ width="720"
6
+ alt="ArkType — TypeScript's smallest, fastest validator. One prompt away."
7
+ />
8
+ </a>
9
+ </p>
3
10
 
4
11
  <p align="center">
5
- <a href="https://arktype.io/#board"><img src="https://arktype.io/image/og.png" width="640" alt="ArkType's places for validation speed, startup and bundle size, from the scoreboard at arktype.io" /></a>
12
+ <a href="https://arktype.io/docs/intro/setup"><strong>Docs</strong></a>
13
+ &nbsp;·&nbsp;
14
+ <a href="https://arktype.io/#board">Benchmarks</a>
15
+ &nbsp;·&nbsp;
16
+ <a href="https://arktype.io/docs/precompile">Precompile</a>
17
+ &nbsp;·&nbsp;
18
+ <a href="https://arktype.io/docs/migrating">Migrate from Zod</a>
19
+ &nbsp;·&nbsp;
20
+ <a href="https://arktype.io/playground">Playground</a>
21
+ &nbsp;·&nbsp;
22
+ <a href="https://arktype.io/discord">Discord</a>
6
23
  </p>
7
24
 
8
- Write a type the way TypeScript does. ArkType checks the definition as you type, infers the type and validates data against it at runtime.
25
+ ## Quick start
26
+
27
+ ```sh
28
+ npm install arktype
29
+ ```
9
30
 
10
- **Using Zod?** [Switch with one prompt](#switching-from-zod). Your schemas keep their names, their messages and the libraries that read them.
31
+ Write definitions in TypeScript's own syntax — inferred 1:1 and validated at runtime. Works with anything that takes [Standard Schema](https://standardschema.dev) (tRPC, Hono, React Hook Form, Drizzle, AI SDK, MCP SDK, and more).
11
32
 
12
33
  ```ts
13
34
  import { type } from "arktype"
@@ -33,158 +54,41 @@ if (out instanceof type.errors) {
33
54
  }
34
55
  ```
35
56
 
36
- ```sh
37
- npm install arktype
38
- ```
39
-
40
- - **Checked as you type.** A definition is parsed by TypeScript's own type system, so a typo is a type error where you wrote it.
41
- - **Precompiled when you build.** [`@ark/aot`](#precompile) replaces each Type with a standalone validator, so no parser ships and nothing compiles at startup. [arktype.io](https://arktype.io/#board) has the benchmarks against Zod, Valibot, Typia and ajv, each with its method.
42
- - **Accepted where Zod is.** Every Type is a [Standard Schema](https://standardschema.dev) that writes its own JSON Schema, so tRPC, oRPC, Hono, react-hook-form, the AI SDK and the MCP SDK [accept it](https://arktype.io/docs/integrations).
57
+ ## Migrate with one prompt
43
58
 
44
- ## Switching from Zod
59
+ 1. Add the ArkType [agent skill](https://arktype.io/docs/agents):
45
60
 
46
- One command, then one prompt to your coding agent:
47
-
48
- ```sh
49
- npx skills add arktypeio/arktype
50
- ```
61
+ ```sh
62
+ npx skills add arktypeio/arktype
63
+ ```
51
64
 
52
- ```
53
- Migrate this project from Zod to ArkType.
54
- ```
65
+ 2. Ask your coding agent:
55
66
 
56
- The [skill](https://arktype.io/docs/agents) teaches your agent ArkType and includes the [migration guide](https://arktype.io/docs/migrating) it follows. It converts each schema where it is, under the same name, keeping what the schema accepts, rejects and returns. Before removing `zod`, it runs each schema your tests don't cover against its Zod original on the same inputs, then runs your typecheck and tests. Where a dependency accepts only Zod, it keeps Zod for that call and tells you.
67
+ ```text
68
+ Migrate this project from Zod to ArkType.
69
+ ```
57
70
 
58
- ```ts
59
- // before
60
- import { z } from "zod"
71
+ See the [migration guide](https://arktype.io/docs/migrating) for Zod, Valibot, TypeBox, Yup, Joi, Effect Schema, and JSON Schema.
61
72
 
62
- const Signup = z.object({
63
- email: z.email("Enter a valid email"),
64
- password: z.string().min(8, "Use 8 or more characters"),
65
- role: z.enum(["admin", "member"])
66
- })
67
-
68
- type Signup = z.infer<typeof Signup>
69
- ```
70
-
71
- ```ts
72
- // after
73
- import { type } from "arktype"
74
-
75
- const Signup = type({
76
- email: ["string.email", "@", { message: "Enter a valid email" }],
77
- password: ["string >= 8", "@", { message: "Use 8 or more characters" }],
78
- role: "'admin' | 'member'"
79
- })
80
-
81
- type Signup = typeof Signup.infer
82
- ```
83
-
84
- ### What you keep
85
-
86
- **Your messages.** A `message` is shown exactly as you wrote it and never includes the path, as Zod's `issue.message` doesn't. A form library reading either `Signup` above through Standard Schema gets the same path and message for each issue:
87
-
88
- ```ts
89
- Signup["~standard"].validate({ email: "x", password: "short", role: "admin" })
90
- // {
91
- // issues: [
92
- // { path: ["email"], message: "Enter a valid email", ... },
93
- // { path: ["password"], message: "Use 8 or more characters", ... }
94
- // ]
95
- // }
96
- ```
97
-
98
- A missing key says its value's message too, so it covers `required_error`. A refinement's message becomes `ctx.reject({ message, path })`, and `out.summary` names each path for a log: `email: Enter a valid email`.
99
-
100
- **Your integrations.** A library that accepts Zod through Standard Schema accepts the Type in the same call: tRPC's `.input()`, TanStack Form, `@t3-oss/env-*`, the AI SDK's `tool()` from v6 and v2 of the MCP SDK. `zodResolver` becomes `standardSchemaResolver`, and `zod-to-json-schema` becomes `Signup.toJsonSchema()`. The guide [lists each swap](https://arktype.io/docs/migrating#migrating-a-project).
101
-
102
- **Your pace.** A Zod schema works inside an ArkType definition, so you can convert one file at a time:
103
-
104
- ```ts
105
- // not converted yet
106
- const Address = z.object({ street: z.string(), city: z.string() })
107
-
108
- const User = type({ name: "string", address: Address })
109
- ```
110
-
111
- Not switching yet? [ArkSets](https://arktype.io/docs/sets) runs ArkType's set theory on the Zod schemas you have: `isSubset(v1, v2)` tells you whether a schema change still accepts everything the old one did.
112
-
113
- ### What changes
114
-
115
- These are the differences a migration has to handle. The guide covers each, and your agent reports any it couldn't keep identical.
116
-
117
- - **Defaults differ.** `z.object()` removes undeclared keys and `.optional()` accepts `undefined`. ArkType keeps undeclared keys and treats an optional key as TypeScript's `exactOptionalPropertyTypes` does, so the migration sets `onUndeclaredKey: "delete"` once and writes `"key?": "T | undefined"`. [Defaults that differ](https://arktype.io/docs/migrating#defaults-that-differ) has the full table.
118
- - **Validation is synchronous.** An async `.refine()` moves out of the schema, to run after validation.
119
- - **A check across keys runs last.** A `.narrow()` on an object runs once every key is valid, where Zod 4 also runs a `.refine()` when a key fails a check like `.min()`.
120
- - **Default error text is ArkType's.** `must be an email address` where Zod says `Invalid email address`. Messages you wrote are unchanged.
121
-
122
- <details>
123
- <summary><b>Zod to ArkType, the common cases</b></summary>
124
-
125
- | Zod | ArkType |
126
- | ----------------------------------------- | ----------------------------------------------------------- |
127
- | `z.object({ ... })` | `type({ ... })` |
128
- | `z.string().min(1).max(100)` | `"1 <= string <= 100"` |
129
- | `z.string().email()`, `.url()`, `.uuid()` | `"string.email"`, `"string.url"`, `"string.uuid"` |
130
- | `z.number().int().positive()` | `"number.integer > 0"` |
131
- | `z.enum(["a", "b"])` | `"'a' \| 'b'"` |
132
- | `z.array(z.string()).min(1)` | `"string[] >= 1"` |
133
- | `z.union([A, B])`, `z.discriminatedUnion` | `A.or(B)`, which finds the discriminant itself |
134
- | `.extend({ ... })` | `.merge({ ... })` |
135
- | `.refine(fn, message)` | `.narrow((v, ctx) => fn(v) \|\| ctx.reject({ message }))` |
136
- | `.transform(fn)` | `.pipe(fn)` |
137
- | `z.infer<typeof T>`, `z.input` | `typeof T.infer`, `typeof T.inferIn` |
138
- | `T.parse(x)`, `T.safeParse(x)` | `T.assert(x)`, `T(x)` checked with `instanceof type.errors` |
73
+ ## Docs
139
74
 
140
- </details>
75
+ - **[Get started](https://arktype.io/docs/intro/setup)** — installation, editor setup, and your first type
76
+ - **[Precompile](https://arktype.io/docs/precompile)** — compile Types at build time with `@ark/aot`
77
+ - **[Benchmarks](https://arktype.io/#board)** — speed, startup, and bundle size, with methods and rerun commands
78
+ - **[Migration guide](https://arktype.io/docs/migrating)** — from Zod, Valibot, TypeBox, Yup, Joi, Effect Schema, and JSON Schema
79
+ - **[With agents](https://arktype.io/docs/agents)** — the skill and Markdown docs at [arktype.io/llms.txt](https://arktype.io/llms.txt)
80
+ - **[What's new in 3.0](https://arktype.io/docs/blog/3.0)** — release notes and [upgrading from 2.x](https://arktype.io/docs/upgrading)
141
81
 
142
- The guide maps [the whole Zod API](https://arktype.io/docs/migrating#zod), and has tables for Valibot, TypeBox, Yup, Joi, Effect Schema and JSON Schema.
82
+ ## CLI
143
83
 
144
- ## Precompile
84
+ `arktype` ships the `ark` binary (`init`, `migrate`, `skill`, and `check` / `emit` / `declare` via `@ark/aot`). Inside an installed project, run `pnpm exec ark` (or `npx arktype` everywhere — `ark` on npm is an unrelated package):
145
85
 
146
86
  ```sh
147
- npm install -D @ark/aot
148
- ```
149
-
150
- ```ts
151
- // vite.config.ts
152
- import { precompile } from "@ark/aot/unplugin"
153
-
154
- export default {
155
- plugins: [precompile.vite()]
156
- }
87
+ npx arktype init # create ark.json and install the bundled skill
88
+ npx arktype migrate # install the skill and print a migration prompt
89
+ npx arktype check # run @ark/aot --check
157
90
  ```
158
91
 
159
- When you build, each Type your program defines becomes a validator with only the checks it needs, on `arktype/runtime`. The code that calls it doesn't change, and neither do your definitions or the types they infer.
160
-
161
- - **Plugins** for Vite, Rollup, Rolldown, webpack, Rspack, esbuild, Bun and Farm, with drivers for Node, Bun's runtime and Next's Turbopack. Without a bundler, run `tsc && npx arktype-precompile --emit`. [Setup](https://arktype.io/docs/precompile/setup) has a config for each.
162
- - **Errors that name the fix.** A definition the build can't precompile, like one built from a value known only at runtime, fails the build with its file, line, reason and what to write instead. `npx arktype-precompile --check "src/**/*.ts"` lists them before you switch.
163
- - **Dynamic when you need it.** `type()` still parses definitions at runtime with no build step, and a precompiled build can leave any definition to it.
164
-
165
- [Precompile](https://arktype.io/docs/precompile) has the benchmarks, the build times and how a precompiled validator differs.
166
-
167
- ## With agents
168
-
169
- - `npx skills add arktypeio/arktype` adds the [skill](https://arktype.io/docs/agents): current syntax, how it maps to TypeScript, the mistakes to avoid and how to work in a precompiled project.
170
- - Every docs page is Markdown at its URL plus `.md`, and [arktype.io/llms.txt](https://arktype.io/llms.txt) indexes them.
171
- - Every error names its fix, from `tsc`, from the build and from validation, so an agent can act on each without a docs lookup.
172
-
173
- ## New in 3.0
174
-
175
- - [Precompilation](https://arktype.io/docs/precompile) with `@ark/aot`
176
- - [Codecs](https://arktype.io/docs/codecs): `codec` pairs a morph with its inverse, and `.encode` inverts a Type's morphs
177
- - [Errors as plain objects](https://arktype.io/docs/errors), each with a `path`, a `code` and a `message`
178
- - [Error messages in other languages](https://arktype.io/docs/i18n)
179
- - [JSON Schema](https://arktype.io/docs/json-schema/to-json-schema) for draft 2020-12, draft-07 and OpenAPI 3.0, from every Type
180
- - [ArkSets](https://arktype.io/docs/sets): `isSubset(v1, v2)` and the rest of ArkType's set algebra, for Types, JSON Schemas and Standard JSON Schemas like Zod's
181
-
182
- The [announcement](https://arktype.io/docs/blog/3.0) has the rest, and [Upgrading](https://arktype.io/docs/upgrading) lists each breaking change since 2.2 with what to write instead.
183
-
184
- ## Docs
185
-
186
- [arktype.io](https://arktype.io/docs/intro/setup)
187
-
188
92
  ## Contributions
189
93
 
190
94
  We accept and encourage pull requests from outside ArkType. Planned work is tracked in [this GitHub project](https://github.com/orgs/arktypeio/projects/4).
@@ -0,0 +1,24 @@
1
+ import type { Backslash, contains, ErrorMessage, noSuggest, Scanner, writeUnclosedGroupMessage } from "../util/index.js";
2
+ import type { NonZeroDigit, RegexClassChar, StringDigit, writeUnnecessaryEscapeMessage } from "./escape.ts";
3
+ import type { UnicodeFlag } from "./regex.ts";
4
+ import type { Control, s, State } from "./state.ts";
5
+ export type parseCharset<s extends State, unscanned extends string> = Scanner.shiftUntilEscapable<unscanned, "]", Backslash> extends (Scanner.shiftResult<infer scanned, infer nextUnscanned>) ? nextUnscanned extends `]${infer remaining}` ? scanned extends Scanner.shift<"^", string> ? s.shiftQuantifiable<s, string, remaining> : parseNonNegatedCharset<scanned, never, null, contains<s["flags"], UnicodeFlag>> extends infer result extends string ? [
6
+ result
7
+ ] extends [never] ? s.error<emptyCharacterSetMessage> : result extends ErrorMessage ? s.error<result> : s.shiftQuantifiable<s, result, remaining> : never : s.error<writeUnclosedGroupMessage<"]">> : never;
8
+ type parseNonNegatedCharset<chars extends string, set extends string, lastChar extends string | null, unicode extends boolean> = parseChar<chars, unicode> extends (Scanner.shiftResult<infer result, infer unscanned>) ? result extends UnescapedDashMarker ? parseDash<unscanned, set, lastChar, unicode> : result extends ErrorMessage ? result : parseNonNegatedCharset<unscanned, set | result, result, unicode> : set;
9
+ type parseDash<unscanned extends string, set extends string, lastChar extends string | null, unicode extends boolean> = lastChar extends string ? parseChar<unscanned, unicode> extends (Scanner.shiftResult<infer rangeEnd, infer next>) ? rangeEnd extends ErrorMessage ? rangeEnd : parseNonNegatedCharset<next, set | inferRange<lastChar, rangeEnd>, null, unicode> : // trailing -, treat as literal
10
+ set | "-" : parseNonNegatedCharset<unscanned, set | "-", "-", unicode>;
11
+ type inferRange<start extends string, end extends string> = start | end extends StringDigit ? `${number}` : string;
12
+ type UnescapedDashMarker = noSuggest<"dash">;
13
+ type parseChar<unscanned extends string, unicode extends boolean> = unscanned extends Scanner.shift<infer lookahead, infer next> ? lookahead extends Backslash ? next extends Scanner.shift<infer escaped, infer postEscaped> ? Scanner.shiftResult<parseEscapedSetChar<escaped, unicode>, postEscaped> : never : Scanner.shiftResult<lookahead extends "-" ? UnescapedDashMarker : lookahead, next> : null;
14
+ type parseEscapedSetChar<char extends string, unicode extends boolean> = char extends "b" ? "\b" : char extends "d" ? `${number}` : char extends keyof EscapedControlChars ? EscapedControlChars[char] : char extends "0" | "c" | "x" | "u" | "p" | "P" | "s" | RegexClassChar ? string : unicode extends true ? char extends Control | "/" ? char : ErrorMessage<writeUnnecessaryEscapeMessage<char>> : char extends NonZeroDigit ? string : char;
15
+ type EscapedControlChars = {
16
+ n: "\n";
17
+ t: "\t";
18
+ r: "\r";
19
+ f: "\f";
20
+ v: "\v";
21
+ };
22
+ export declare const emptyCharacterSetMessage = "Empty character set [] is unsatisfiable";
23
+ export type emptyCharacterSetMessage = typeof emptyCharacterSetMessage;
24
+ export {};
@@ -0,0 +1,29 @@
1
+ import type { ErrorMessage, Scanner } from "../util/index.js";
2
+ import type { Control, ReferenceNode, s, State } from "./state.ts";
3
+ export type parseEscape<s extends State, unscanned extends string> = unscanned extends Scanner.shift<infer char, infer nextUnscanned> ? char extends NonZeroDigit ? parseNumericBackreference<s, unscanned> : char extends "k" ? parseNamedBackreference<s, nextUnscanned> : char extends UnicodePropertyChar ? parseUnicodeProperty<s, char, nextUnscanned> : parseSingleEscapedCharacter<s, char, nextUnscanned> : s.error<trailingBackslashMessage>;
4
+ type parseNumericBackreference<s extends State, fullUnscanned extends string> = Scanner.shiftUntilNot<fullUnscanned, StringDigit> extends (Scanner.shiftResult<infer ref, infer remaining>) ? s.shiftQuantifiable<s, ReferenceNode<ref>, remaining> : never;
5
+ type parseNamedBackreference<s extends State, unscanned extends string> = unscanned extends `<${infer ref}>${infer following}` ? s.shiftQuantifiable<s, ReferenceNode<ref>, following> : s.error<missingBackreferenceNameMessage>;
6
+ type parseUnicodeProperty<s extends State, char extends UnicodePropertyChar, unscanned extends string> = unscanned extends `{${string}}${infer following}` ? s.shiftQuantifiable<s, string, following> : s.error<writeInvalidUnicodePropertyMessage<char>>;
7
+ type parseSingleEscapedCharacter<s extends State, char extends string, remaining extends string> = parseEscapedChar<char> extends infer result extends string ? result extends ErrorMessage ? s.error<result> : s.shiftQuantifiable<s, result, remaining> : never;
8
+ export type parseEscapedChar<char extends string> = char extends RegexClassChar | "s" ? string : char extends "d" ? `${number}` : char extends BoundaryChar ? "" : char extends Control ? char : char extends "c" ? ErrorMessage<caretNotationMessage> : char extends StringEscapableChar ? ErrorMessage<writeStringEscapableMessage<char>> : ErrorMessage<writeUnnecessaryEscapeMessage<char>>;
9
+ export declare const trailingBackslashMessage = "A regex cannot end with \\";
10
+ export type trailingBackslashMessage = typeof trailingBackslashMessage;
11
+ export declare const writeUnresolvableBackreferenceMessage: <ref extends string | number>(ref: ref) => writeUnresolvableBackreferenceMessage<ref>;
12
+ export type writeUnresolvableBackreferenceMessage<ref extends string | number> = `Group ${ref} does not exist`;
13
+ export declare const missingBackreferenceNameMessage = "\\k must be followed by a named reference like <name>";
14
+ export type missingBackreferenceNameMessage = typeof missingBackreferenceNameMessage;
15
+ export declare const writeInvalidUnicodePropertyMessage: <char extends UnicodePropertyChar>(char: char) => writeInvalidUnicodePropertyMessage<char>;
16
+ export type writeInvalidUnicodePropertyMessage<char extends UnicodePropertyChar> = `\\${char} must be followed by a property like \\${char}{Emoji_Presentation}`;
17
+ export declare const writeUnnecessaryEscapeMessage: <char extends string>(char: char) => writeUnnecessaryEscapeMessage<char>;
18
+ export type writeUnnecessaryEscapeMessage<char extends string> = `Escape preceding ${char} is unnecessary and should be removed.`;
19
+ export declare const writeStringEscapableMessage: (char: StringEscapableChar) => "\\0 should be specified with a single backslash like regex('\\n')" | "\\f should be specified with a single backslash like regex('\\n')" | "\\n should be specified with a single backslash like regex('\\n')" | "\\r should be specified with a single backslash like regex('\\n')" | "\\t should be specified with a single backslash like regex('\\n')" | "\\u should be specified with a single backslash like regex('\\n')" | "\\v should be specified with a single backslash like regex('\\n')" | "\\x should be specified with a single backslash like regex('\\n')";
20
+ export type writeStringEscapableMessage<char extends StringEscapableChar> = `\\${char} should be specified with a single backslash like regex('\n')`;
21
+ export declare const caretNotationMessage = "\\\\cX notation is not supported. Use hex (\\\\x) or unicode (\\\\u) instead.";
22
+ export type caretNotationMessage = "\\cX notation is not supported. Use hex (\\x) or unicode (\\u) instead.";
23
+ export type StringEscapableChar = "t" | "n" | "r" | "f" | "v" | "0" | "x" | "u";
24
+ export type RegexClassChar = "w" | "W" | "D" | "S";
25
+ export type BoundaryChar = "b" | "B";
26
+ export type UnicodePropertyChar = "p" | "P";
27
+ export type NonZeroDigit = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
28
+ export type StringDigit = "0" | NonZeroDigit;
29
+ export {};
@@ -0,0 +1,24 @@
1
+ import type { DynamicBase } from "../util/index.js";
2
+ import type { Flags, IndexedCaptures, NamedCaptures } from "./regex.ts";
3
+ export interface RegexExecArray<patternAndCaptures extends IndexedCaptures, namedCaptures extends NamedCaptures, flags extends Flags> extends DynamicBase<patternAndCaptures> {
4
+ /**
5
+ * The index of the search at which the result was found.
6
+ */
7
+ index: number;
8
+ /**
9
+ * A copy of the search string.
10
+ */
11
+ input: patternAndCaptures[0];
12
+ indices: flags extends `${string}d${string}` ? RegexIndicesArray<patternAndCaptures, namedCaptures> : undefined;
13
+ groups: keyof namedCaptures extends never ? undefined : namedCaptures;
14
+ }
15
+ export type RegexIndexRange = [start: number, end: number];
16
+ interface RegexIndicesArray<patternAndCaptures extends IndexedCaptures, namedCaptures extends NamedCaptures> extends DynamicBase<{
17
+ [i in keyof patternAndCaptures]: indexRangeOf<patternAndCaptures[i]>;
18
+ }> {
19
+ groups: keyof namedCaptures extends never ? undefined : {
20
+ [k in keyof namedCaptures]: indexRangeOf<namedCaptures[k]>;
21
+ };
22
+ }
23
+ type indexRangeOf<capture> = capture extends string ? RegexIndexRange : undefined;
24
+ export {};
@@ -0,0 +1,34 @@
1
+ import type { ErrorMessage, Scanner, writeUnclosedGroupMessage } from "../util/index.js";
2
+ import type { State, s } from "./state.ts";
3
+ type LookaroundChar = "=" | "!";
4
+ type lookaroundKindOf<char extends LookaroundChar> = char extends "=" ? State.UnnamedCaptureKind.lookaround : State.UnnamedCaptureKind.negativeLookaround;
5
+ export type ModifiableFlag = "i" | "m" | "s";
6
+ export type parseGroup<s extends State, unscanned extends string> = unscanned extends Scanner.shift<infer lookahead, infer next> ? lookahead extends "?" ? parseNonCapturingGroup<s, next> : s.pushGroup<s, State.UnnamedCaptureKind.indexed, unscanned, undefined> : s.error<writeUnclosedGroupMessage<")">>;
7
+ type parseNonCapturingGroup<s extends State, unscanned extends string> = unscanned extends Scanner.shift<infer lookahead, infer next> ? lookahead extends ":" ? s.pushGroup<s, State.UnnamedCaptureKind.noncapturing, next, undefined> : lookahead extends LookaroundChar ? s.pushGroup<s, lookaroundKindOf<lookahead>, next, undefined> : lookahead extends "<" ? parseNamedGroupOrLookbehind<s, next> : shiftModifiers<unscanned> extends (ShiftedModifiers<infer flags, infer negated, infer following>) ? following extends ErrorMessage<infer message> ? s.error<message> : s.pushGroup<s, State.UnnamedCaptureKind.noncapturing, following, "i" extends flags ? true : "i" extends negated ? false : undefined> : never : s.error<writeUnclosedGroupMessage<")">>;
8
+ type ShiftedModifiers<flags extends ModifiableFlag = ModifiableFlag, negated extends ModifiableFlag = ModifiableFlag, unscanned extends string = string> = [ParsedModifiers<flags, negated>, unscanned];
9
+ type ParsedModifiers<flags extends ModifiableFlag = ModifiableFlag, negated extends ModifiableFlag = ModifiableFlag> = {
10
+ flags: flags;
11
+ negated: negated;
12
+ };
13
+ type shiftModifiers<unscanned extends string> = Scanner.shiftUntil<unscanned, ":" | ")"> extends (Scanner.shiftResult<infer scanned, infer next>) ? next extends Scanner.shift<infer terminator, infer following> ? terminator extends ":" ? parseModifiers<scanned> extends (ParsedModifiers<infer flags, infer negated>) ? ShiftedModifiers<flags, negated, following> : ShiftedModifiers<never, never, ErrorMessage<parseModifiers<scanned> & string>> : ShiftedModifiers<never, never, ErrorMessage<unescapedLiteralQuestionMarkMessage>> : ShiftedModifiers<never, never, ErrorMessage<writeUnclosedGroupMessage<")">>> : never;
14
+ type parseModifiers<unscanned extends string> = _parseModifiers<unscanned, never, never>;
15
+ type _parseModifiers<unscanned extends string, flags extends ModifiableFlag, negated extends ModifiableFlag> = unscanned extends Scanner.shift<infer lookahead, infer next> ? lookahead extends "-" ? [
16
+ negated
17
+ ] extends [never] ? next extends Scanner.shift<infer modifier, infer next> ? modifier extends ModifiableFlag ? modifier extends flags | negated ? writeDuplicateModifierMessage<modifier> : _parseModifiers<next, flags, negated | modifier> : writeInvalidModifierMessage<modifier> : missingNegatedModifierMessage : multipleModifierDashesMessage : lookahead extends ModifiableFlag ? lookahead extends flags | negated ? writeDuplicateModifierMessage<lookahead> : [
18
+ negated
19
+ ] extends [never] ? _parseModifiers<next, flags | lookahead, negated> : _parseModifiers<next, flags, negated | lookahead> : writeInvalidModifierMessage<lookahead> : ParsedModifiers<flags, negated>;
20
+ export declare const writeDuplicateModifierMessage: <modifier extends ModifiableFlag>(modifier: modifier) => writeDuplicateModifierMessage<modifier>;
21
+ type writeDuplicateModifierMessage<modifier extends ModifiableFlag> = `Modifier ${modifier} cannot appear multiple times in a single group`;
22
+ export declare const multipleModifierDashesMessage = "Modifiers can include at most one '-' to negate subsequent flags";
23
+ type multipleModifierDashesMessage = typeof multipleModifierDashesMessage;
24
+ export declare const missingNegatedModifierMessage = "- must be followed by the modifier flag to negate ('i', 'm' or 's')";
25
+ type missingNegatedModifierMessage = typeof missingNegatedModifierMessage;
26
+ export declare const writeInvalidModifierMessage: <char extends string>(char: char) => writeInvalidModifierMessage<char>;
27
+ type writeInvalidModifierMessage<char extends string> = `Modifier flag ${char} must be 'i', 'm' or 's'`;
28
+ type parseNamedGroupOrLookbehind<s extends State, unscanned extends string> = unscanned extends (Scanner.shift<infer char extends LookaroundChar, infer next>) ? s.pushGroup<s, lookaroundKindOf<char>, next, undefined> : shiftNamedGroup<unscanned> extends (Scanner.shiftResult<infer name, infer following>) ? s.pushGroup<s, name, following, undefined> : s.error<writeUnclosedGroupMessage<")">>;
29
+ type shiftNamedGroup<unscanned extends string> = unscanned extends `${infer name}>${infer next}` ? name extends "" ? Scanner.shiftResult<"", ErrorMessage<unnamedCaptureGroupMessage>> : Scanner.shiftResult<name, next> : Scanner.shiftResult<"", ErrorMessage<writeUnclosedGroupMessage<">">>>;
30
+ export declare const unnamedCaptureGroupMessage = "Capture group <> requires a name";
31
+ export type unnamedCaptureGroupMessage = typeof unnamedCaptureGroupMessage;
32
+ export declare const unescapedLiteralQuestionMarkMessage = "literal ? must be escaped at the start of a group";
33
+ export type unescapedLiteralQuestionMarkMessage = typeof unescapedLiteralQuestionMarkMessage;
34
+ export {};
@@ -0,0 +1,2 @@
1
+ export type { RegexExecArray } from "./execArray.ts";
2
+ export { regex, type Regex } from "./regex.ts";
@@ -0,0 +1,9 @@
1
+ export * from "./index.ts";
2
+ export * from "./charset.ts";
3
+ export * from "./escape.ts";
4
+ export * from "./execArray.ts";
5
+ export * from "./group.ts";
6
+ export * from "./parse.ts";
7
+ export * from "./quantify.ts";
8
+ export * from "./regex.ts";
9
+ export * from "./state.ts";
@@ -0,0 +1,10 @@
1
+ import type { Backslash, contains, ErrorMessage, Scanner } from "../util/index.js";
2
+ import type { parseCharset } from "./charset.ts";
3
+ import type { parseEscape } from "./escape.ts";
4
+ import type { parseGroup } from "./group.ts";
5
+ import type { parseBuiltinQuantifier, parsePossibleRange, QuantifyingChar } from "./quantify.ts";
6
+ import type { Anchor, AnchorMarker, s, State, UnionTree } from "./state.ts";
7
+ export type parseState<s extends State> = s["unscanned"] extends ErrorMessage ? s["unscanned"] : s["unscanned"] extends "" ? s.finalize<s> : parseState<next<s>>;
8
+ export type next<s extends State> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "." ? s.shiftQuantifiable<s, string, unscanned> : lookahead extends Backslash ? parseEscape<s, unscanned> : lookahead extends "|" ? s.finalizeBranch<s, unscanned> : lookahead extends Anchor ? contains<s["flags"], "m"> extends true ? s.shiftQuantifiable<s, "", unscanned> : s.anchor<s, AnchorMarker<lookahead>, unscanned> : lookahead extends "(" ? parseGroup<s, unscanned> : lookahead extends ")" ? s.popGroup<s, unscanned> : lookahead extends QuantifyingChar ? parseBuiltinQuantifier<s, lookahead, unscanned> : lookahead extends "{" ? parsePossibleRange<s, unscanned> : lookahead extends "[" ? parseCharset<s, unscanned> : s.shiftQuantifiable<s, maybeSplitCasing<s["caseInsensitive"], lookahead>, unscanned> : never;
9
+ type maybeSplitCasing<caseInsensitive extends boolean, char extends string> = caseInsensitive extends false ? char : Lowercase<char> extends Uppercase<char> ? char : UnionTree<[Lowercase<char>, Capitalize<char>]>;
10
+ export {};
@@ -0,0 +1,59 @@
1
+ import type { parseNonNegativeInteger, Scanner } from "../util/index.js";
2
+ import type { s, State } from "./state.ts";
3
+ export type parseBuiltinQuantifier<s extends State, quantifier extends QuantifyingChar, unscanned extends string> = s["root"] extends "" ? s.error<writeUnmatchedQuantifierError<quantifier>> : quantifyBuiltin<s, quantifier, unscanned extends Scanner.shift<"?", infer lazyUnscanned> ? lazyUnscanned : unscanned>;
4
+ type quantifyBuiltin<s extends State, quantifier extends QuantifyingChar, unscanned extends string> = quantifier extends "?" ? s.pushQuantifier<s, 0, 1, unscanned> : quantifier extends "+" ? s.pushQuantifier<s, 1, null, unscanned> : quantifier extends "*" ? s.pushQuantifier<s, 0, null, unscanned> : never;
5
+ type ParsedRange = {
6
+ min: number;
7
+ max: number | null;
8
+ unscanned: string;
9
+ };
10
+ declare namespace ParsedRange {
11
+ type from<r extends ParsedRange> = r;
12
+ }
13
+ type skipPossibleQuestionMark<unscanned extends string> = unscanned extends `?${infer next}` ? next : unscanned;
14
+ type parsePossibleRangeString<unscanned extends string> = unscanned extends (`${infer l extends `${number}`},${infer r extends `${number}`}}${infer next}`) ? ParsedRange.from<{
15
+ min: parseNonNegativeInteger<l>;
16
+ max: parseNonNegativeInteger<r>;
17
+ unscanned: skipPossibleQuestionMark<next>;
18
+ }> : unscanned extends `${infer l extends `${number}`},}${infer next}` ? ParsedRange.from<{
19
+ min: parseNonNegativeInteger<l>;
20
+ max: null;
21
+ unscanned: skipPossibleQuestionMark<next>;
22
+ }> : unscanned extends `${infer l extends `${number}`}}${infer next}` ? ParsedRange.from<{
23
+ min: parseNonNegativeInteger<l>;
24
+ max: parseNonNegativeInteger<l>;
25
+ unscanned: skipPossibleQuestionMark<next>;
26
+ }> : null;
27
+ type GreaterDigits = {
28
+ "0": never;
29
+ "1": "0";
30
+ "2": "0" | "1";
31
+ "3": "0" | "1" | "2";
32
+ "4": "0" | "1" | "2" | "3";
33
+ "5": "0" | "1" | "2" | "3" | "4";
34
+ "6": "0" | "1" | "2" | "3" | "4" | "5";
35
+ "7": "0" | "1" | "2" | "3" | "4" | "5" | "6";
36
+ "8": "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7";
37
+ "9": "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8";
38
+ };
39
+ type isGreaterNaturalString<l extends string, r extends string, decided extends boolean | null = null> = l extends `${infer ld extends keyof GreaterDigits}${infer lRest}` ? r extends `${infer rd extends keyof GreaterDigits}${infer rRest}` ? isGreaterNaturalString<lRest, rRest, decided extends boolean ? decided : ld extends rd ? null : rd extends GreaterDigits[ld] ? true : false> : true : r extends "" ? decided extends true ? true : false : false;
40
+ type exceedsMax<min extends number, max extends number | null> = max extends number ? min extends 0 | max ? false : isGreaterNaturalString<`${min}`, `${max}`> : false;
41
+ type parseQuantifier<unscanned extends string, parsed extends ParsedRange> = unscanned extends `${infer range}${parsed["unscanned"]}` ? `{${range}` : never;
42
+ export type parsePossibleRange<s extends State, unscanned extends string, parsed extends ParsedRange | null = parsePossibleRangeString<unscanned>> = parsed extends ParsedRange ? s["root"] extends "" ? s.error<writeUnmatchedQuantifierError<parseQuantifier<unscanned, parsed>>> : [parsed["min"], parsed["max"]] extends ([
43
+ never,
44
+ unknown
45
+ ] | [unknown, never]) ? s.error<writeUnnaturalNumberQuantifierError<parseQuantifier<unscanned, parsed>>> : exceedsMax<parsed["min"], parsed["max"]> extends true ? s.error<writeMinExceedsMaxQuantifierError<parseQuantifier<unscanned, parsed>>> : s.pushQuantifier<s, parsed["min"], parsed["max"], parsed["unscanned"]> : s.shiftQuantifiable<s, "{", unscanned>;
46
+ export type quantify<pattern extends string, min extends number, max extends number | null> = tryFastPath<pattern, min, max>;
47
+ type tryFastPath<pattern extends string, min extends number, max extends number | null> = max extends 0 ? "" : string extends pattern ? string : [pattern, `${number}`] extends [`${number}`, pattern] ? max extends null ? string : min extends 0 ? "" | `${number}` : `${number}` : min extends 0 ? max extends 1 ? "" | pattern : max extends number ? loopFromZero<pattern, max, "", []> : // max is null, all we can do is append ${string}
48
+ "" | `${pattern}${string}` : loopUntilMin<pattern, min, max, "", []>;
49
+ type loopFromZero<base extends string, max extends number, acc extends string, repetitions extends 1[]> = repetitions["length"] extends max ? acc : loopFromZero<base, max, acc | `${acc}${base}`, [...repetitions, 1]>;
50
+ type loopUntilMin<base extends string, min extends number, max extends number | null, acc extends string, repetitions extends 1[]> = repetitions["length"] extends min ? max extends number ? loopUntilMax<base, min, max, acc, repetitions> : repetitions["length"] extends 0 ? acc | `${acc}${base}${string}` : `${acc}${string}` : loopUntilMin<base, min, max, `${acc}${base}`, [...repetitions, 1]>;
51
+ type loopUntilMax<base extends string, min extends number, max extends number, acc extends string, repetitions extends 1[]> = repetitions["length"] extends max ? acc : loopUntilMax<base, min, max, acc | `${acc}${base}`, [...repetitions, 1]>;
52
+ export type QuantifyingChar = "*" | "+" | "?";
53
+ export declare const writeUnmatchedQuantifierError: <quantifier extends string>(quantifier: quantifier) => writeUnmatchedQuantifierError<quantifier>;
54
+ export type writeUnmatchedQuantifierError<quantifier extends string> = `Quantifier ${quantifier} requires a preceding token`;
55
+ export declare const writeUnnaturalNumberQuantifierError: <quantifier extends string>(quantifier: quantifier) => writeUnnaturalNumberQuantifierError<quantifier>;
56
+ export type writeUnnaturalNumberQuantifierError<quantifier extends string> = `Quantifier ${quantifier} must use natural numbers`;
57
+ export declare const writeMinExceedsMaxQuantifierError: <quantifier extends string>(quantifier: quantifier) => writeMinExceedsMaxQuantifierError<quantifier>;
58
+ export type writeMinExceedsMaxQuantifierError<quantifier extends string> = `Quantifier ${quantifier} min cannot exceed max`;
59
+ export {};
@@ -0,0 +1,38 @@
1
+ import type { ErrorMessage, inferred } from "../util/index.js";
2
+ import type { RegexExecArray } from "./execArray.ts";
3
+ import type { parseState } from "./parse.ts";
4
+ import type { State } from "./state.ts";
5
+ export type IndexedCaptures = Array<string | undefined>;
6
+ export type NamedCaptures = Record<string, string | undefined>;
7
+ export type UnicodeFlag = "v" | "u";
8
+ export type Flags = `${"d" | ""}${"g" | ""}${"i" | ""}${"m" | ""}${"s" | ""}${UnicodeFlag | ""}${"y" | ""}`;
9
+ export type RegexContext = {
10
+ flags?: Flags;
11
+ captures?: IndexedCaptures;
12
+ names?: NamedCaptures;
13
+ };
14
+ export interface Regex<out pattern extends string = string, out ctx extends RegexContext = RegexContext> extends RegExp {
15
+ [inferred]: pattern;
16
+ infer: pattern;
17
+ inferCaptures: ctx["captures"] extends IndexedCaptures ? ctx["captures"] : [];
18
+ inferNamedCaptures: ctx["names"] extends NamedCaptures ? ctx["names"] : {};
19
+ inferExecArray: RegexExecArray<[
20
+ pattern,
21
+ ...this["inferCaptures"]
22
+ ], this["inferNamedCaptures"], this["flags"]>;
23
+ flags: ctx["flags"] extends Flags ? ctx["flags"] : "";
24
+ test(s: string): s is pattern;
25
+ exec(s: string): this["inferExecArray"] | null;
26
+ exec(s: string): never;
27
+ }
28
+ export interface RegexParser {
29
+ <src extends string, flags extends Flags = "">(src: regex.validate<src, flags>, flags?: flags): regex.parse<src, flags>;
30
+ as: <pattern extends string = string, ctx extends RegexContext = {}>(src: string, flags?: Flags) => Regex<pattern, ctx>;
31
+ }
32
+ export declare const regex: RegexParser;
33
+ export type regex<pattern extends string = string, ctx extends RegexContext = RegexContext> = Regex<pattern, ctx>;
34
+ export declare namespace regex {
35
+ type infer<src extends string, flags extends Flags = ""> = parse<src, flags> extends Regex<infer pattern> ? pattern : never;
36
+ type validate<src extends string, flags extends Flags = ""> = parse<src, flags> extends infer e extends ErrorMessage ? e : src;
37
+ type parse<src extends string, flags extends Flags = ""> = parseState<State.initialize<src, flags>>;
38
+ }