mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 08:58:09 +08:00
Merge remote-tracking branch 'origin/main' into feat/support-agent-sandbox
# Conflicts: # web/eslint-suppressions.json
This commit is contained in:
@ -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() ?? ''
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user