30 lines
947 B
TypeScript
30 lines
947 B
TypeScript
export function slugify(text: string): string {
|
|
return text
|
|
.normalize('NFD')
|
|
.replace(/[̀-ͯ]/g, '') // eliminar diacríticos (á→a, ñ→n, ü→u)
|
|
.toLowerCase()
|
|
.replace(/[^a-z0-9]+/g, '-') // todo lo no-alfanumérico → guión
|
|
.replace(/^-+|-+$/g, '') // recortar guiones del inicio/fin
|
|
.slice(0, 60) // limitar longitud para nombres de archivo
|
|
}
|
|
|
|
export function buildFileName(
|
|
processName: string,
|
|
clientName: string | undefined,
|
|
date: Date,
|
|
ext: 'pdf' | 'csv',
|
|
suffix = '' // '_actual' | '_automatizado' | '_roi' | ''
|
|
): string {
|
|
const dateStr = [
|
|
date.getFullYear(),
|
|
String(date.getMonth() + 1).padStart(2, '0'),
|
|
String(date.getDate()).padStart(2, '0'),
|
|
].join('')
|
|
|
|
const parts = [slugify(processName)]
|
|
if (clientName?.trim()) parts.push(slugify(clientName.trim()))
|
|
parts.push(dateStr)
|
|
|
|
return `${parts.join('_')}${suffix}.${ext}`
|
|
}
|