@iot9x.com/ipc-utils
Version:
九星云、九星小程序、九星配置工具所共用的库方法
38 lines (28 loc) • 935 B
Markdown
九星云、九星小程序、九星配置工具所共用的库方法。
1. 由于考虑到小程序,所以不要支持`Buffer`,所以`Buffer`部分全部使用`Int8Array`来代替。
```bash
$ pnpm add @iot9x.com/ipc-utils
```
* [文档地址](https://docs.iot9x.com/docs/js/上位机工具库/)
* [NPM地址](https://www.npmjs.com/package/@iot9x.com/ipc-utils)
```js
import {
RegularUtil,
ConversionUtil,
dataFormatUtil
} from '@iot9x.com/ipc-utils'
// 检查是否为空
RegularUtil.isEmpty(null); // true
RegularUtil.isEmpty({}); // true
RegularUtil.isEmpty([]); // true
// 进制转换
ConversionUtil.hexToStr('31 32 33'); // 123
ConversionUtil.strToHex('123'); // 313233
ConversionUtil.strToHex('123', true); // 31 32 33
// 时间日期转换
dataFormatUtil.formatDate(Date.now()); // 2023-09-07 16:46:22
dataFormatUtil.formatHms(Date.now()); // 16:46:22
```