Skip to content

getFileName 获取文件名

function getFileName(filePath: string): string

从文件路径中提取完整文件名,包含后缀。路径无效或不匹配支持的文件后缀时返回空字符串或仅标题。

参数

参数名说明类型默认值
filePath文件路径,可包含查询参数string必填

返回值

返回值说明类型
fileName包含后缀的文件名string

示例

typescript
import { getFileName } from '@mingto/tools'

getFileName('/docs/report.pdf') // 'report.pdf'
getFileName('/docs/report.pdf?download=1') // 'report.pdf'
getFileName('/api/users') // ''