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
10
11export function sanitizeDisplayName(
12 str: string,
13 moderation?: ModerationUI,
14): string {
15 if (moderation?.blur) {
16 return ''
17 }
18 if (typeof str === 'string') {
19 return str.replace(CHECK_MARKS_RE, '').replace(CONTROL_CHARS_RE, '').trim()
20 }
21 return ''
22}
23
24export function combinedDisplayName({
25 handle,
26 displayName,
27}: {
28 handle?: string
29 displayName?: string
30}): string {
31 if (!handle) {
32 return ''
33 }
34 return displayName
35 ? `${sanitizeDisplayName(displayName)} (@${handle})`
36 : `@${handle}`
37}