Skip to content

updateFilePathQuery 更新文件查询参数

function updateFilePathQuery(filePath: string, objectQuery: Record<string, string>, isAppend?: boolean): string

更新文件路径上的查询参数。默认会保留原查询参数并追加/覆盖新参数;也可选择完全替换查询参数。

参数

参数名说明类型默认值
filePath文件路径,可包含查询参数string必填
objectQuery需要设置的查询参数对象Record<string, string>必填
isAppend是否在原查询参数基础上追加booleantrue

返回值

返回值说明类型
path更新后的文件路径string

示例

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

updateFilePathQuery('/docs/report.pdf?a=1', { b: '2' })
// '/docs/report.pdf?a=1&b=2'

updateFilePathQuery('/docs/report.pdf?a=1', { b: '2' }, false)
// '/docs/report.pdf?b=2'

注意事项

  • objectQuery 为空对象时,返回不带查询参数的文件路径。
  • 查询字符串生成逻辑来自 objectToQueryString