-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnormalize-statuses.mjs
More file actions
134 lines (109 loc) · 4.02 KB
/
normalize-statuses.mjs
File metadata and controls
134 lines (109 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env node
/**
* normalize-statuses.mjs — Map status aliases to canonical values
*
* Handles English, Spanish, and common typo aliases.
* Creates .bak backup before writing.
*
* Usage: node normalize-statuses.mjs [--dry-run]
*/
import { readFile, writeFile, copyFile } from 'node:fs/promises';
import { existsSync } from 'node:fs';
const DRY_RUN = process.argv.includes('--dry-run');
const TRACKER_PATH = existsSync('data/applications.md')
? 'data/applications.md'
: 'applications.md';
const VALID_STATUSES = [
'Evaluated', 'Applied', 'Responded', 'Interview',
'Offer', 'Rejected', 'Discarded', 'SKIP',
];
const ALIASES = {
// Evaluated
'eval': 'Evaluated', 'reviewed': 'Evaluated', 'evaluado': 'Evaluated',
'scored': 'Evaluated', 'assessed': 'Evaluated',
// Applied
'submitted': 'Applied', 'sent': 'Applied', 'aplicado': 'Applied',
'postulado': 'Applied', 'applied online': 'Applied',
// Responded
'reply': 'Responded', 'replied': 'Responded', 'response': 'Responded',
'respondido': 'Responded', 'heard back': 'Responded',
// Interview
'interviewing': 'Interview', 'phone screen': 'Interview',
'technical': 'Interview', 'onsite': 'Interview', 'final round': 'Interview',
'entrevista': 'Interview', 'phone': 'Interview', 'screen': 'Interview',
'coding challenge': 'Interview', 'take home': 'Interview',
'assessment': 'Interview', 'hr screen': 'Interview',
// Offer
'offered': 'Offer', 'oferta': 'Offer', 'condicional': 'Offer',
// Rejected
'declined by company': 'Rejected', 'no': 'Rejected',
'rejected by company': 'Rejected', 'rechazado': 'Rejected',
'not selected': 'Rejected', 'declined': 'Rejected',
// Discarded
'withdrawn': 'Discarded', 'closed': 'Discarded', 'expired': 'Discarded',
'descartado': 'Discarded', 'duplicado': 'Discarded',
'cerrada': 'Discarded', 'cancelada': 'Discarded',
'repost': 'Discarded', 'geo blocker': 'Discarded',
'geo blocked': 'Discarded', 'no longer available': 'Discarded',
// SKIP
'no apply': 'SKIP', 'pass': 'SKIP', 'skip': 'SKIP',
'hold': 'SKIP', 'maybe later': 'SKIP', 'not now': 'SKIP',
'pasar': 'SKIP',
};
async function main() {
if (!existsSync(TRACKER_PATH)) {
console.error(`Tracker not found: ${TRACKER_PATH}`);
process.exit(1);
}
const content = await readFile(TRACKER_PATH, 'utf-8');
const lines = content.split('\n');
let changes = 0;
const sepIndex = lines.findIndex(l => /^\|[-\s|]+\|$/.test(l));
if (sepIndex === -1) {
console.error('Could not find header separator');
process.exit(1);
}
for (let i = sepIndex + 1; i < lines.length; i++) {
const line = lines[i].trim();
if (!line || !line.startsWith('|')) continue;
const cols = line.split('|');
if (cols.length < 7) continue;
// Status column — try index 6 first, fall back to scanning
let statusIdx = -1;
for (let c = 1; c < cols.length - 1; c++) {
const val = cols[c].trim().replace(/\*\*/g, '');
if (VALID_STATUSES.includes(val) || ALIASES[val.toLowerCase()]) {
statusIdx = c;
break;
}
}
if (statusIdx === -1) statusIdx = 6; // default position
const raw = cols[statusIdx]?.trim().replace(/\*\*/g, '');
if (!raw) continue;
if (!VALID_STATUSES.includes(raw)) {
const canonical = ALIASES[raw.toLowerCase()];
if (canonical) {
cols[statusIdx] = ` ${canonical} `;
lines[i] = cols.join('|');
console.log(` Line ${i + 1}: "${raw}" → "${canonical}"`);
changes++;
} else {
console.warn(` Line ${i + 1}: Unknown status "${raw}" — skipping`);
}
}
}
if (changes === 0) {
console.log('All statuses are already canonical.');
return;
}
if (!DRY_RUN) {
await copyFile(TRACKER_PATH, TRACKER_PATH + '.bak');
console.log(` Backup: ${TRACKER_PATH}.bak`);
await writeFile(TRACKER_PATH, lines.join('\n'));
}
console.log(`\n${changes} status(es) normalized${DRY_RUN ? ' (DRY RUN)' : ''}.`);
}
main().catch(err => {
console.error('Normalization failed:', err.message);
process.exit(1);
});