mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {ModerationUI} from '@atproto/api'
2
3// \u2705 = ✅
4// \u2713 = ✓
5// \u2714 = ✔
6// \u2611 = ☑
7const CHECK_MARKS_RE = /[\u2705\u2713\u2714\u2611]/gu
8const CONTROL_CHARS_RE =
9 /[\u0000-\u001F\u007F-\u009F\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069]/g
10const MULTIPLE_SPACES_RE = /[\s][\s\u200B]+/g
11
12export function sanitizeDisplayName(
13 str: string,
14 moderation?: ModerationUI,
15): string {
16 if (moderation?.blur) {
17 return ''
18 }
19 if (typeof str === 'string') {
20 return str
21 .replace(CHECK_MARKS_RE, '')
22 .replace(CONTROL_CHARS_RE, '')
23 .replace(MULTIPLE_SPACES_RE, ' ')
24 .trim()
25 }
26 return ''
27}
28
29export function combinedDisplayName({
30 handle,
31 displayName,
32}: {
33 handle?: string
34 displayName?: string
35}): string {
36 if (!handle) {
37 return ''
38 }
39 return displayName
40 ? `${sanitizeDisplayName(displayName)} (@${handle})`
41 : `@${handle}`
42}