mirror of
https://github.com/langgenius/dify.git
synced 2026-02-09 23:20:12 -05:00
refactor(datasets): extract hooks and components with comprehensive tests (#31707)
Co-authored-by: CodingOnStar <hanxujiang@dify.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
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