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

45 lines
1.1 KiB
TypeScript

/**
* Utilidades de formato de mensajes (IDs, fechas y estilos WhatsApp).
*/
export function padTaskId(id: number, width: number = 4): string {
const s = String(Math.max(0, Math.floor(id)));
if (s.length >= width) return s;
return '0'.repeat(width - s.length) + s;
}
export function codeId(id: number, displayCode?: number | null): string {
const n = typeof displayCode === 'number' && Number.isFinite(displayCode) && displayCode > 0 ? displayCode : id;
return '`' + padTaskId(n) + '`';
}
export function formatDDMM(ymd?: string | null): string | null {
if (!ymd) return null;
const parts = String(ymd).split('-');
if (parts.length >= 3) {
const [Y, M, D] = parts;
if (D && M) return `${D}/${M}`;
}
return String(ymd);
}
export function bold(s: string): string {
return `*${s}*`;
}
export function italic(s: string): string {
return `_${s}_`;
}
export function code(s: string): string {
return '`' + String(s) + '`';
}
export function section(s: string): string {
return `*${String(s).toUpperCase()}*`;
}
export function bullets(items: string[]): string {
return (items || []).map((i) => `- ${String(i)}`).join('\n');
}