Skip to content

Commit 81d9f71

Browse files
feat: add phone number extraction to resume parser [ GSSOC'26 ] (JhaSourav07#2986)
## Description Adds `extractPhone()` to the resume parser that matches common phone number formats including international prefixes, dashes, dots, spaces, and parentheses. The extracted value is included as a `phone` field in the `ParsedResume` return value. Fixes JhaSourav07#2985 ## Pillar - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A — parsing utility, no visual output. ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally. - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors. - [x] My commits follow the Conventional Commits format. - [x] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have starred the repo. - [x] I have made sure that I have only one commit to merge in this PR. - [ ] The SVG output matches the CommitPulse "premium quality" aesthetic standard. - [ ] (Recommended) I joined the CommitPulse Discord community.
1 parent b130694 commit 81d9f71

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

lib/resume-parser.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,30 @@ function extractTextFromBuffer(buffer: Buffer, _mimeType: string): string {
118118
return printable;
119119
}
120120

121+
/**
122+
* Extracts a phone number from raw resume text.
123+
*
124+
* Matches common formats including international prefixes,
125+
* dashes, dots, spaces, and parentheses.
126+
*
127+
* @param text - Raw resume text.
128+
* @returns The first phone number found, or an empty string.
129+
*
130+
* @example
131+
* const phone = extractPhone(rawText);
132+
*/
133+
function extractPhone(text: string): string {
134+
const match = text.match(/(\+?\d{1,3}[\s.-]?)?(\(?\d{3}\)?[\s.-]?)(\d{3}[\s.-]?\d{4})/);
135+
return match ? match[0].trim() : '';
136+
}
137+
121138
export async function parseResume(buffer: Buffer, mimeType: string): Promise<ParsedResume> {
122139
const rawText = extractTextFromBuffer(buffer, mimeType);
123140

124141
return {
125142
name: extractName(rawText),
126143
email: extractEmail(rawText),
144+
phone: extractPhone(rawText),
127145
skills: extractSkills(rawText),
128146
education: extractEducation(rawText),
129147
experience: extractExperience(rawText),

types/student.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('types/student', () => {
2929
const parsedResume: ParsedResume = {
3030
name: 'Sonal Mittal',
3131
email: 'sonal@example.com',
32+
phone: '',
3233
skills: ['TypeScript', 'React'],
3334
education: [education],
3435
experience: [experience],
@@ -77,6 +78,7 @@ describe('types/student', () => {
7778
data: {
7879
name: 'Sonal Mittal',
7980
email: 'sonal@example.com',
81+
phone: '',
8082
skills: ['React'],
8183
education: [education],
8284
experience: [experience],

types/student.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export interface ParsedResume {
22
name: string;
33
email: string;
4+
phone: string;
45
skills: string[];
56
education: Education[];
67
experience: Experience[];

0 commit comments

Comments
 (0)