Skip to content

getFileTitle 获取文件标题

function getFileTitle(filePath: string): string

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

参数

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

返回值

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

示例

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

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