Merge remote-tracking branch 'origin/main' into feat/support-agent-sandbox

# Conflicts:
#	web/eslint-suppressions.json
This commit is contained in:
yyh
2026-02-04 18:15:32 +08:00
51 changed files with 9433 additions and 1688 deletions

View File

@ -148,3 +148,23 @@ export const formatNumberAbbreviated = (num: number) => {
export const formatToLocalTime = (time: Dayjs, local: Locale, format: string) => {
return time.locale(localeMap[local] ?? 'en').format(format)
}
/**
* Get file extension from file name.
* @param fileName file name
* @example getFileExtension('document.pdf') will return 'pdf'
* @example getFileExtension('archive.tar.gz') will return 'gz'
* @example getFileExtension('.gitignore') will return '' (hidden file with no extension)
* @example getFileExtension('.hidden.txt') will return 'txt'
*/
export const getFileExtension = (fileName: string): string => {
if (!fileName)
return ''
// Handle hidden files (starting with dot) by finding dot after the first character
const dotIndex = fileName.indexOf('.', fileName.startsWith('.') ? 1 : 0)
if (dotIndex === -1 || dotIndex === fileName.length - 1)
return ''
return fileName.slice(dotIndex + 1).split('.').pop()?.toLowerCase() ?? ''
}