# byte-parse-util

> The operation of combining and decomposing bytes

Latest version **0.0.2** (published 2021-01-29) · ISC license · 0 weekly downloads

## Install

```sh
npm install byte-parse-util
pnpm add byte-parse-util
yarn add byte-parse-util
bun add byte-parse-util
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2021-01-29 |
| First published | 2021-01-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 40.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | hedy ma |
| Maintainers | hedyma86 |
| Keywords | bit, byte, join byte to string, splite byte, bute to unit8Array, hex to float, parse REAL type, CRC |

## Links

- npm: https://www.npmjs.com/package/byte-parse-util
- Repository: https://github.com/hedyma86/byte-parse-util
- Issues: https://github.com/hedyma86/byte-parse-util/issues
- npm.io page: https://npm.io/package/byte-parse-util

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 0.0.2 (latest) — 2021-01-29
- 0.0.1 — 2021-01-29

## README

# byte-parse-util


字节处理工具集合

## Features

- 字节提取指定位
- 进制换算
- CRC校验
- REAL类型解析

## Browser Support

![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/src/safari/safari_48x48.png) | ![Opera](https://raw.github.com/alrra/browser-logos/master/src/opera/opera_48x48.png) | ![Edge](https://raw.github.com/alrra/browser-logos/master/src/edge/edge_48x48.png) | ![IE](https://raw.github.com/alrra/browser-logos/master/src/archive/internet-explorer_9-11/internet-explorer_9-11_48x48.png) |
--- | --- | --- | --- | --- | --- |
Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11 ✔ |



## Installing

Using npm:

```bash
$ npm install byte-parse-util
```
Using cdn:

```html
<script src="https://unpkg.com/byte-parse-util/dist/main.js"></script>
```

## Example
```js
//es6 module
import byteParseUtil from 'byte-parse-util';

//commonjs
const util = require('../dist/main.js');
let byteParseUtil = util.byteParseUtil;

```



### 字节处理相关

```js
//从数字中获取指定位 输出 3   125对应 二进制 11111111  提取 1 【start】11【end】11111,==》11，十进制为3
console.log(byteParseUtil.getBit(125,1,2));  

//从数字中获取指定位字符串 输出 '11'  125对应 二进制 11111111字符串  提取 1 【start】11【end】11111,==》11
console.log(byteParseUtil.getBitString(125,1,2));  

//合并字节数组 [0x2c,0x01] ==> 0x2c01 对应十进制为 11265
console.log(byteParseUtil.joinArr2Byte([0x2c,0x01])); 

//将字节按指定大小端模式分解成指定长度数组 0x2c01 ==> [0x2c,0x01] 以大端模式分解
console.log(byteParseUtil.spliteByte(0x2c01,2,'BE')); 

//字节转换为编码字符串 仅支持浏览器端 
try{
    console.log(byteParseUtil.bytesToEncodedString(5)); 
}catch(e){
    console.log('bytesToEncodedString 仅支持浏览器端');
}
```

### 数据包处理相关

```js
//获取校验值 数组（长度<=15）总和%256  输出254 (1+253)%253
console.log(byteParseUtil.getValidCode([1,253]));

//自动补全 输出[1,253,5,5,5,5,5,5,5,5,5,5,5,5,5]
console.log(byteParseUtil.cover([1,253],5));

//转换成标准16个字节unit8数组，末位为校验位 输出[1, 253, 5,  5, 5, 5,5,5, 5,  5, 5, 5,5,5, 5, 63]
console.log(byteParseUtil.bytesToSendUnit8Array([1,253],5));

//转换成标准16个字节unit8字符串，末位为校验位 输出1,253,5,5,5,5,5,5,5,5,5,5,5,5,5,63
console.log(byteParseUtil.bytesToSendUint8String([1,253],5));

//获取CRC校验位 输出16349
let arr = byteParseUtil.cover([1,253],5);
console.log(byteParseUtil.getCRC(arr));
```

### 字符串处理相关

```js
//将字符串以指定字符 输出 123,345,567,78
console.log(byteParseUtil.InsertString('12345678',',',3));

//给字符串添加指定长度的前缀或后缀
console.log(byteParseUtil.FillString('1235','*',15,true));

//16进制字符串转换成浮点数, 注意参数<=8位 
console.log(byteParseUtil.HexToSingleBatch('2c012c01'));

//解析REAL类型 输出同上
console.log(byteParseUtil.getFloat32ByArr([0x2c,0x1,0x2c,1]));

//浮点数转换成十六进制 输出 3F CC CC CC
console.log(byteParseUtil.SingleToHexBatch(1.6));

//浮点数转换成十六进制数组 输出 [ 63, 204, 204, 204 ] (==[0x3F,0xCC,0xCC,0xCC])
console.log(byteParseUtil.SingleToHexArray(1.6));

//获取字符串各字符的asc码 输出 [ 104, 101, 108, 108, 111 ]
console.log(byteParseUtil.getStrAsc2Array('hello'));

//将十进制数组转换为指定字符的十六进制字符串 输出 05,0b,0f,0b
console.log(byteParseUtil.parseToHexString([5,11,15,11],','));

//十六进制转换为int16类型数字 输出 -1
console.log(byteParseUtil.hexToInt16('ff1'));

```
### 其他
```js
//格式化时间显示 y-m-d h:m:s 
console.log(byteParseUtil.parseTime(1611722358182));
```



## Credits

> 本模块是我常用的字节处理工具集合，欢迎大家使用。  
> 如有问题欢迎联系指正。  
> HedyMa
> 


## License

MIT

---
_Source: https://npm.io/package/byte-parse-util · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
