ArkType
12kb
文字列でvalidaitonを書くTSのruntime type checkできるやつ
type level parserと通常のparserと両方書かないといけないから大変やね

tsimport { type } from "arktype"
// Define your type...
export const pkg = type({
name: "string",
version: "semver",
"contributors?": "1<email[]<=10" // 文字列でvalidation書く
})
// Infer it...
export type Package = typeof pkg.infer
// Get validated data or clear, customizable error messages.
export const { data, problems } = pkg({
name: "arktype",
version: "1.0.0-alpha",
contributors: ["david@arktype.io"]
})
// "contributors must be more than 1 items long (was 1)"
console.log(problems?.summary ?? data)
かけるクエリの例
tsexport const validationSyntax = type({
keywords: "email|uuid|creditCard|integer", // and many more
builtinParsers: "parsedDate", // parses a Date from a string
nativeRegexLiteral: /@arktype\.io/,
embeddedRegexLiteral: "email&/@arktype\\.io/",
divisibility: "number%10", // a multiple of 10
bound: "alpha>10", // an alpha-only string with more than 10 characters
range: "1<=email[]<99", // a list of 1 to 99 emails
narrows: ["number", "=>", (n) => n % 2 === 1], // an odd integer
morphs: ["string", "|>", parseFloat] // validates a string input then parses it to a number
})
ArkType自体の設計が大変そうだな..

普通の言語の設計してるのと近くて、1つのsyntaxを追加した時の影響度がでかそう
Zodとの違いというページがあった

Zodよりも定義時に必要な文字量が50%減る
文字列でクエリを書く
素の typeof
が使える
hoverしたときに表示される型が本来のものに近い
zodは複雑な型が表示されてしまう
定義がsrealizableである
ゆくゆくは他の言語でも使えるようにする予定らしい?
エラーメッセージがより見やすい
再帰型も定義できる
ゆくゆくはJIT Compileする予定で、速い
ってやってるところに、文字列でクエリ書くのか
