npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

byte-parse-util

v0.0.2

Published

The operation of combining and decomposing bytes

Downloads

5

Readme

byte-parse-util

字节处理工具集合

Features

  • 字节提取指定位
  • 进制换算
  • CRC校验
  • REAL类型解析

Browser Support

Chrome | Firefox | Safari | Opera | Edge | IE | --- | --- | --- | --- | --- | --- | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11 ✔ |

Installing

Using npm:

$ npm install byte-parse-util

Using cdn:

<script src="https://unpkg.com/byte-parse-util/dist/main.js"></script>

Example

//es6 module
import byteParseUtil from 'byte-parse-util';

//commonjs
const util = require('../dist/main.js');
let byteParseUtil = util.byteParseUtil;

字节处理相关

//从数字中获取指定位 输出 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 仅支持浏览器端');
}

数据包处理相关

//获取校验值 数组(长度<=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));

字符串处理相关

//将字符串以指定字符 输出 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'));

其他

//格式化时间显示 y-m-d h:m:s 
console.log(byteParseUtil.parseTime(1611722358182));

Credits

本模块是我常用的字节处理工具集合,欢迎大家使用。
如有问题欢迎联系指正。
HedyMa

License

MIT