/** * 获取文件名中的扩展名部分。 * * @param fileName - 完整的文件名,包括点(.)和扩展名。 * @returns 返回文件的扩展名(不含点),如果未找到扩展名则返回空字符串。 * * @example * getFileExtension("example.text.txt"); // 返回: "txt" * getFileExtension("document.pdf"); // 返回: "pdf" * getFileExtension("noExtension"); // 返回: "" */ export function getFileExtension(fileName: string): string { const reg = /[^.]+$/; const match = reg.exec(fileName); return match ? match[0] : ''; // 使用非空断言并提供默认返回值 }