1.0.0 • Published 10 months ago

util-th v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

Utility Functions

这个库包含一些实用的工具函数,适用于常见的开发需求。

使用

getFileNameForPath(path: string): string 从文件路径中提取文件名。

formatFileSize(bytes: number): string 将字节数转换为人类可读的格式(例如:KB, MB)。

formatHTML(value: string): string 格式化 HTML 字符串,去除多余的空白。

formatDate(date: number, formatStr?: string, ignoreWithinTwoMin?: boolean): string 将日期格式化为指定格式。

convertToBase64(file: File): Promise 将文件转换为 Base64 编码。

base64ToFile(base64String: string, fileName: string): File 将 Base64 字符串转换为文件对象。

randomId(length?: number): string 生成指定长度的随机 ID。

resizeBox(options: ResizeBox): Promise 调整元素大小。

compareVersions(v1: string, v2: string): boolean 比较两个版本号。

isJSON(str: string): boolean 判断字符串是否为有效的 JSON。

debounce(func: T, wait: number) 防抖函数。

getParams(key: string): string

安装

npm install UtilTh

import { debounce } from 'UtilTh';

联系我们

如果你有任何问题或建议,请通过 Email 联系我们。

1.0.0

10 months ago