UNPKG

use-downloads

Version:

A js utilities that contains all the methods for downloading files

53 lines (46 loc) 1.57 kB
declare const _default: { version: string; download: typeof download; downloadUrlFile: typeof downloadUrlFile; openFile: typeof openFile; saveFile: typeof saveFile; }; export default _default; /** * Several ways of file downloading: * 1. For file formats that some browsers do not recognize. Enter the file URL in the address bar, window.location.href = URL, window.open(URL); * 2. using a tag download attribute (or js create a tag); * 3. browser-recognizable pdf, txt files, back-end compatible with handling attachment; * 4. add token in the header for authenticated download, use XmlHttpRequest to want to backend to launch the request * * @param url - link * @param filename - filename * @param type - download type 'href','open','download','request' */ export declare function download(url: string, filename: string, type?: string): void; /** * Download secondary system documents * * @private * @param url - link * @param filename - the name of the file */ export declare function downloadUrlFile(url: string, filename: string): void; /** * New tab to download files * * @private * @param url - link * @param filename - the name of the file */ export declare function openFile(url: string, filename: string, fileType: string): void; /** * Save the file * * @private * @param data - file data * @param filename - the name of the file */ export declare function saveFile(data: any, filename: string): void; export declare const version: string; export { }