haw-utils
Version:
一个基于业务场景的工具方法库
98 lines (68 loc) • 4.21 kB
Markdown
# haw-utils
[haw-utils](https://haw-utils.zhaoy1959.now.sh) 是一个基于业务场景的工具方法库。
## 丰富utils库
## 使用
**`npm` 或 `yarn` 安装**
```shell
npm install haw-utils --save
```
```shell
yarn add haw-utils
```
**浏览器引入**
在浏览器中使用 `script` 标签直接引入文件,并使用全局变量 `hawUtils` 。
`npm` 包的 `haw-utils/dist` 目录下提供了 `haw-utils.js` 以及 `haw-utils.min.js`。你也可以通过 [UNPKG](https://unpkg.com/haw-utils@latest/dist/) 进行下载。
*强烈不推荐使用已构建文件,这样无法按需加载。*
## 示例
```javascript
import { formatBankCard } from 'haw-utils'
formatBankCard('6228480402564890018'); // => 6228 4804 0256 4890 018
formatBankCard('6228480402564890018', {char: '-'}); // => 6228-4804-0256-4890-018
```
**按需引入**
如果你使用 `babel`,下面两种方式都可以只加载用到的组件。
- 方式一:指定模块文件,所有模块都放在 `lib` 目录下
```javascript
import formatBankCard from 'haw-utils/lib/formatBankCard'
```
- 方式二:使用 [babel-plugin-import](https://github.com/ant-design/babel-plugin-import) ,在 `babel` `plugin` 中添加以下配置
```javascript
['import', {
libraryName: 'haw-utils',
camel2DashComponentName: false
}, 'haw-utils']
```
## 文档
> 数学计算,修正了浮点数计算问题,适用于金额计算。
> 参考:[JS浮点数计算测试](https://2zbuy.csb.app/)
- 数学计算
- [plus](https://haw-utils.zhaoy1959.now.sh/module-Math.html#.plus) - 加
- [minus](https://haw-utils.zhaoy1959.now.sh/module-Math.html#.minus) - 减
- [times](https://haw-utils.zhaoy1959.now.sh/module-Math.html#.times) - 乘
- [divide](https://haw-utils.zhaoy1959.now.sh/module-Math.html#.divide) - 除
- [round](https://haw-utils.zhaoy1959.now.sh/module-Math.html#.round) - 四舍五入
- 数据处理
- [formatMoney](https://haw-utils.zhaoy1959.now.sh/module-Processor.html#.formatMoney) - 金额格式化
- [formatBankCard](https://haw-utils.zhaoy1959.now.sh/module-Processor.html#.formatBankCard) - 银行卡格式化
- [replaceChar](https://haw-utils.zhaoy1959.now.sh/module-Processor.html#.replaceChar) - 替换字符,应用场景如:脱敏
- [numberToChinese](https://haw-utils.zhaoy1959.now.sh/module-Processor.html#.numberToChinese) - 数字转中文数字
- 数据验证
- [isMobile](https://haw-utils.zhaoy1959.now.sh/module-Validator.html#.isMobile) - 手机号码
- [isTelephone](https://haw-utils.zhaoy1959.now.sh/module-Validator.html#.isTelephone) - 固定电话
- [isPostcode](https://haw-utils.zhaoy1959.now.sh/module-Validator.html#.isPostcode) - 邮政编码
- [isIdCard](https://haw-utils.zhaoy1959.now.sh/module-Validator.html#.isIdCard) - 身份证号
- [isEmail](https://haw-utils.zhaoy1959.now.sh/module-Validator.html#.isEmail) - 邮箱
- [isQQ](https://haw-utils.zhaoy1959.now.sh/module-Validator.html#.isQQ) - QQ号
- [isWX](https://haw-utils.zhaoy1959.now.sh/module-Validator.html#.isWX) - 微信号
- [isVehicle](https://haw-utils.zhaoy1959.now.sh/module-Validator.html#.isVehicle) - 车牌号
- [isBankCard](https://haw-utils.zhaoy1959.now.sh/module-Validator.html#.isBankCard) - 银行卡
- [isSocialCreditCode](https://haw-utils.zhaoy1959.now.sh/module-Validator.html#.isSocialCreditCode) - 统一社会信用代码,也叫三证合一组织代码
- [isPassword](https://haw-utils.zhaoy1959.now.sh/module-Validator.html#.isPassword) 密码强度
- [isPassport](https://haw-utils.zhaoy1959.now.sh/module-Validator.html#.isPassport) - 护照号
- [isChinese](https://haw-utils.zhaoy1959.now.sh/module-Validator.html#.isChinese) - 中文
- [isIPv4](https://haw-utils.zhaoy1959.now.sh/module-Validator.html#.isIPv4) - IPv4
- [isIPv6](https://haw-utils.zhaoy1959.now.sh/module-Validator.html#.isIPv6) - IPv6
- [isUrl](https://haw-utils.zhaoy1959.now.sh/module-Validator.html#.isUrl) - URL
- [isBusinessLicense](https://haw-utils.zhaoy1959.now.sh/module-Validator.html#.isBusinessLicense) - 营业执照,也叫工商注册号
### 项目版本
- [初始版本来源v3.1.0](https://www.npmjs.com/package/util-helpers)