69 lines
No EOL
2.2 KiB
JavaScript
69 lines
No EOL
2.2 KiB
JavaScript
// Test the current userMapping logic with real email data
|
|
const stripTechnicalSuffixes = (email) => {
|
|
if (!email || typeof email !== 'string') {
|
|
return email;
|
|
}
|
|
|
|
return email
|
|
.replace(/_barclays\.com#ext#@olivermarketing\.onmicrosoft\.com$/, '')
|
|
.replace(/_barclaycard\.co\.uk#ext#@olivermarketing\.onmicrosoft\.com$/, '')
|
|
.replace(/_[^_]+\.(com|co\.uk)#ext#@olivermarketing\.onmicrosoft\.com$/, '');
|
|
};
|
|
|
|
const getFriendlyNameFromEmail = (email) => {
|
|
if (!email || typeof email !== 'string') {
|
|
return email || 'Unknown User';
|
|
}
|
|
|
|
const cleanEmail = stripTechnicalSuffixes(email);
|
|
const prefix = cleanEmail.split('@')[0];
|
|
|
|
if (!prefix) {
|
|
return email;
|
|
}
|
|
|
|
// Handle Oliver agency emails (camelCase format like 'michaelclervi')
|
|
if (email.includes('@oliver.agency')) {
|
|
// Try to split camelCase into words
|
|
const words = prefix.match(/[A-Z][a-z]*|[a-z]+/g) || [prefix];
|
|
if (words.length >= 2) {
|
|
return words.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(' ');
|
|
} else {
|
|
// Single word, just capitalize first letter
|
|
return prefix.charAt(0).toUpperCase() + prefix.slice(1).toLowerCase();
|
|
}
|
|
} else {
|
|
// Handle external emails (dot.separated format like 'adam.webb')
|
|
const spaced = prefix.replace(/[._-]/g, ' ');
|
|
|
|
// Title case each word
|
|
const titleCased = spaced
|
|
.toLowerCase()
|
|
.split(' ')
|
|
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
|
.join(' ');
|
|
|
|
return titleCased;
|
|
}
|
|
};
|
|
|
|
// Test with actual email patterns
|
|
const testEmails = [
|
|
'michaelclervi@oliver.agency',
|
|
'adam.webb_barclaycard.co.uk#ext#@olivermarketing.onmicrosoft.com',
|
|
'aileen.stevenson_barclays.com#ext#@olivermarketing.onmicrosoft.com',
|
|
'christopher.x.perkins_barclays.com#ext#@olivermarketing.onmicrosoft.com',
|
|
'jeremycrockerwhite@oliver.agency',
|
|
'armanpreetkapoor@oliver.agency',
|
|
'daveporter@oliver.agency'
|
|
];
|
|
|
|
console.log('Testing email name extraction:');
|
|
testEmails.forEach(email => {
|
|
const stripped = stripTechnicalSuffixes(email);
|
|
const friendly = getFriendlyNameFromEmail(email);
|
|
console.log(`${email}`);
|
|
console.log(` Stripped: ${stripped}`);
|
|
console.log(` Friendly: ${friendly}`);
|
|
console.log('');
|
|
}); |