local no errors
Some checks failed
Rebuild signaller for deprived.dev to rebuild site / test_service (push) Failing after 9s

This commit is contained in:
BOTAlex 2025-10-03 15:06:40 +02:00
parent a7a53e6fb6
commit 7a21f70144
7 changed files with 104 additions and 5 deletions

View file

@ -0,0 +1,50 @@
// npm i zod
import { z } from "zod";
const Link = z.object({
text: z.string().min(1),
link: z.string().url(),
});
const Experience = z.object({
imageId: z.string().min(1),
name: z.string().min(1),
date: z.string().min(1),
});
const EducationLoose = z.object({
imageId: z.string().min(1).optional(),
name: z.string().min(1).optional(),
});
const ProfileSchema = z.object({
name: z.string().min(1),
shortProfileHiddenContent: z.array(z.string()),
email: z.string().email(),
phone: z.string().min(1),
linkedIn: Link,
itch: Link,
experience: z.array(Experience),
education: z
.array(EducationLoose)
.transform((arr) =>
arr.filter(
(e): e is { imageId: string; name: string } => !!e.imageId && !!e.name,
),
),
});
export type LinkT = z.infer<typeof Link>;
export type ExperienceT = z.infer<typeof Experience>;
export type EducationT = { imageId: string; name: string };
export type Profile = Omit<z.infer<typeof ProfileSchema>, "education"> & {
education: EducationT[];
};
export function parseProfile(json: unknown): Profile {
return ProfileSchema.parse(json);
}
// --- usage ---
// const raw = JSON.parse(yourJsonString);
// const profile = parseProfile(raw);