|
| 1 | +import { LifeStyle, TechStack, SocialMedia, About } from "./constants"; |
| 2 | + |
| 3 | +export const isLifeStyle = (obj: unknown): obj is LifeStyle => { |
| 4 | + if (!isObject(obj)) return false; |
| 5 | + return ( |
| 6 | + typeof obj.icon === 'string' && |
| 7 | + typeof obj.title === 'string' && |
| 8 | + typeof obj.text === 'string' |
| 9 | + ); |
| 10 | +}; |
| 11 | + |
| 12 | +export const isTechStack = (obj: unknown): obj is TechStack => { |
| 13 | + if (!isObject(obj)) return false; |
| 14 | + return ( |
| 15 | + typeof obj.id === 'string' && |
| 16 | + typeof obj.src === 'string' && |
| 17 | + typeof obj.alt === 'string' |
| 18 | + ); |
| 19 | +}; |
| 20 | + |
| 21 | +export const isSocialMedia = (obj: unknown): obj is SocialMedia => { |
| 22 | + if (!isObject(obj)) return false; |
| 23 | + return ( |
| 24 | + typeof obj.githubUsername === 'string' && |
| 25 | + typeof obj.mediumUsername === 'string' && |
| 26 | + typeof obj.twitterUsername === 'string' && |
| 27 | + typeof obj.linkedinUsername === 'string' |
| 28 | + ); |
| 29 | +}; |
| 30 | + |
| 31 | +export const isAbout = (obj: unknown): obj is About => { |
| 32 | + if (!isObject(obj)) return false; |
| 33 | + return ( |
| 34 | + isSocialMedia(obj.socialMedia) && |
| 35 | + typeof obj.header === 'string' && |
| 36 | + typeof obj.subHeader === 'string' && |
| 37 | + typeof obj.pronouns === 'string' && |
| 38 | + Array.isArray(obj.introductions) && |
| 39 | + obj.introductions.every(item => typeof item === 'string') && |
| 40 | + Array.isArray(obj.lifestyle) && |
| 41 | + obj.lifestyle.every(item => isLifeStyle(item)) && |
| 42 | + Array.isArray(obj.programmingLanguage) && |
| 43 | + obj.programmingLanguage.every(item => isTechStack(item)) && |
| 44 | + Array.isArray(obj.devOps) && |
| 45 | + obj.devOps.every(item => isTechStack(item)) |
| 46 | + ); |
| 47 | +}; |
| 48 | + |
| 49 | + |
| 50 | +export const isObject = (object: unknown): object is Record<string, unknown> => { |
| 51 | + return typeof object === 'object' && object !== null && !Array.isArray(object); |
| 52 | +}; |
| 53 | + |
0 commit comments