resumeParser.js•5.34 kB
const fs = require("fs").promises;
const path = require("path");
class ResumeParser {
constructor(dataPath = "./data/resume.json") {
this.dataPath = dataPath;
this.resumeData = null;
}
/**
* Load resume data from JSON file
*/
async loadResumeData() {
try {
const fullPath = path.resolve(this.dataPath);
const data = await fs.readFile(fullPath, "utf-8");
this.resumeData = JSON.parse(data);
return this.resumeData;
} catch (error) {
throw new Error(`Failed to load resume data: ${error}`);
}
}
/**
* Get current resume data
*/
getResumeData() {
return this.resumeData;
}
/**
* Search for specific information in the resume
*/
searchResume(query) {
if (!this.resumeData) {
throw new Error("Resume data not loaded");
}
const results = [];
const searchTerm = query.toLowerCase();
// Search in personal info
if (this.resumeData.personalInfo.name.toLowerCase().includes(searchTerm)) {
results.push(`Name: ${this.resumeData.personalInfo.name}`);
}
// Search in experience
this.resumeData.experience.forEach((exp, index) => {
if (
exp.company.toLowerCase().includes(searchTerm) ||
exp.position.toLowerCase().includes(searchTerm) ||
exp.description.toLowerCase().includes(searchTerm)
) {
results.push(
`Experience ${index + 1}: ${exp.position} at ${exp.company}`
);
}
});
// Search in skills
const matchingSkills = this.resumeData.skills.filter((skill) =>
skill.toLowerCase().includes(searchTerm)
);
if (matchingSkills.length > 0) {
results.push(`Skills: ${matchingSkills.join(", ")}`);
}
// Search in education
this.resumeData.education.forEach((edu, index) => {
if (
edu.institution.toLowerCase().includes(searchTerm) ||
edu.degree.toLowerCase().includes(searchTerm) ||
edu.field.toLowerCase().includes(searchTerm)
) {
results.push(
`Education ${index + 1}: ${edu.degree} in ${edu.field} from ${
edu.institution
}`
);
}
});
return results;
}
/**
* Get formatted resume summary
*/
getResumeSummary() {
if (!this.resumeData) {
throw new Error("Resume data not loaded");
}
const { personalInfo, summary, experience, education, skills } =
this.resumeData;
return `
Name: ${personalInfo.name}
Email: ${personalInfo.email}
Location: ${personalInfo.location || "Not specified"}
Summary:
${summary}
Current Position: ${
experience.find((exp) => exp.current)?.position || "Not specified"
}
Company: ${experience.find((exp) => exp.current)?.company || "Not specified"}
Total Experience: ${experience.length} positions
Education: ${education.map((edu) => `${edu.degree} in ${edu.field}`).join(", ")}
Skills: ${skills.slice(0, 10).join(", ")}${skills.length > 10 ? "..." : ""}
`.trim();
}
/**
* Get detailed work experience
*/
getWorkExperience() {
if (!this.resumeData) {
throw new Error("Resume data not loaded");
}
return this.resumeData.experience
.map(
(exp, index) => `
${index + 1}. ${exp.position} at ${exp.company}
Duration: ${exp.startDate} - ${exp.endDate || "Present"}
Description: ${exp.description}
Key Achievements:
${exp.achievements.map((achievement) => ` • ${achievement}`).join("\n")}
Technologies: ${exp.technologies.join(", ")}
`
)
.join("\n");
}
/**
* Get education details
*/
getEducation() {
if (!this.resumeData) {
throw new Error("Resume data not loaded");
}
return this.resumeData.education
.map(
(edu, index) => `
${index + 1}. ${edu.degree} in ${edu.field}
Institution: ${edu.institution}
Duration: ${edu.startDate} - ${edu.endDate || "Present"}
GPA: ${edu.gpa || "Not specified"}
${edu.achievements ? `Achievements: ${edu.achievements.join(", ")}` : ""}
`
)
.join("\n");
}
/**
* Get skills list
*/
getSkills() {
if (!this.resumeData) {
throw new Error("Resume data not loaded");
}
return this.resumeData.skills.join(", ");
}
/**
* Get projects information
*/
getProjects() {
if (!this.resumeData || !this.resumeData.projects) {
return "No projects information available";
}
return this.resumeData.projects
.map(
(project, index) => `
${index + 1}. ${project.name}
Description: ${project.description}
Technologies: ${project.technologies.join(", ")}
Duration: ${project.startDate} - ${project.endDate || "Present"}
${project.url ? `URL: ${project.url}` : ""}
${project.github ? `GitHub: ${project.github}` : ""}
`
)
.join("\n");
}
/**
* Get certifications
*/
getCertifications() {
if (!this.resumeData || !this.resumeData.certifications) {
return "No certifications available";
}
return this.resumeData.certifications
.map(
(cert, index) => `
${index + 1}. ${cert.name}
Issuer: ${cert.issuer}
Date: ${cert.date}
${cert.credentialId ? `Credential ID: ${cert.credentialId}` : ""}
${cert.url ? `URL: ${cert.url}` : ""}
`
)
.join("\n");
}
}
module.exports = { ResumeParser };