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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@modpackqt/bytes

v1.0.0

Published

Universal byte / register decoder + encoder for Node.js. Decode and encode int16, uint16, int32, uint32, float32, float64, strings, and bitmasks from any Buffer or numeric array — Modbus registers, MQTT payloads, raw TCP/UDP, BLE, LoRaWAN, file parsing. F

Readme

@modpackqt/bytes

Universal byte / register decoder + encoder for Node.js. Free, MIT, zero dependencies, no rate limits.

npm version License: MIT Powered by ModPackQT

Decode and encode int16, uint16, int32, uint32, float32, float64, strings, and bitmasks from any Buffer or numeric array — Modbus registers, MQTT payloads, raw TCP/UDP, BLE, LoRaWAN, file parsing.

The same byte/endian engine that powers the node-red-contrib-bytes-modpackqt palette, exposed as a clean Node.js library so you can use it in your own backends, CLIs, edge gateways, and bridge services.


Install

npm install @modpackqt/bytes

Requires Node.js 14 or later. Zero dependencies.


Quick start

const bytes = require('@modpackqt/bytes');

// Decode 2 Modbus holding registers as a single float32 (big-endian, ABCD order)
const value = bytes.decode([0x4248, 0x0000], 'registers', 'BE', 'float32');
// → [50]

// Encode a float back to registers, ready for FC16 write
const regs = bytes.encode([50], 'BE', 'float32');
// → [0x4248, 0x0000]

// Decode a 16-bit word as 16 boolean alarms (LSB first)
const alarms = bytes.decodeBitmask([0b0000000000010101], 'registers');
// → [true, false, true, false, true, false, ...]

// Decode a Modbus string (some devices need byte-swap)
const name = bytes.decodeString([0x4142, 0x4344], 'registers', 'BE', 'utf8', true);
// → "ABCD"

// Re-order bytes between two devices that disagree on endianness
const swapped = bytes.endianSwap([0x1234, 0x5678], 'registers', 'BE_SWAP', 4);
// → [0x3412, 0x7856]

API

decode(input, sourceType, endian, type) → number[]

Decode numeric values.

| Param | Type | Values | |---|---|---| | input | Buffer | number[] | A Buffer, an array of 16-bit registers, or an array of bytes | | sourceType | 'registers' | 'bytes' | How to interpret an input array | | endian | 'BE' | 'LE' | 'BE_SWAP' | 'LE_SWAP' | Word + byte order (see endianness table below) | | type | 'int16' | 'uint16' | 'int32' | 'uint32' | 'float32' | 'float64' | Output type |

Returns an array (always — even for one value) of decoded numbers.

encode(values, endian, type) → number[]

Encode one or more numbers as 16-bit registers (Modbus convention).

decodeString(input, sourceType, endian, encoding?, trim?) → string

Decode a string. encoding defaults to 'utf8'. trim strips trailing nulls and whitespace.

encodeString(value, endian, encoding?, padTo?) → number[]

Encode a string as 16-bit registers. padTo zero-pads to a fixed byte length.

decodeBitmask(input, sourceType, bits?) → boolean[]

Expand each 16-bit word into 16 booleans (LSB first). bits truncates the result.

endianSwap(input, sourceType, endian, width) → number[]

Re-order bytes/words. width is 2, 4, or 8. Useful when bridging two devices that disagree on endianness.

toBuffer(input, sourceType) → Buffer

Lower-level helper — convert any accepted input shape into a Buffer.


Endianness — what the four modes mean

For multi-register values (32-bit and 64-bit), Modbus devices vary by vendor. These are the four common conventions:

| Mode | Word order | Byte order within each word | Example: 0x12345678 over 2 regs | |---|---|---|---| | BE (default) | Big | Big | [0x1234, 0x5678] — "ABCD" | | LE | Little | Little | [0x7856, 0x3412] — "DCBA" | | BE_SWAP | Big | Swapped | [0x3412, 0x7856] — "BADC" | | LE_SWAP | Little | Swapped | [0x5678, 0x1234] — "CDAB" |

Tip: if your decoded float looks insane (1.7e-43 or NaN), try the other three modes — endianness mismatch is the #1 cause.


Use cases

  • Modbus — pair with modbus-serial or any Modbus library; this decodes the register arrays they return.
  • MQTT — decode binary payloads from sensors / industrial brokers.
  • BLE / LoRaWAN — decode characteristic / payload buffers.
  • Raw TCP/UDP — decode messages from custom protocols, energy meters, inverters.
  • File parsing — binary log files, vendor data dumps.

Quiet mode

The library prints a one-line banner on first import (so users know where to find docs and the free tester). Suppress it with:

MODPACKQT_QUIET=1 node your-app.js

Companion tools


Attribution

If @modpackqt/bytes saves you time, a README badge helps others find it:

[![Powered by ModPackQT](https://img.shields.io/badge/Powered%20by-ModPackQT-2563eb)](https://modpackqt.com)

License

MIT. See LICENSE. Provided "as is" without warranty of any kind.