# xm-utlis-templet **Repository Path**: public_12/xm-utlis-templet ## Basic Information - **Project Name**: xm-utlis-templet - **Description**: 工具函数库,js函数库工程化模板,支持打包发布npm - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2025-04-20 - **Last Updated**: 2025-08-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 一个工具函数库。js库的编写工程化模板 - 关于这个项目搭建明细 请看我的博客 [https://blog.csdn.net/weixin_43376417/article/details/147365642](https://blog.csdn.net/weixin_43376417/article/details/147365642) - 个人邮箱:2654392501@qq.com # lib ## 安装 ```bash npm i @renjinming/xm-lib ``` ## 使用 ```js // commonjs const { getObjType } = require('@renjinming/xm-lib'); const type = getObjType('123'); console.log(type); // "string" ``` ```js // esm import { getObjType } from '@renjinming/xm-lib'; const type = getObjType('123'); console.log(type); // "string" ``` ## API ### getObjType 获取对象类型 ```js const { getObjType } = require('@renjinming/xm-lib'); const type = getObjType('123'); console.log(type); // "string" const type2 = getObjType(123); console.log(type2); // "number" const type3 = getObjType({ name: 'renjinming' }); console.log(type3); // "object" const type4 = getObjType([1, 2, 3]); console.log(type4); // "array" const type5 = getObjType(null); console.log(type5); // "null" const type6 = getObjType(undefined); console.log(type6); // "undefined" const type7 = getObjType(function () {}); console.log(type7); // "function" const type8 = getObjType(new Date()); console.log(type8); // "date" const type9 = getObjType(/a/); console.log(type9); // "regexp" // ---- ``` ### rules 数据校验 ```bash const { rules } = require("@renjinming/xm-lib"); const info = { ticketPrice: "", adjustPrice: "accw" }; const rule = { ticketPrice: [ { required: true, message: "请输入票面金额" }, { pattern: /^[0-9.]{1,50}$/, message: "必须是0以上的数字" }, ], adjustPrice: [ { required: true, message: "请输入上浮金额" }, { pattern: /^[0-9.]{1,50}$/, message: "必须是0以上的数字" }, ], }; const result = rules(info, rule); console.log(result); // 请输入票面金额 ``` ### objArrSet 对象数组去重 ```js const { objArrSet } = require('@renjinming/xm-lib'); const arr = [ { id: 1, name: 'a' }, { id: 2, name: 'b' }, { id: 3, name: 'c' }, { id: 1, name: 'dcc' }, ]; const arr2 = objArrSet(arr, 'id'); console.log(arr2); // [ { id: 1, name: 'a' }, { id: 2, name: 'b' }, { id: 3, name: 'c' } ] ``` ### deepClone 对象深度拷贝