<!-- * @Description: 实用程序合集 * @Author: YH * @Date: 2025-10-17 17:13:02 * @LastEditors: YH * @LastEditTime: 2025-10-21 14:54:58 * @FilePath: \vite-project\packages\utils\README.md -->
npm install @yh-kit/utils实用程序合集
``bash`
npm i @yh-kit/utils
此库包含以下工具函数,及其函数名如下:
| 函数对象名 | 描述 | 函数实现方式 |
| :------ | :------ | :------ |
| arrayUtils | 数组相关操作工具函数 | js对象函数 |
| Base64Utils | Base64 相关操作工具函数 | class类 |
| booleanUtils | 布尔值相关操作工具函数 | js对象函数 |
| cookieUtils | Cookie 相关操作工具函数 | js对象函数 |
| dateUtils | 日期相关操作工具函数 | js对象函数 |
| documentUtils | 文档相关操作工具函数 | js对象函数 |
| downloadUtils | 下载相关操作工具函数 | js对象函数 |
| echartsUtils | Echarts 相关操作工具函数 |
| letterUtils | 字母相关操作工具函数 | js对象函数 |
| mapUtils | 地图相关操作工具函数 | js对象函数 |
| MoneyFormatter | 金额格式化工具函数 | class类 |
| nameUtils | 姓名相关操作工具函数 | namespace |
| numberUtils | 数字相关操作工具函数 | js对象函数 |
| objectUtils | 对象相关操作工具函数 | js对象函数 |
| phoneUtils | 手机号相关操作工具函数 | js对象函数 |
| randomUtils | 随机数相关操作工具函数 | js对象函数 |
| regexpUtils | 常用正则表达式 | js对象函数 |
| storageUtils | 本地存储相关操作工具函数 | js对象函数 |
| stringUtils | 字符串相关操作工具函数 | js对象函数 |
| urlUtils | URL 相关操作工具函数 | js对象函数 |
| waterfallUtils | 瀑布流相关操作工具函数 | js对象函数 |
你可以通过以下方式引入库中的工具函数并使用它们:
`ts``
import { arrayUtils, numberUtils, urlUtils } from "@yh-kit/utils";
const queryId = urlUtils.getQueryInfoByName("id");
console.log(queryId); // 123 地址为:http://localhost:5173/?id=123
const toEnumObj = arrayUtils.toEnumObj([
{
value: "1",
label: "壹"
}
]);
console.log(toEnumObj); // {1: {label: '壹', text: '壹', value: '1'}}
const toEnumObj2 = arrayUtils.toEnumObj(
[
{
value: "1",
label: "壹"
}
],
"label"
);
console.log(toEnumObj2); // {'壹': {label: '壹', text: '壹', value: '1'}}
const toMoney = numberUtils.toMoney(123456789);
console.log(toMoney); // 123,456,789.00