Skip to content

isFilePath 判断文件路径

function isFilePath(filePath: string): boolean

判断字符串是否是支持后缀的文件路径。支持带查询参数的 URL 形式。

参数

参数名说明类型默认值
filePath待判断的文件路径string必填

返回值

返回值说明类型
result是支持的文件路径时返回 true,否则返回 falseboolean

示例

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

isFilePath('https://example.com/report.pdf') // true
isFilePath('/images/avatar.png?x=1') // true
isFilePath('/api/users') // false

注意事项

  • 支持的后缀来自 FileSuffixEnum
  • 空字符串、0 等被 checkEmpty 判定为空的值会返回 false