You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

15 lines
667 B

import { NOSTR_URI_INLINE_REGEX } from '@/lib/content-patterns'
/** Bare NIP-19 entities (no `nostr:` prefix) often pasted in note text */
const BARE_BECH32 = /\b(npub|nprofile|note|nevent|naddr|nrelay)1[a-z0-9]+\b/gi
/**
* Remove `nostr:` NIP-21 URIs, bare bech32 ids, and 64-char hex event ids so one-line UI snippets
* (e.g. thread backlinks) do not show raw addresses when the quoted note is mostly references.
*/
export function stripNostrIdsFromPlainTextSnippet(text: string): string {
let s = text.replace(NOSTR_URI_INLINE_REGEX, ' ')
s = s.replace(BARE_BECH32, ' ')
s = s.replace(/\b[0-9a-f]{64}\b/gi, ' ')
return s.replace(/\s+/g, ' ').trim()
}