UNPKG

jinbi-utils

Version:

这是一个实用工具库,包含了多个常用的功能模块。以下是各个模块的详细说明:

97 lines (96 loc) 2.82 kB
/** * 文件处理相关 * @packageDocumentation * @module File * @preferred */ export declare type FileSizeUnit = 'B' | 'KB' | 'MB' | 'GB' | 'TB'; export interface FileSizeObject { size: number; unit: FileSizeUnit; } /** * 计算文件大小 #### 使用说明 ``` calcFileSize(100) 返回 { size: 100, unit: 'B' } calcFileSize(1024) 返回 { size: 1, unit: 'KB' } calcFileSize(1024, 'KB') 返回 { size: 1, unit: 'MB' } calcFileSize(1126.4, 'mb') 返回 { size: 1.1, unit: 'GB' } calcFileSize(Math.pow(1024, 2), 'kb') 返回 { size: 1, unit: 'GB' } ``` * @param size 单位 k * @returns number */ export declare function calcFileSize(size: number, unit?: FileSizeUnit): FileSizeObject; /** * 文件大小转换 #### 使用说明 ``` fileSizeFormat('') 返回 - fileSizeFormat('1024') 返回 1KB fileSizeFormat('1024', 'KB') 返回 1MB fileSizeFormat('2645', 'B') 返回 ceil(2645 / 1024, 2)MB ``` * @param {string} str 字符串 单位k */ export declare function fileSizeFormat(str: string | number, unit?: FileSizeUnit, defaultValue?: string): string; /** * base64转换为file * dataurl base64图片 * */ export declare function dataURLtoBlob(dataurl: string): Blob; export declare function blobToDataURL(blob: Blob): any; export interface CompressImgScaleCallback { (w: number, h: number): number; } export interface CompressImgQualityCallback { (fileSize: number, scale: number, w: number, h: number): number; } /** * 压缩图片方法 * @param file 图片 * @param scaleCallback 宽高 压缩规则 * @param qualityCallback 质量 压缩规则 */ export declare function compressImg(file: File, scaleCallback?: CompressImgScaleCallback, qualityCallback?: CompressImgQualityCallback): Promise<Blob>; export declare type Method = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'link' | 'LINK' | 'unlink' | 'UNLINK'; export interface ExportByBlobParams { /** * 请求方式 */ method?: Method; /** * 接口地址 */ url: string; /** * post接口参数 */ data?: any; /** * get接口参数 */ params?: any; /** * 导出的文件名称 */ filename?: string; } export interface GenExportByBlobParams { /** * axios 请求函数 */ axiosRequest: any; /** * 不使用 withCredentials 域名 */ notWithCredentials?: string[]; } /** * 生成导出函数 */ export declare function genExportByBlob({ axiosRequest, notWithCredentials, }: { axiosRequest: any; notWithCredentials?: never[] | undefined; }): (config: ExportByBlobParams) => Promise<unknown>;