export class Masking {
static email(email: string): string {
const [username, domain] = email.split('@')
const numStars: number = Math.abs(Math.floor(username.length / 2))
let maskedUsername: string = ''
if (username.length <= numStars) {
maskedUsername = '*'.repeat(username.length) + username.slice(-2)
} else {
maskedUsername = username.slice(0, -numStars) + '*'.repeat(numStars - 1) + username.slice(-1)
}
return `${maskedUsername}@${domain}`
}
static mobile(mobile: string): string {
const numStars: number = Math.abs(Math.floor(mobile.length / 2))
return mobile.slice(0, 4) + String('*').repeat(numStars) + mobile.slice(-4)
}
}