almeira-web/src/lib/utils.ts

47 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
/**
* Decodifica entidades HTML comunes que vienen de WordPress (ej: … -> ...)
* @param text Texto con entidades HTML
* @returns Texto decodificado
*/
export function decodeHtmlEntities(text: string): string {
if (!text) return "";
// Objeto con entidades comunes de WordPress/HTML
const entities: { [key: string]: string } = {
'–': '–',
'—': '—',
'‘': "‘",
'’': "'",
'“': '"',
'”': '"',
'…': '...',
' ': ' ',
'&': '&',
'&lt;': '<',
'&gt;': '>',
'&quot;': '"',
'&#039;': "'",
'&#38;': '&',
'&#160;': ' '
};
let decoded = text;
// Aplicar reemplazos del mapa manual
Object.keys(entities).forEach(entity => {
decoded = decoded.split(entity).join(entities[entity]);
});
// Decodificador genérico para cualquier otra entidad numérica residual (&#...;)
return decoded.replace(/&#(\d+);/g, (match, dec) => {
return String.fromCharCode(parseInt(dec, 10));
});
}