14 lines
645 B
JavaScript
14 lines
645 B
JavaScript
/** Публичное отображение автора отзыва (без «голого» email). */
|
|
export function publicReviewAuthorDisplay(user) {
|
|
if (!user || typeof user !== 'object') return 'Покупатель'
|
|
const name = typeof user.name === 'string' ? user.name.trim() : ''
|
|
if (name) return name
|
|
const email = typeof user.email === 'string' ? user.email.trim() : ''
|
|
const at = email.indexOf('@')
|
|
if (at <= 0) return 'Покупатель'
|
|
const local = email.slice(0, at)
|
|
const domain = email.slice(at + 1)
|
|
const masked = local.length <= 1 ? '*' : `${local.slice(0, 1)}***`
|
|
return `${masked}@${domain}`
|
|
}
|