lat and long
This commit is contained in:
@@ -675,11 +675,37 @@ const Rule = () => (
|
||||
<div style={{ height: 1, background: 'var(--color-line)', margin: '5px 0' }} />
|
||||
);
|
||||
|
||||
/**
|
||||
* Up to two letters for the avatar. Never a dash.
|
||||
*
|
||||
* First name and last name where the account has them. Where it does not —
|
||||
* plenty of rows on this backend carry neither — the email is used instead,
|
||||
* split on the separators people actually put in addresses, so
|
||||
* `ragul.kumar@shop.in` gives RK and `care@nearle.in` gives C.
|
||||
*
|
||||
* The old version returned an em dash for anything it could not parse, and that
|
||||
* is what every Store Admin and Store user saw: their accounts have no first or
|
||||
* last name, so the avatar was a dash on every page. A dash says nothing and
|
||||
* looks like a bug, which is worse than one letter.
|
||||
*/
|
||||
function initials(name: string): string {
|
||||
const parts = name.trim().split(/\s+/).filter(Boolean);
|
||||
if (parts.length === 0) return '—';
|
||||
const first = parts[0]?.[0] ?? '';
|
||||
const last = parts.length > 1 ? (parts[parts.length - 1]?.[0] ?? '') : '';
|
||||
const trimmed = name.trim();
|
||||
if (trimmed === '') return '?';
|
||||
|
||||
// An email is not a name. Take the part before the @ and read the words out
|
||||
// of it — a full address would otherwise give the domain's letter as the
|
||||
// second initial.
|
||||
const source = trimmed.includes('@') ? (trimmed.split('@')[0] ?? trimmed) : trimmed;
|
||||
|
||||
const words = source
|
||||
.split(/[\s._\-+]+/)
|
||||
.map((word) => word.replace(/[^\p{L}\p{N}]/gu, ''))
|
||||
.filter(Boolean);
|
||||
|
||||
if (words.length === 0) return '?';
|
||||
|
||||
const first = words[0]?.[0] ?? '';
|
||||
const last = words.length > 1 ? (words[words.length - 1]?.[0] ?? '') : '';
|
||||
return (first + last).toUpperCase();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user