Ctrl K
ComunidadGuías…

app/utils/emoji.ts

Rama main · réplica de lectura del repositorio original.

Archivo original ↗Preguntar a KiBot
/**
 * Converts an emoji character to a data URL that can be used as an image
 * source.
 *
 * @param text the emoji character to convert.
 * @returns a data URL containing the emoji rendered as an SVG.
 */
export function emojiToUrl(text: string) {
  return `data:image/svg+xml;data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>${text}</text></svg>`;
}

/**
 * Generates a valid emoji name from a filename by:
 * - Removing file extension
 * - Converting to lowercase
 * - Replacing spaces and dashes with underscores
 * - Removing invalid characters (only allowing lowercase letters and underscores)
 * - Removing numbers
 * - Removing leading/trailing underscores
 *
 * @param filename the name of the file.
 * @returns a valid emoji name string.
 */
export function generateEmojiNameFromFilename(filename: string): string {
  // Remove file extension
  const nameWithoutExt = filename.replace(/\.[^.]+$/, "");

  // Convert to lowercase, replace spaces and dashes with underscores
  let name = nameWithoutExt
    .toLowerCase()
    .replace(/\s+/g, "_")
    .replace(/-+/g, "_");

  // Remove all characters that aren't lowercase letters or underscores (including numbers)
  name = name.replace(/[^a-z_]/g, "");

  // Remove leading/trailing underscores and collapse multiple underscores
  name = name.replace(/^_+|_+$/g, "").replace(/_+/g, "_");

  return name;
}