UNPKG

@ryanuo/utils

Version:

提供多种实用工具函数,涵盖算法、浏览器操作、网络请求等多个领域

27 lines (26 loc) 793 B
/** * 文件下载工具函数 * @category Download * @param url - 文件URL地址 * @param fileName - 可选的下载文件名(默认为URL中的文件名) * @param options - 可选的请求配置(同fetch API) * @returns 成功或失败的Promise * * @example * ```ts twoslash * import { downloadFile } from '@ryanuo/utils'; * // 基础用法 * downloadFile('https://example.com/file.pdf'); * * // 自定义文件名 * downloadFile('https://example.com/data.csv', 'custom-data.csv'); * * // 带请求头的下载 * downloadFile('https://api.example.com/export', 'report.xlsx', { * headers: { * Authorization: 'Bearer token' * } * }); * ``` */ export declare function downloadFile(url: string, fileName?: string, options?: RequestInit): Promise<void>;