Refactor: extract emoji shortcode regex to constant

Move the emoji shortcode matching pattern to EMOJI_SHORTCODE_REGEX
constant in emoji-helpers.ts for reuse across reaction renderers.
This commit is contained in:
Claude
2026-01-09 10:00:15 +00:00
parent aef464b8a0
commit bb0bce31a8
3 changed files with 10 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ import { Heart, ThumbsUp, ThumbsDown, Flame, Smile } from "lucide-react";
import { useNostrEvent } from "@/hooks/useNostrEvent";
import { UserName } from "../UserName";
import { RichText } from "../RichText";
import { EMOJI_SHORTCODE_REGEX } from "@/lib/emoji-helpers";
/**
* Compact preview for Kind 7 (Reaction)
@@ -26,7 +27,7 @@ export function ReactionCompactPreview({ event }: { event: NostrEvent }) {
// Parse reaction content for custom emoji
const parsedReaction = useMemo(() => {
const match = reaction.match(/^:([a-zA-Z0-9_-]+):$/);
const match = reaction.match(EMOJI_SHORTCODE_REGEX);
if (match && customEmojis[match[1]]) {
return {
type: "custom" as const,

View File

@@ -6,6 +6,7 @@ import { NostrEvent } from "@/types/nostr";
import { KindRenderer } from "./index";
import { EventCardSkeleton } from "@/components/ui/skeleton";
import { parseReplaceableAddress } from "applesauce-core/helpers/pointers";
import { EMOJI_SHORTCODE_REGEX } from "@/lib/emoji-helpers";
/**
* Renderer for Kind 7 - Reactions
@@ -32,7 +33,7 @@ export function Kind7Renderer({ event }: BaseEventProps) {
// Parse reaction content to detect custom emoji shortcodes
// Format: :shortcode: in the content
const parsedReaction = useMemo(() => {
const match = reaction.match(/^:([a-zA-Z0-9_-]+):$/);
const match = reaction.match(EMOJI_SHORTCODE_REGEX);
if (match && customEmojis[match[1]]) {
return {
type: "custom" as const,

View File

@@ -1,6 +1,12 @@
import { getOrComputeCachedValue } from "applesauce-core/helpers";
import type { NostrEvent } from "@/types/nostr";
/**
* Regex pattern to match NIP-30 custom emoji shortcodes like :shortcode:
* Supports alphanumeric characters, underscores, and dashes
*/
export const EMOJI_SHORTCODE_REGEX = /^:([a-zA-Z0-9_-]+):$/;
/**
* Represents a parsed emoji tag from NIP-30
*/