feat: version 2 beta

This commit is contained in:
2025-04-25 22:39:47 +00:00
commit 1e58359905
75 changed files with 6899 additions and 0 deletions

33
libraries/zod.ts Normal file
View File

@@ -0,0 +1,33 @@
import { ZodError } from "zod";
export function toPrettyErrorLines(error: ZodError, padding: number = 0): string[] {
const lines: string[] = [];
const margin = " ".repeat(padding);
const issues = [...error.issues].sort((a, b) => a.path.length - b.path.length);
for (const issue of issues) {
lines.push(`${margin}${issue.message}`);
if (issue.path?.length) {
lines.push(`${margin} → at ${toDotPath(issue.path)}`);
}
}
return lines;
}
function toDotPath(path: (string | number | symbol)[]): string {
const segs: string[] = [];
for (const seg of path) {
if (typeof seg === "number") {
segs.push(`[${seg}]`);
} else if (typeof seg === "symbol") {
segs.push(`["${String(seg)}"]`);
} else if (seg.includes(".")) {
segs.push(`["${seg}"]`);
} else {
if (segs.length) {
segs.push(".");
}
segs.push(seg);
}
}
return segs.join("");
}