//#region src/modules/bytes.d.ts /** * 单位转换的字典 * @public */ declare const bytesUnitMap: Record; /** * 单位类型 * @public */ type BytesUnitType = keyof typeof bytesUnitMap; /** * 配置项 * @public */ interface BytesOption { unit?: BytesUnitType; decimalPlaces?: number; fixedDecimals?: boolean; thousandsSeparator?: string; unitSeparator?: string; } /** * 整合了字节单位格式化相关的方法 * @public */ declare class Bytes { /** * 用于格式化千分为字符串 * B非单词边界,也就是说是连续的数字 * ?= 肯定预查,后面会跟3个数字 * ?! 否定预查,后面不会跟数字 * 也就是说,前面多个3个数字连续,加上非数尾部 * 多次执行replace,就是不断从后面取3个数,前面加上分隔符 */ readonly formatThousandsRegExp: RegExp; /** *去除小数点后多余的零 */ readonly formatDecimalsRegExp: RegExp; /** * 提取正负号,数字,和单位 */ readonly parseRegExp: RegExp; readonly unitMap: Record; constructor(); /** * 传入数值转化为字节字符串或是传入字节字符串解析出数值,根据传入变量的类型区分调用方式 * @param value - 要转换的值 * @param options - 转换选项 * @returns - 转换结果 */ convert(value: number | string, options?: BytesOption): string | number | null | undefined; parse(val: string): number | null; format(value: number, options?: BytesOption): string | null; } /** * Bytes 类的实例 * @public */ declare const bytesInstance: Bytes; /** * 字节转换函数 * @param value - 要转换的值 * @param options - 转换选项 * @returns - 转换结果 * @public */ declare function bytes(value: number | string, options?: BytesOption): string | number | null | undefined; //#endregion export { Bytes, type BytesOption, type BytesUnitType, bytes, bytesInstance, bytesUnitMap };