Some checks failed
Rebuild signaller for deprived.dev to rebuild site / test_service (push) Failing after 9s
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
// 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);
|