mirror of
https://github.com/LucasVbr/LucasVbr.git
synced 2026-05-16 01:21:51 +00:00
feat: Use Typescript, YAML, Handlebars with generation workflow
Took 5 hours 7 minutes
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import type {ZodObject} from 'zod';
|
||||
|
||||
/**
|
||||
* Validator class for validating and parsing objects against a Zod schema.
|
||||
*/
|
||||
export class Validator {
|
||||
|
||||
/**
|
||||
* Creates an instance of the Validator.
|
||||
* @param schema - The Zod schema to validate against.
|
||||
*/
|
||||
constructor(private schema: ZodObject<any, any>) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the given value against the schema.
|
||||
* @param value - The object to validate.
|
||||
* @returns true if the value is valid, false otherwise.
|
||||
*/
|
||||
public isValid(value: object): boolean {
|
||||
try {
|
||||
this.schema.parse(value);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Validation error:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the given value against the schema.
|
||||
* @param value - The object to parse.
|
||||
* @returns The parsed object if valid, throws an error otherwise.
|
||||
*/
|
||||
public validate(value: object): object {
|
||||
try {
|
||||
return this.schema.parse(value);
|
||||
} catch (error) {
|
||||
console.error('Parsing error:', error);
|
||||
throw new Error('Failed to parse value');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import {z} from 'zod';
|
||||
|
||||
export const AuthorSchema = z.object({
|
||||
first_name: z.string(),
|
||||
location: z.string(),
|
||||
company: z.string(),
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
import {z} from 'zod';
|
||||
import {AuthorSchema, SkillSchema, SocialSchema} from '.';
|
||||
|
||||
export const ReadmeSchema = z.object({
|
||||
author: AuthorSchema,
|
||||
socials: z.array(SocialSchema),
|
||||
skills: z.array(SkillSchema),
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
import {z} from 'zod';
|
||||
|
||||
export const SkillSchema = z.object({
|
||||
name: z.string(),
|
||||
icon: z.string(),
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
import {z} from 'zod';
|
||||
|
||||
export const SocialSchema = z.object({
|
||||
name: z.string(),
|
||||
icon: z.string(),
|
||||
url: z.string(),
|
||||
});
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from './AuthorSchema';
|
||||
export * from './SocialSchema';
|
||||
export * from './SkillSchema';
|
||||
export * from './ReadmeSchema';
|
||||
Reference in New Issue
Block a user